camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] git commit: CAMEL-6718: Marshal should leverage stream caching if enabled. Thanks to Franz Forsthofer for patch.
Date Tue, 10 Sep 2013 09:11:29 GMT
Updated Branches:
  refs/heads/camel-2.12.x 4d7e7e187 -> 19c96be7b


CAMEL-6718: Marshal should leverage stream caching if enabled. Thanks to Franz Forsthofer
for patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3d1b979c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3d1b979c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3d1b979c

Branch: refs/heads/camel-2.12.x
Commit: 3d1b979c08d054d67cd53e0a7cb66d7fc0dba374
Parents: 19df5be
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 10 10:26:35 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 10 11:11:18 2013 +0200

----------------------------------------------------------------------
 .../camel/processor/MarshalProcessor.java       | 27 ++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3d1b979c/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
index 2c47081..c26d00a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/MarshalProcessor.java
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContextAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Traceable;
+import org.apache.camel.converter.stream.CachedOutputStream;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.AsyncProcessorHelper;
@@ -35,7 +36,7 @@ import org.apache.camel.util.ServiceHelper;
  * Marshals the body of the incoming message using the given
  * <a href="http://camel.apache.org/data-format.html">data format</a>
  *
- * @version 
+ * @version
  */
 public class MarshalProcessor extends ServiceSupport implements AsyncProcessor, Traceable,
CamelContextAware {
     private CamelContext camelContext;
@@ -52,7 +53,18 @@ public class MarshalProcessor extends ServiceSupport implements AsyncProcessor,
     public boolean process(Exchange exchange, AsyncCallback callback) {
         ObjectHelper.notNull(dataFormat, "dataFormat");
 
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        // if stream caching is enabled then use that so we can stream accordingly
+        // for example to overflow to disk for big streams
+        CachedOutputStream cos;
+        ByteArrayOutputStream os;
+        if (exchange.getContext().getStreamCachingStrategy().isEnabled()) {
+            cos = new CachedOutputStream(exchange);
+            os = null;
+        } else {
+            cos = null;
+            os = new ByteArrayOutputStream();
+        }
+
         Message in = exchange.getIn();
         Object body = in.getBody();
 
@@ -62,9 +74,14 @@ public class MarshalProcessor extends ServiceSupport implements AsyncProcessor,
         out.copyFrom(in);
 
         try {
-            dataFormat.marshal(exchange, body, buffer);
-            byte[] data = buffer.toByteArray();
-            out.setBody(data);
+            dataFormat.marshal(exchange, body, os);
+
+            if (cos != null) {
+                out.setBody(cos.newStreamCache());
+            } else {
+                byte[] data = os.toByteArray();
+                out.setBody(data);
+            }
         } catch (Exception e) {
             // remove OUT message, as an exception occurred
             exchange.setOut(null);


Mime
View raw message