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 07:34:10 UTC
[1/3] git commit: CAMEL-7209 Fixed the issue that
NIOConverter.toByteArray return bad data with thanks to Radek
Repository: camel
Updated Branches:
refs/heads/camel-2.12.x daac2ba31 -> d5811bab9
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/d35fb74b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d35fb74b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d35fb74b
Branch: refs/heads/camel-2.12.x
Commit: d35fb74b81c24b36aa71da59fe745eba5e315c67
Parents: daac2ba
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:33:08 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/d35fb74b/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/d35fb74b/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());
[3/3] git commit: CAMEL-7213 NIOConverter need to call flip() when we
put something into the buffer
Posted by ni...@apache.org.
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/d5811bab
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d5811bab
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d5811bab
Branch: refs/heads/camel-2.12.x
Commit: d5811bab9a6f48febd4ad7f9bcf7dc5d4373876c
Parents: 407cd12
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 14:29:46 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Feb 17 14:33:45 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/d5811bab/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 0bf08ac..41273b6 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/d5811bab/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 cd56200..bcd423b 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
@@ -78,40 +78,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());
}
[2/3] git commit: CAMEL-7209 Fixed the unit test failure of
XmlConverterTest
Posted by ni...@apache.org.
CAMEL-7209 Fixed the unit test failure of XmlConverterTest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/407cd129
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/407cd129
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/407cd129
Branch: refs/heads/camel-2.12.x
Commit: 407cd1297f1e3a3468983b0ba399bca98dd3f2e5
Parents: d35fb74
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 14:07:14 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Feb 17 14:33:35 2014 +0800
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/converter/NIOConverter.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/407cd129/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 9a2b60a..0bf08ac 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
@@ -99,6 +99,7 @@ public final class NIOConverter {
bytes = value.getBytes();
}
buf.put(bytes);
+ buf.flip();
return buf;
}