You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/02/17 06:25:08 UTC
git commit: CAMEL-7209 Fixed the issue that NIOConverter.toByteArray
return bad data with thanks to Radek
Repository: camel
Updated Branches:
refs/heads/master fe052fc92 -> 2cf59955d
CAMEL-7209 Fixed the issue that NIOConverter.toByteArray return bad data with thanks to Radek
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2cf59955
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2cf59955
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2cf59955
Branch: refs/heads/master
Commit: 2cf59955dda8c4c0f5334f2aed426659b7a708f2
Parents: fe052fc
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 13:24:25 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Feb 17 13:24:25 2014 +0800
----------------------------------------------------------------------
.../java/org/apache/camel/converter/NIOConverter.java | 4 +++-
.../org/apache/camel/converter/NIOConverterTest.java | 14 ++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2cf59955/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java b/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
index c0bff94..9a2b60a 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/NIOConverter.java
@@ -47,7 +47,9 @@ public final class NIOConverter {
@Converter
public static byte[] toByteArray(ByteBuffer buffer) {
- return buffer.array();
+ byte[] bArray = new byte[buffer.limit()];
+ buffer.get(bArray);
+ return bArray;
}
@Converter
http://git-wip-us.apache.org/repos/asf/camel/blob/2cf59955/camel-core/src/test/java/org/apache/camel/converter/NIOConverterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/NIOConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/NIOConverterTest.java
index 78a571f..cd56200 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/NIOConverterTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/NIOConverterTest.java
@@ -34,6 +34,20 @@ public class NIOConverterTest extends ContextTestSupport {
assertNotNull(out);
assertEquals(5, out.length);
}
+
+ /**
+ * Test if returned array size is only to limit of ByteBuffer.
+ *
+ * If byteBuffer capacity is bigger that limit, we MUST return data only to the limit.
+ */
+ public void testToByteArrayBigBuffer() {
+ ByteBuffer bb = ByteBuffer.allocate(100);
+ bb.put("Hello".getBytes());
+ bb.flip();
+ byte[] out = NIOConverter.toByteArray(bb);
+ assertNotNull(out);
+ assertEquals(5, out.length);
+ }
public void testToString() throws Exception {
ByteBuffer bb = ByteBuffer.wrap("Hello".getBytes());