camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7241 Fixed the ByteBuffer to String conversion issue
Date Wed, 26 Feb 2014 02:12:12 GMT
Repository: camel
Updated Branches:
  refs/heads/master 92200b5f8 -> 18c23fa82


CAMEL-7241 Fixed the ByteBuffer to String conversion issue


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

Branch: refs/heads/master
Commit: 18c23fa82a7e7ccb5593de1a070c9a562c8083e1
Parents: 92200b5
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Feb 26 10:11:58 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Feb 26 10:11:58 2014 +0800

----------------------------------------------------------------------
 .../java/org/apache/camel/converter/NIOConverter.java |  2 +-
 .../org/apache/camel/converter/NIOConverterTest.java  | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/18c23fa8/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 41273b6..e1cf6d6 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
@@ -54,7 +54,7 @@ public final class NIOConverter {
 
     @Converter
     public static String toString(ByteBuffer buffer, Exchange exchange) throws IOException
{
-        return IOConverter.toString(buffer.array(), exchange);
+        return IOConverter.toString(toByteArray(buffer), exchange);
     }
 
     @Converter

http://git-wip-us.apache.org/repos/asf/camel/blob/18c23fa8/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 bcd423b..8e02529 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
@@ -55,6 +55,20 @@ public class NIOConverterTest extends ContextTestSupport {
         assertNotNull(out);
         assertEquals("Hello", out);
     }
+    
+    /**
+     * ToString need to deal the array size issue as ToByteArray does 
+     */
+    public void testByteBufferToStringConversion() throws Exception {
+        String str = "123456789";
+        ByteBuffer buffer = ByteBuffer.allocate(16);
+        buffer.put(str.getBytes());
+        buffer.flip();
+
+        String out = NIOConverter.toString(buffer, null);
+        assertEquals(str, out);
+    }
+    
 
     public void testToByteBuffer() {
         ByteBuffer bb = NIOConverter.toByteBuffer("Hello".getBytes());


Mime
View raw message