You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/03 08:43:04 UTC

[camel] branch main updated: CAMEL-17266: camel-google-storage - Include body should use stream caching

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new f7c75ac  CAMEL-17266: camel-google-storage - Include body should use stream caching
f7c75ac is described below

commit f7c75ac4912f59eb0b5b4e541b18a13ffc97ff3a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 3 09:42:23 2021 +0100

    CAMEL-17266: camel-google-storage - Include body should use stream caching
---
 .../component/google/storage/GoogleCloudStorageConsumer.java   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
index ef00abf..8891ecc 100644
--- a/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
+++ b/components/camel-google/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConsumer.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.google.storage;
 
-import java.io.ByteArrayOutputStream;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
@@ -38,6 +37,7 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.Synchronization;
 import org.apache.camel.support.EmptyAsyncCallback;
 import org.apache.camel.support.ScheduledBatchPollingConsumer;
+import org.apache.camel.support.builder.OutputStreamBuilder;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -271,9 +271,11 @@ public class GoogleCloudStorageConsumer extends ScheduledBatchPollingConsumer {
 
         if (getConfiguration().isIncludeBody()) {
             try {
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                blob.downloadTo(baos);
-                message.setBody(baos.toByteArray());
+                // if stream caching is enabled then use that so we can stream accordingly
+                // for example to overflow to disk for big streams
+                OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
+                blob.downloadTo(osb);
+                message.setBody(osb.build());
             } catch (Exception e) {
                 throw new RuntimeCamelException(e);
             }