org.apache.cxf.helpers.IOUtils.copyAndCloseInput()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.apache.cxf.helpers.IOUtils.copyAndCloseInput()方法的一些代码示例,展示了IOUtils.copyAndCloseInput()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copyAndCloseInput()方法的具体详情如下:
包路径:org.apache.cxf.helpers.IOUtils
类名称:IOUtils
方法名:copyAndCloseInput

IOUtils.copyAndCloseInput介绍

暂无

代码示例

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

  1. protected void serveStaticContent(HttpServletRequest request,
  2. HttpServletResponse response,
  3. String pathInfo) throws ServletException {
  4. InputStream is = getResourceAsStream(pathInfo);
  5. if (is == null) {
  6. throw new ServletException("Static resource " + pathInfo + " is not available");
  7. }
  8. try {
  9. int ind = pathInfo.lastIndexOf(".");
  10. if (ind != -1 && ind < pathInfo.length()) {
  11. String type = getStaticResourceContentType(pathInfo.substring(ind + 1));
  12. if (type != null) {
  13. response.setContentType(type);
  14. }
  15. }
  16. String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL);
  17. if (cacheControl != null) {
  18. response.setHeader("Cache-Control", cacheControl.trim());
  19. }
  20. ServletOutputStream os = response.getOutputStream();
  21. IOUtils.copyAndCloseInput(is, os);
  22. os.flush();
  23. } catch (IOException ex) {
  24. throw new ServletException("Static resource " + pathInfo
  25. + " can not be written to the output stream");
  26. }
  27. }

代码示例来源:origin: apache/cxf

  1. public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException {
  2. IOUtils.copyAndCloseInput(in, out, bufferSize);
  3. }

代码示例来源:origin: org.apache.cxf/cxf-core

  1. public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException {
  2. IOUtils.copyAndCloseInput(in, out, bufferSize);
  3. }

代码示例来源:origin: apache/cxf

  1. public static void writeUtilsToResponseStream(Class<?> referenceClass, OutputStream outputStream) {
  2. InputStream utils = referenceClass.getResourceAsStream(JS_UTILS_PATH);
  3. if (utils == null) {
  4. throw new RuntimeException("Unable to get stream for " + JS_UTILS_PATH);
  5. }
  6. try {
  7. IOUtils.copyAndCloseInput(utils, outputStream);
  8. outputStream.flush();
  9. } catch (IOException e) {
  10. throw new RuntimeException("Failed to write javascript utils to HTTP response.", e);
  11. }
  12. }

代码示例来源:origin: apache/cxf

  1. protected void handleRangeRequest(InputStream is,
  2. OutputStream os,
  3. HttpHeaders inHeaders,
  4. MultivaluedMap<String, Object> outHeaders) throws IOException {
  5. String range = inHeaders.getRequestHeaders().getFirst("Range");
  6. if (range == null) {
  7. IOUtils.copyAndCloseInput(is, os, bufferSize);
  8. } else {
  9. // implement
  10. }
  11. }

代码示例来源:origin: apache/cxf

  1. @Override
  2. protected byte[] getBytes(Object object) {
  3. DataSource dataSource = (DataSource) object;
  4. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  5. try {
  6. IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos);
  7. } catch (IOException e) {
  8. throw new RuntimeException(e);
  9. }
  10. return baos.toByteArray();
  11. }
  12. }

代码示例来源:origin: apache/cxf

  1. public static void transferTo(InputStream inputStream, File destinationFile) throws IOException {
  2. if (Transferable.class.isAssignableFrom(inputStream.getClass())) {
  3. ((Transferable)inputStream).transferTo(destinationFile);
  4. } else {
  5. try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) {
  6. copyAndCloseInput(inputStream, out);
  7. }
  8. }
  9. }

代码示例来源:origin: org.apache.cxf/cxf-core

  1. public static void transferTo(InputStream inputStream, File destinationFile) throws IOException {
  2. if (Transferable.class.isAssignableFrom(inputStream.getClass())) {
  3. ((Transferable)inputStream).transferTo(destinationFile);
  4. } else {
  5. try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) {
  6. copyAndCloseInput(inputStream, out);
  7. }
  8. }
  9. }

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

  1. protected void handleRangeRequest(InputStream is,
  2. OutputStream os,
  3. HttpHeaders inHeaders,
  4. MultivaluedMap<String, Object> outHeaders) throws IOException {
  5. String range = inHeaders.getRequestHeaders().getFirst("Range");
  6. if (range == null) {
  7. IOUtils.copyAndCloseInput(is, os);
  8. } else {
  9. // implement
  10. }
  11. }

代码示例来源:origin: org.apache.cxf/cxf-rt-databinding-aegis

  1. @Override
  2. protected byte[] getBytes(Object object) {
  3. DataSource dataSource = (DataSource) object;
  4. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  5. try {
  6. IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos);
  7. } catch (IOException e) {
  8. throw new RuntimeException(e);
  9. }
  10. return baos.toByteArray();
  11. }
  12. }

代码示例来源:origin: apache/cxf

  1. public void writeCacheTo(OutputStream out) throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. ((ByteArrayOutputStream)currentStream).writeTo(out);
  6. } else {
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. } else {
  10. // read the file
  11. InputStream fin = createInputStream(tempFile);
  12. IOUtils.copyAndCloseInput(fin, out);
  13. }
  14. }

代码示例来源:origin: org.apache.cxf/cxf-api

  1. public void writeCacheTo(OutputStream out) throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. ((ByteArrayOutputStream)currentStream).writeTo(out);
  6. } else {
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. } else {
  10. // read the file
  11. InputStream fin = createInputStream(tempFile);
  12. IOUtils.copyAndCloseInput(fin, out);
  13. }
  14. }

代码示例来源:origin: apache/cxf

  1. public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
  2. MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
  3. throws IOException {
  4. DataSource ds = DataSource.class.isAssignableFrom(cls)
  5. ? (DataSource)src : ((DataHandler)src).getDataSource();
  6. if (useDataSourceContentType) {
  7. setContentTypeIfNeeded(type, headers, ds.getContentType());
  8. }
  9. IOUtils.copyAndCloseInput(ds.getInputStream(), os);
  10. }

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

  1. public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations,
  2. MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
  3. throws IOException {
  4. DataSource ds = DataSource.class.isAssignableFrom(cls)
  5. ? (DataSource)src : ((DataHandler)src).getDataSource();
  6. if (useDataSourceContentType) {
  7. setContentTypeIfNeeded(type, headers, ds.getContentType());
  8. }
  9. IOUtils.copyAndCloseInput(ds.getInputStream(), os);
  10. }

代码示例来源:origin: Talend/tesb-rt-se

  1. public void performTransformation(Message message) {
  2. Reader transformedReader = null;
  3. try {
  4. transformedReader = XSLTUtils.transform(xsltTemplate, getReader());
  5. IOUtils.copyAndCloseInput(transformedReader, origWriter, IOUtils.DEFAULT_BUFFER_SIZE);
  6. message.setContent(Writer.class, origWriter);
  7. } catch (IOException e) {
  8. throw new Fault("READER_COPY", LOG, e, e.getMessage());
  9. }
  10. }
  11. }

代码示例来源:origin: apache/cxf

  1. @Test
  2. public void testPostPetStatus2() throws Exception {
  3. Socket s = new Socket("localhost", Integer.parseInt(PORT));
  4. IOUtils.copyAndCloseInput(getClass().getResource("resources/formRequest.txt").openStream(),
  5. s.getOutputStream());
  6. s.getOutputStream().flush();
  7. try {
  8. assertTrue("Wrong status returned", getStringFromInputStream(s.getInputStream())
  9. .contains("open"));
  10. } finally {
  11. s.close();
  12. }
  13. }

代码示例来源:origin: apache/cxf

  1. private void handleReader(Message message, Reader reader) throws IOException {
  2. CachedWriter writer = new CachedWriter();
  3. IOUtils.copyAndCloseInput(reader, writer);
  4. message.setContent(Reader.class, writer.getReader());
  5. message.setContent(CachedWriter.class, writer);
  6. }

代码示例来源:origin: org.apache.cxf/cxf-rt-features-logging

  1. private void handleReader(Message message, Reader reader) throws IOException {
  2. CachedWriter writer = new CachedWriter();
  3. IOUtils.copyAndCloseInput(reader, writer);
  4. message.setContent(Reader.class, writer.getReader());
  5. message.setContent(CachedWriter.class, writer);
  6. }

代码示例来源:origin: apache/cxf

  1. private InputStream copyIn(InputStream in) throws Exception {
  2. try (CachedOutputStream bos = new CachedOutputStream()) {
  3. IOUtils.copyAndCloseInput(in, bos);
  4. in = bos.getInputStream();
  5. bos.close();
  6. return in;
  7. }
  8. }
  9. private String getStringFromInputStream(InputStream in) throws Exception {

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

  1. protected void copyInputToOutput(InputStream is, OutputStream os,
  2. MultivaluedMap<String, Object> outHeaders) throws IOException {
  3. if (isRangeSupported()) {
  4. Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage();
  5. handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders);
  6. } else if (closeResponseInputStream) {
  7. IOUtils.copyAndCloseInput(is, os);
  8. } else {
  9. IOUtils.copy(is, os);
  10. }
  11. }

相关文章