Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8731510E3D for ; Wed, 26 Feb 2014 02:12:14 +0000 (UTC) Received: (qmail 82092 invoked by uid 500); 26 Feb 2014 02:12:13 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 82054 invoked by uid 500); 26 Feb 2014 02:12:13 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 82047 invoked by uid 99); 26 Feb 2014 02:12:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Feb 2014 02:12:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id E040B92D52E; Wed, 26 Feb 2014 02:12:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Message-Id: <113e38b341e041d7bb0ecde097dd5785@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-7241 Fixed the ByteBuffer to String conversion issue Date: Wed, 26 Feb 2014 02:12:12 +0000 (UTC) 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 Authored: Wed Feb 26 10:11:58 2014 +0800 Committer: Willem Jiang 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());