本文整理了Java中org.apache.cxf.helpers.IOUtils.copyAndCloseInput()
方法的一些代码示例,展示了IOUtils.copyAndCloseInput()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copyAndCloseInput()
方法的具体详情如下:
包路径:org.apache.cxf.helpers.IOUtils
类名称:IOUtils
方法名:copyAndCloseInput
暂无
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
protected void serveStaticContent(HttpServletRequest request,
HttpServletResponse response,
String pathInfo) throws ServletException {
InputStream is = getResourceAsStream(pathInfo);
if (is == null) {
throw new ServletException("Static resource " + pathInfo + " is not available");
}
try {
int ind = pathInfo.lastIndexOf(".");
if (ind != -1 && ind < pathInfo.length()) {
String type = getStaticResourceContentType(pathInfo.substring(ind + 1));
if (type != null) {
response.setContentType(type);
}
}
String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL);
if (cacheControl != null) {
response.setHeader("Cache-Control", cacheControl.trim());
}
ServletOutputStream os = response.getOutputStream();
IOUtils.copyAndCloseInput(is, os);
os.flush();
} catch (IOException ex) {
throw new ServletException("Static resource " + pathInfo
+ " can not be written to the output stream");
}
}
代码示例来源:origin: apache/cxf
public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException {
IOUtils.copyAndCloseInput(in, out, bufferSize);
}
代码示例来源:origin: org.apache.cxf/cxf-core
public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException {
IOUtils.copyAndCloseInput(in, out, bufferSize);
}
代码示例来源:origin: apache/cxf
public static void writeUtilsToResponseStream(Class<?> referenceClass, OutputStream outputStream) {
InputStream utils = referenceClass.getResourceAsStream(JS_UTILS_PATH);
if (utils == null) {
throw new RuntimeException("Unable to get stream for " + JS_UTILS_PATH);
}
try {
IOUtils.copyAndCloseInput(utils, outputStream);
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException("Failed to write javascript utils to HTTP response.", e);
}
}
代码示例来源:origin: apache/cxf
protected void handleRangeRequest(InputStream is,
OutputStream os,
HttpHeaders inHeaders,
MultivaluedMap<String, Object> outHeaders) throws IOException {
String range = inHeaders.getRequestHeaders().getFirst("Range");
if (range == null) {
IOUtils.copyAndCloseInput(is, os, bufferSize);
} else {
// implement
}
}
代码示例来源:origin: apache/cxf
@Override
protected byte[] getBytes(Object object) {
DataSource dataSource = (DataSource) object;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
return baos.toByteArray();
}
}
代码示例来源:origin: apache/cxf
public static void transferTo(InputStream inputStream, File destinationFile) throws IOException {
if (Transferable.class.isAssignableFrom(inputStream.getClass())) {
((Transferable)inputStream).transferTo(destinationFile);
} else {
try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) {
copyAndCloseInput(inputStream, out);
}
}
}
代码示例来源:origin: org.apache.cxf/cxf-core
public static void transferTo(InputStream inputStream, File destinationFile) throws IOException {
if (Transferable.class.isAssignableFrom(inputStream.getClass())) {
((Transferable)inputStream).transferTo(destinationFile);
} else {
try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) {
copyAndCloseInput(inputStream, out);
}
}
}
代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs
protected void handleRangeRequest(InputStream is,
OutputStream os,
HttpHeaders inHeaders,
MultivaluedMap<String, Object> outHeaders) throws IOException {
String range = inHeaders.getRequestHeaders().getFirst("Range");
if (range == null) {
IOUtils.copyAndCloseInput(is, os);
} else {
// implement
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-databinding-aegis
@Override
protected byte[] getBytes(Object object) {
DataSource dataSource = (DataSource) object;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
return baos.toByteArray();
}
}
代码示例来源:origin: apache/cxf
public void writeCacheTo(OutputStream out) throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
((ByteArrayOutputStream)currentStream).writeTo(out);
} else {
throw new IOException("Unknown format of currentStream");
}
} else {
// read the file
InputStream fin = createInputStream(tempFile);
IOUtils.copyAndCloseInput(fin, out);
}
}
代码示例来源:origin: org.apache.cxf/cxf-api
public void writeCacheTo(OutputStream out) throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
((ByteArrayOutputStream)currentStream).writeTo(out);
} else {
throw new IOException("Unknown format of currentStream");
}
} else {
// read the file
InputStream fin = createInputStream(tempFile);
IOUtils.copyAndCloseInput(fin, out);
}
}
代码示例来源:origin: apache/cxf
public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
throws IOException {
DataSource ds = DataSource.class.isAssignableFrom(cls)
? (DataSource)src : ((DataHandler)src).getDataSource();
if (useDataSourceContentType) {
setContentTypeIfNeeded(type, headers, ds.getContentType());
}
IOUtils.copyAndCloseInput(ds.getInputStream(), os);
}
代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs
public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
throws IOException {
DataSource ds = DataSource.class.isAssignableFrom(cls)
? (DataSource)src : ((DataHandler)src).getDataSource();
if (useDataSourceContentType) {
setContentTypeIfNeeded(type, headers, ds.getContentType());
}
IOUtils.copyAndCloseInput(ds.getInputStream(), os);
}
代码示例来源:origin: Talend/tesb-rt-se
public void performTransformation(Message message) {
Reader transformedReader = null;
try {
transformedReader = XSLTUtils.transform(xsltTemplate, getReader());
IOUtils.copyAndCloseInput(transformedReader, origWriter, IOUtils.DEFAULT_BUFFER_SIZE);
message.setContent(Writer.class, origWriter);
} catch (IOException e) {
throw new Fault("READER_COPY", LOG, e, e.getMessage());
}
}
}
代码示例来源:origin: apache/cxf
@Test
public void testPostPetStatus2() throws Exception {
Socket s = new Socket("localhost", Integer.parseInt(PORT));
IOUtils.copyAndCloseInput(getClass().getResource("resources/formRequest.txt").openStream(),
s.getOutputStream());
s.getOutputStream().flush();
try {
assertTrue("Wrong status returned", getStringFromInputStream(s.getInputStream())
.contains("open"));
} finally {
s.close();
}
}
代码示例来源:origin: apache/cxf
private void handleReader(Message message, Reader reader) throws IOException {
CachedWriter writer = new CachedWriter();
IOUtils.copyAndCloseInput(reader, writer);
message.setContent(Reader.class, writer.getReader());
message.setContent(CachedWriter.class, writer);
}
代码示例来源:origin: org.apache.cxf/cxf-rt-features-logging
private void handleReader(Message message, Reader reader) throws IOException {
CachedWriter writer = new CachedWriter();
IOUtils.copyAndCloseInput(reader, writer);
message.setContent(Reader.class, writer.getReader());
message.setContent(CachedWriter.class, writer);
}
代码示例来源:origin: apache/cxf
private InputStream copyIn(InputStream in) throws Exception {
try (CachedOutputStream bos = new CachedOutputStream()) {
IOUtils.copyAndCloseInput(in, bos);
in = bos.getInputStream();
bos.close();
return in;
}
}
private String getStringFromInputStream(InputStream in) throws Exception {
代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs
protected void copyInputToOutput(InputStream is, OutputStream os,
MultivaluedMap<String, Object> outHeaders) throws IOException {
if (isRangeSupported()) {
Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage();
handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders);
} else if (closeResponseInputStream) {
IOUtils.copyAndCloseInput(is, os);
} else {
IOUtils.copy(is, os);
}
}
内容来源于网络,如有侵权,请联系作者删除!