use of org.apache.camel.converter.stream.CachedOutputStream in project camel by apache.
the class JcloudsBlobStoreConsumer method poll.
@Override
protected int poll() throws Exception {
shutdownRunningTask = null;
pendingExchanges = 0;
Queue<Exchange> queue = new LinkedList<Exchange>();
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));
}
use of org.apache.camel.converter.stream.CachedOutputStream in project camel by apache.
the class RestletHelper method readResponseBodyFromInputStream.
/**
* 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 java.io.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();
}
}
use of org.apache.camel.converter.stream.CachedOutputStream in project camel by apache.
the class HttpHelper method readRequestBodyFromInputStream.
/**
* 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();
}
}
use of org.apache.camel.converter.stream.CachedOutputStream in project camel by apache.
the class JettyChuckedFalseTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:{{port}}/test?matchOnUriPrefix=true&chunked=false").to("http://localhost:{{port2}}/other?bridgeEndpoint=true");
from("jetty:http://localhost:{{port2}}/other").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "image/jpeg");
CachedOutputStream stream = new CachedOutputStream(exchange);
stream.write("This is hello world.".getBytes());
exchange.getOut().setBody(stream.getInputStream());
IOHelper.close(stream);
}
});
}
};
}
Aggregations