camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: CAMEL-10714 Replace ByteArrayOutputStream with OutputStreamBuilder
Date Fri, 03 Feb 2017 20:05:14 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x b265e3cfa -> 799b78d94
  refs/heads/master fa7d80731 -> 5f566e096


CAMEL-10714 Replace ByteArrayOutputStream with OutputStreamBuilder


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

Branch: refs/heads/master
Commit: 705f02dc511abd2241e4df5121f7deb5cf567b46
Parents: fa7d807
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Fri Feb 3 16:08:35 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Feb 3 20:33:33 2017 +0100

----------------------------------------------------------------------
 .../component/jetty9/JettyContentExchange9.java | 27 ++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/705f02dc/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
index 50f2e43..1f66312 100644
--- a/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
+++ b/components/camel-jetty9/src/main/java/org/apache/camel/component/jetty9/JettyContentExchange9.java
@@ -37,8 +37,10 @@ import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.StreamCache;
 import org.apache.camel.component.jetty.JettyContentExchange;
 import org.apache.camel.component.jetty.JettyHttpBinding;
+import org.apache.camel.converter.stream.OutputStreamBuilder;
 import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.api.Request;
 import org.eclipse.jetty.client.api.Response;
@@ -222,15 +224,18 @@ public class JettyContentExchange9 implements JettyContentExchange {
         };
 
         InputStreamResponseListener responseListener = new InputStreamResponseListener()
{
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
 
             @Override
             public void onContent(Response response, ByteBuffer content, Callback callback)
{
                 byte[] buffer = new byte[content.limit()];
                 content.get(buffer);
-                baos.write(buffer, 0, buffer.length);
-
-                callback.succeeded();
+                try {
+                    osb.write(buffer);
+                    callback.succeeded();
+                } catch (IOException e) {
+                    callback.failed(e);
+                }
             }
 
             @Override
@@ -238,7 +243,19 @@ public class JettyContentExchange9 implements JettyContentExchange {
                 if (result.isFailed()) {
                     doTaskCompleted(result.getFailure());
                 } else {
-                    onResponseComplete(result, baos.toByteArray());
+                    try {
+                        Object content = osb.build();
+                        if (content instanceof byte[]) {
+                            onResponseComplete(result, (byte[]) content);
+                        } else {
+                            StreamCache cos = (StreamCache) content;
+                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                            cos.writeTo(baos);
+                            onResponseComplete(result, baos.toByteArray());
+                        }
+                    } catch (IOException e) {
+                        doTaskCompleted(e);
+                    }
                 }
             }
         };


Mime
View raw message