org.apache.cxf.helpers.IOUtils类的使用及代码示例

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

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

IOUtils介绍

暂无

代码示例

代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws

  1. try {
  2. if (src.getInputStream() != null) {
  3. try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) {
  4. IOUtils.copy(src.getInputStream(), bos, 1024);
  5. ds = new ByteDataSource(bos.toByteArray(), ct);
  6. ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8),
  7. ct);
  8. throw new Fault(e);
  9. ByteArrayOutputStream bwriter = new ByteArrayOutputStream();
  10. XMLStreamWriter writer = null;
  11. try {
  12. ds = new ByteDataSource(bwriter.toByteArray(), ct);
  13. } catch (XMLStreamException e1) {
  14. throw new Fault(e1);
  15. } finally {
  16. StaxUtils.close(writer);

代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws

  1. if (a.getId().startsWith(start)) {
  2. DataHandler dh = a.getDataHandler();
  3. String ct = dh.getContentType();
  4. Object o = null;
  5. Class<?> typeClass = mpi.getTypeClass();
  6. try {
  7. o = dh.getContent();
  8. } catch (IOException e) {
  9. throw new Fault(e);
  10. o = IOUtils.readBytesFromStream(dh.getInputStream());
  11. } catch (IOException e) {
  12. throw new Fault(e);
  13. o = ImageIO.read(dh.getInputStream());
  14. } catch (IOException e) {
  15. throw new Fault(e);

代码示例来源: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 byte[] readBytesFromStream(InputStream in) throws IOException {
  2. int i = in.available();
  3. if (i < DEFAULT_BUFFER_SIZE) {
  4. i = DEFAULT_BUFFER_SIZE;
  5. }
  6. try (ByteArrayOutputStream bos = new ByteArrayOutputStream(i)) {
  7. copy(in, bos);
  8. return bos.toByteArray();
  9. } finally {
  10. in.close();
  11. }
  12. }
  13. }

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

  1. @Override
  2. public byte[] getAttachmentAsByteArray(String contentId) {
  3. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  4. try {
  5. InputStream is = AttachmentUtil.getAttachmentDataSource(contentId, attachments)
  6. .getInputStream();
  7. IOUtils.copy(is, bos);
  8. is.close();
  9. bos.close();
  10. } catch (IOException e) {
  11. throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_READ_ERROR", LOG), e);
  12. }
  13. return bos.toByteArray();
  14. }

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

  1. public byte[] invokeBytes(String address, String transport, String message) throws Exception {
  2. EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
  3. ei.setAddress(address);
  4. ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
  5. ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
  6. Conduit conduit = conduitInit.getConduit(ei);
  7. TestMessageObserver obs = new TestMessageObserver();
  8. conduit.setMessageObserver(obs);
  9. Message m = new MessageImpl();
  10. conduit.prepare(m);
  11. OutputStream os = m.getContent(OutputStream.class);
  12. InputStream is = getResourceAsStream(message);
  13. if (is == null) {
  14. throw new RuntimeException("Could not find resource " + message);
  15. }
  16. IOUtils.copy(is, os);
  17. // TODO: shouldn't have to do this. IO caching needs cleaning
  18. // up or possibly removal...
  19. os.flush();
  20. is.close();
  21. os.close();
  22. byte[] bs = obs.getResponseStream().toByteArray();
  23. return bs;
  24. }
  25. public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {

代码示例来源: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. /**
  2. * Read the entire original input stream and cache it. Useful
  3. * if switching threads or doing something where the original
  4. * stream may not be valid by the time the next read() occurs
  5. */
  6. public void cacheInput() {
  7. if (!cached) {
  8. CachedOutputStream cache = new CachedOutputStream();
  9. try {
  10. InputStream origIn = in;
  11. IOUtils.copy(in, cache);
  12. if (cache.size() > 0) {
  13. in = cache.getInputStream();
  14. } else {
  15. in = new ByteArrayInputStream(new byte[0]);
  16. }
  17. cache.close();
  18. origIn.close();
  19. } catch (IOException e) {
  20. //ignore
  21. }
  22. cached = true;
  23. }
  24. }

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

  1. public void onMessage(Message message) {
  2. try {
  3. contentType = (String)message.get(Message.CONTENT_TYPE);
  4. InputStream is = message.getContent(InputStream.class);
  5. try {
  6. IOUtils.copy(is, response);
  7. is.close();
  8. response.close();
  9. } catch (IOException e) {
  10. throw new RuntimeException(e);
  11. }
  12. } finally {
  13. synchronized (this) {
  14. written = true;
  15. notifyAll();
  16. }
  17. }
  18. }
  19. }

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

  1. public static String readBody(InputStream is, String encoding) {
  2. try {
  3. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  4. IOUtils.copy(is, bos, 1024);
  5. return new String(bos.toByteArray(), encoding);
  6. } catch (Exception ex) {
  7. throw ExceptionUtils.toInternalServerErrorException(ex, null);
  8. }
  9. }

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

  1. /**
  2. * Copied from LoggingInInterceptor
  3. *
  4. * @param soapMessage
  5. */
  6. private void getSoapRequest(Message soapMessage, ExchangeData exchange) {
  7. InputStream is = soapMessage.getContent(InputStream.class);
  8. if (is != null) {
  9. CachedOutputStream bos = new CachedOutputStream();
  10. try {
  11. IOUtils.copy(is, bos);
  12. bos.flush();
  13. is.close();
  14. soapMessage.setContent(InputStream.class, bos.getInputStream());
  15. StringBuilder builder = new StringBuilder();
  16. bos.writeCacheTo(builder, bos.size());
  17. bos.close();
  18. exchange.setRequest(builder.toString());
  19. exchange.setRequestSize((int)bos.size());
  20. } catch (IOException e) {
  21. throw new Fault(e);
  22. }
  23. }
  24. }

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

  1. public void echoData(Holder<String> text, Holder<DataHandler> data) {
  2. try {
  3. InputStream bis = null;
  4. bis = data.value.getDataSource().getInputStream();
  5. byte[] b = new byte[6];
  6. bis.read(b, 0, 6);
  7. String string = IOUtils.newStringFromBytes(b);
  8. ByteArrayDataSource source =
  9. new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
  10. data.value = new DataHandler(source);
  11. } catch (IOException e) {
  12. e.printStackTrace();
  13. }
  14. }

代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws

  1. public void handleMessage(Message message) throws Fault {
  2. BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
  3. if (bop != null && !bindingName.equals(bop.getBinding().getName())) {
  4. return;
  5. } else if (DataSource.class.isAssignableFrom(type)) {
  6. deser.initializeAttachments();
  7. } catch (IOException ex) {
  8. throw new Fault(ex);
  9. try {
  10. InputStream in = ds.getInputStream();
  11. IOUtils.copy(in, out);
  12. in.close();
  13. out.flush();
  14. out.close();
  15. } catch (IOException e) {
  16. throw new Fault(e);
  17. out = new CachedOutputStream();
  18. ds = new DOMSource(StaxUtils.read(ds));
  19. } catch (XMLStreamException e) {
  20. throw new Fault(e);

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

  1. public static int copyAndCloseInput(final InputStream input,
  2. final OutputStream output) throws IOException {
  3. try {
  4. return copy(input, output);
  5. } finally {
  6. input.close();
  7. }
  8. }

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

  1. public byte[] getBytes() throws IOException {
  2. flush();
  3. if (inmem) {
  4. if (currentStream instanceof ByteArrayOutputStream) {
  5. return ((ByteArrayOutputStream)currentStream).toByteArray();
  6. }
  7. throw new IOException("Unknown format of currentStream");
  8. }
  9. // read the file
  10. try (InputStream fin = createInputStream(tempFile)) {
  11. return IOUtils.readBytesFromStream(fin);
  12. }
  13. }

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

  1. public static String getStringFromInputStream(InputStream in) throws Exception {
  2. CachedOutputStream bos = new CachedOutputStream();
  3. IOUtils.copy(in, bos);
  4. in.close();
  5. bos.close();
  6. return bos.getOut().toString();
  7. }

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

  1. public void onMessage(Message message) {
  2. try {
  3. // HTTP seems to need this right now...
  4. ExchangeImpl ex = new ExchangeImpl();
  5. ex.setInMessage(message);
  6. Conduit backChannel = message.getDestination().getBackChannel(message);
  7. MessageImpl res = new MessageImpl();
  8. ex.setOutMessage(res);
  9. res.put(Message.CONTENT_TYPE, "text/xml");
  10. backChannel.prepare(res);
  11. OutputStream out = res.getContent(OutputStream.class);
  12. InputStream is = resource.openStream();
  13. IOUtils.copy(is, out, 2048);
  14. out.flush();
  15. out.close();
  16. is.close();
  17. backChannel.close(res);
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }

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

  1. public static String toString(final InputStream input, int bufferSize, String charset)
  2. throws IOException {
  3. int avail = input.available();
  4. if (avail > bufferSize) {
  5. bufferSize = avail;
  6. }
  7. Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET)
  8. : new InputStreamReader(input, charset);
  9. return toString(reader, bufferSize);
  10. }

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

  1. inMessage.setExchange(new ExchangeImpl());
  2. inMessage.getExchange().put(Bus.class, bus);
  3. inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
  4. InputStream in = inMessage.getContent(InputStream.class);
  5. if (in != null) {
  6. CachedOutputStream cos = new CachedOutputStream();
  7. IOUtils.copy(in, cos);
  8. inMessage.setContent(InputStream.class, cos.getInputStream());

代码示例来源: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. }

相关文章