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/26 03:33:54 UTC

[5/5] git commit: CAMEL-7213 NIOConverter need to call flip() when we put something into the buffer

CAMEL-7213 NIOConverter need to call flip() when we put something into the buffer


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

Branch: refs/heads/camel-2.11.x
Commit: 27f00bef24ecbf055ec0ce26b07de6a61046e41b
Parents: daafa49
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 14:29:46 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 26 10:32:37 2014 +0800

----------------------------------------------------------------------
 .../java/org/apache/camel/converter/NIOConverter.java     |  5 +++++
 .../java/org/apache/camel/converter/NIOConverterTest.java | 10 ----------
 2 files changed, 5 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/27f00bef/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 26f489c..408babe 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
@@ -107,6 +107,7 @@ public final class NIOConverter {
     public static ByteBuffer toByteBuffer(Short value) {
         ByteBuffer buf = ByteBuffer.allocate(2);
         buf.putShort(value);
+        buf.flip();
         return buf;
     }
 
@@ -114,6 +115,7 @@ public final class NIOConverter {
     public static ByteBuffer toByteBuffer(Integer value) {
         ByteBuffer buf = ByteBuffer.allocate(4);
         buf.putInt(value);
+        buf.flip();
         return buf;
     }
 
@@ -121,6 +123,7 @@ public final class NIOConverter {
     public static ByteBuffer toByteBuffer(Long value) {
         ByteBuffer buf = ByteBuffer.allocate(8);
         buf.putLong(value);
+        buf.flip();
         return buf;
     }
 
@@ -128,6 +131,7 @@ public final class NIOConverter {
     public static ByteBuffer toByteBuffer(Float value) {
         ByteBuffer buf = ByteBuffer.allocate(4);
         buf.putFloat(value);
+        buf.flip();
         return buf;
     }
 
@@ -135,6 +139,7 @@ public final class NIOConverter {
     public static ByteBuffer toByteBuffer(Double value) {
         ByteBuffer buf = ByteBuffer.allocate(8);
         buf.putDouble(value);
+        buf.flip();
         return buf;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/27f00bef/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 f1be12b..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
@@ -92,40 +92,30 @@ public class NIOConverterTest extends ContextTestSupport {
     public void testToByteBufferShort() {
         ByteBuffer bb = NIOConverter.toByteBuffer(Short.valueOf("2"));
         assertNotNull(bb);
-
-        bb.position(0);
         assertEquals(2, bb.getShort());
     }
 
     public void testToByteBufferInteger() {
         ByteBuffer bb = NIOConverter.toByteBuffer(Integer.valueOf("2"));
         assertNotNull(bb);
-
-        bb.position(0);
         assertEquals(2, bb.getInt());
     }
 
     public void testToByteBufferLong() {
         ByteBuffer bb = NIOConverter.toByteBuffer(Long.valueOf("2"));
         assertNotNull(bb);
-
-        bb.position(0);
         assertEquals(2, bb.getLong());
     }
 
     public void testToByteBufferDouble() {
         ByteBuffer bb = NIOConverter.toByteBuffer(Double.valueOf("2"));
         assertNotNull(bb);
-
-        bb.position(0);
         assertEquals(2.0d, bb.getDouble());
     }
 
     public void testToByteBufferFloat() {
         ByteBuffer bb = NIOConverter.toByteBuffer(Float.valueOf("2"));
         assertNotNull(bb);
-
-        bb.position(0);
         assertEquals(2.0f, bb.getFloat());
     }