InputStream is = new ByteArrayInputStream(combined.getBytes()); OutputStream os = new FileOutputStream(file, false); IOHelper.copyAndCloseInput(is, os); IOHelper.close(os);
private byte[] readMimePart(InputStream mimePartStream) throws Exception { // mimePartStream could be base64 encoded, or not, but we don't need to worry about it as // Camel is smart enough to wrap it in a decoder stream (eg Base64DecoderStream) when required ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOHelper.copyAndCloseInput(mimePartStream, bos); return bos.toByteArray(); }
private static Object extractResponseBodyAsStream(final InputStream is, final Exchange exchange) { // As httpclient is using a AutoCloseInputStream, it will be closed when the connection is closed // we need to cache the stream for it. if (is == null) { return null; } // convert the input stream to StreamCache if the stream cache is not disabled if (exchange.getProperty(DISABLE_HTTP_STREAM_CACHE, FALSE, Boolean.class)) { return is; } else { try (final CachedOutputStream cos = new CachedOutputStream(exchange)) { // This CachedOutputStream will not be closed when the exchange is onCompletion IOHelper.copyAndCloseInput(is, cos); // When the InputStream is closed, the CachedOutputStream will be closed return cos.newStreamCache(); } catch (IOException ex) { LOGGER.debug("Error extracting body from http request", ex); return null; } } } }
/** * Reads the response body from the given input stream. * * @param is the input stream * @param exchange the exchange * @return the response body, can be <tt>null</tt> if no body * @throws IOException is thrown if error reading response body */ public static Object readResponseBodyFromInputStream(InputStream is, Exchange exchange) throws IOException { if (is == null) { return null; } // convert the input stream to StreamCache if the stream cache is not disabled if (exchange.getProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.FALSE, Boolean.class)) { return is; } else { CachedOutputStream cos = new CachedOutputStream(exchange); IOHelper.copyAndCloseInput(is, cos); return cos.newStreamCache(); } }
IOHelper.copyAndCloseInput(is, stream); } else { throw new InvalidPayloadException(exchange, JAXBElement.class);
IOHelper.copyAndCloseInput(is, stream);
MessageHelper.copyHeaders(exchange.getIn(), camelMessage, true); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOHelper.copyAndCloseInput(stream, bos); InternetHeaders headers = new InternetHeaders(); extractHeader(CONTENT_TYPE, camelMessage, headers);
/** * Reads the response body from the given input stream. * * @param is the input stream * @param exchange the exchange * @return the response body, can be <tt>null</tt> if no body * @throws IOException is thrown if error reading response body */ public static Object readRequestBodyFromInputStream(InputStream is, Exchange exchange) throws IOException { if (is == null) { return null; } boolean disableStreamCaching = false; // Just take the consideration of the setting of Camel Context StreamCaching if (exchange.getContext() instanceof DefaultCamelContext) { DefaultCamelContext context = (DefaultCamelContext) exchange.getContext(); disableStreamCaching = !context.isStreamCaching(); } // convert the input stream to StreamCache if the stream cache is not disabled if (exchange.getProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, disableStreamCaching, Boolean.class)) { return is; } else { CachedOutputStream cos = new CachedOutputStream(exchange); IOHelper.copyAndCloseInput(is, cos); return cos.newStreamCache(); } }
IOHelper.copyAndCloseInput(is, bos);
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext(), sftpConfig.getPrivateKeyUri()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOHelper.copyAndCloseInput(is, bos); jsch.addIdentity("ID", bos.toByteArray(), null, passphrase); } catch (IOException e) {
IOHelper.copyAndCloseInput(is, sigOut); } finally { IOHelper.close(sigOut);