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:50 UTC
[1/5] git commit: CAMEL-7241 Fixed the ByteBuffer to String
conversion issue
Repository: camel
Updated Branches:
refs/heads/camel-2.11.x 06734f1d3 -> 27f00bef2
refs/heads/camel-2.12.x b493aa973 -> f121cf980
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/f121cf98
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f121cf98
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f121cf98
Branch: refs/heads/camel-2.12.x
Commit: f121cf9809cdbf900d53343221d0d81076b209b4
Parents: b493aa9
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Feb 26 10:11:58 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 26 10:20:19 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/f121cf98/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/f121cf98/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());
[3/5] git commit: CAMEL-7209 Fixed the issue that
NIOConverter.toByteArray return bad data with thanks to Radek
Posted by ni...@apache.org.
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/285dc7aa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/285dc7aa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/285dc7aa
Branch: refs/heads/camel-2.11.x
Commit: 285dc7aa1c5427922aace33aa96fa5d298563347
Parents: 06292ae
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 13:24:25 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 26 10:32:06 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/285dc7aa/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 42df28d..d0f86e7 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/285dc7aa/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 3d85e5e..f1be12b 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());
[2/5] git commit: CAMEL-7241 Fixed the ByteBuffer to String
conversion issue
Posted by ni...@apache.org.
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/06292ae0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/06292ae0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/06292ae0
Branch: refs/heads/camel-2.11.x
Commit: 06292ae0a983087ad688e7ee623a8268068759b8
Parents: 06734f1
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Feb 26 10:11:58 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 26 10:20:29 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/06292ae0/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 376cbea..42df28d 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
@@ -52,7 +52,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/06292ae0/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..3d85e5e 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
@@ -41,6 +41,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());
[4/5] 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/daafa49d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/daafa49d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/daafa49d
Branch: refs/heads/camel-2.11.x
Commit: daafa49d4958cbb0f5624511ade7db76e3bcb170
Parents: 285dc7a
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Feb 17 14:07:14 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 26 10:32:21 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/daafa49d/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 d0f86e7..26f489c 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;
}
[5/5] 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/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());
}