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 2016/02/09 11:52:47 UTC
[2/2] camel git commit: CAMEL-7638: Reuse existing type converters
from base netty components.
CAMEL-7638: Reuse existing type converters from base netty components.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/365f6705
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/365f6705
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/365f6705
Branch: refs/heads/camel-2.16.x
Commit: 365f67053e041e59d380b24a02496ae23ae523ea
Parents: ec67150
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Feb 9 11:51:20 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Feb 9 11:52:38 2016 +0100
----------------------------------------------------------------------
.../apache/camel/component/netty/http/NettyHttpConverter.java | 7 +++----
.../camel/component/netty4/http/NettyHttpConverter.java | 4 +---
.../org/apache/camel/component/netty4/NettyConverter.java | 3 +++
3 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/365f6705/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java
index 9457d50..568d2a7 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConverter.java
@@ -16,13 +16,13 @@
*/
package org.apache.camel.component.netty.http;
-import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.apache.camel.FallbackConverter;
+import org.apache.camel.component.netty.NettyConverter;
import org.apache.camel.spi.TypeConverterRegistry;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
@@ -102,13 +102,12 @@ public final class NettyHttpConverter {
@Converter
public static byte[] toBytes(HttpResponse response, Exchange exchange) {
- return response.getContent().toByteBuffer().array();
+ return NettyConverter.toByteArray(response.getContent(), exchange);
}
@Converter
public static InputStream toInputStream(HttpResponse response, Exchange exchange) {
- byte[] bytes = toBytes(response, exchange);
- return new ByteArrayInputStream(bytes);
+ return NettyConverter.toInputStream(response.getContent(), exchange);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/365f6705/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConverter.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConverter.java
index 511c8671..69302ec 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConverter.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConverter.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.netty4.http;
-import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
@@ -111,8 +110,7 @@ public final class NettyHttpConverter {
@Converter
public static InputStream toInputStream(FullHttpResponse response, Exchange exchange) {
- byte[] bytes = toBytes(response, exchange);
- return new ByteArrayInputStream(bytes);
+ return NettyConverter.toInputStream(response.content(), exchange);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/365f6705/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConverter.java b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConverter.java
index bc8065e..780e1fe 100644
--- a/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConverter.java
+++ b/components/camel-netty4/src/main/java/org/apache/camel/component/netty4/NettyConverter.java
@@ -51,6 +51,9 @@ public final class NettyConverter {
@Converter
public static byte[] toByteArray(ByteBuf buffer, Exchange exchange) {
+ if (buffer.hasArray()) {
+ return buffer.array();
+ }
byte[] bytes = new byte[buffer.readableBytes()];
int readerIndex = buffer.readerIndex();
buffer.getBytes(readerIndex, bytes);