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(); } }
try { StaxUtils.copy(reader, cos); li.set(new StreamSourceCache(cos.newStreamCache())); try { xml.toResult(source, sr); li.set(new StreamSourceCache(cos.newStreamCache()));
@Override protected int poll() throws Exception { shutdownRunningTask = null; pendingExchanges = 0; Queue<Exchange> queue = new LinkedList<>(); String directory = endpoint.getDirectory(); ListContainerOptions opt = new ListContainerOptions(); if (!Strings.isNullOrEmpty(directory)) { opt = opt.inDirectory(directory); } for (StorageMetadata md : blobStore.list(container, opt.maxResults(maxMessagesPerPoll).recursive())) { String blobName = md.getName(); if (md.getType().equals(StorageType.BLOB)) { if (!Strings.isNullOrEmpty(blobName)) { InputStream body = JcloudsBlobStoreHelper.readBlob(blobStore, container, blobName); if (body != null) { Exchange exchange = endpoint.createExchange(); CachedOutputStream cos = new CachedOutputStream(exchange); IOHelper.copy(body, cos); exchange.getIn().setBody(cos.newStreamCache()); exchange.setProperty(JcloudsConstants.BLOB_NAME, blobName); queue.add(exchange); } } } } return queue.isEmpty() ? 0 : processBatch(CastUtils.cast(queue)); }
/** * 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(); } }