This is an automated email from the ASF dual-hosted git repository. siano pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new dcb524a CAMEL-12008: Add type converter from byte array to java.io.Reader dcb524a is described below commit dcb524af64b47c1886e74e5e1ec60dfc96855dfc Author: Stephan Siano <stephan.si...@sap.com> AuthorDate: Tue Nov 14 16:01:26 2017 +0100 CAMEL-12008: Add type converter from byte array to java.io.Reader --- .../src/main/java/org/apache/camel/converter/IOConverter.java | 5 +++++ .../test/java/org/apache/camel/converter/IOConverterTest.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java index 72dab06..310425f 100644 --- a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java +++ b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java @@ -182,6 +182,11 @@ public final class IOConverter { return IOHelper.buffered(new InputStreamReader(in, IOHelper.getCharsetName(exchange))); } + @Converter + public static Reader toReader(byte[] data, Exchange exchange) throws IOException { + return toReader(new ByteArrayInputStream(data), exchange); + } + /** * @deprecated will be removed in Camel 3.0. Use the method which has 2 parameters. */ diff --git a/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java index 87d4caa..3dc5793 100644 --- a/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java +++ b/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java @@ -94,6 +94,15 @@ public class IOConverterTest extends ContextTestSupport { assertEquals("Hello", IOConverter.toString(reader)); } + public void testBytesToReader() throws Exception { + Exchange exchange = new DefaultExchange(context); + String defaultCharacterSet = ObjectHelper.getDefaultCharacterSet(); + exchange.setProperty(Exchange.CHARSET_NAME, defaultCharacterSet); + byte[] bytes = "Hello World".getBytes(defaultCharacterSet); + Reader reader = IOConverter.toReader(bytes, exchange); + assertEquals("Hello World", IOConverter.toString(reader)); + } + public void testToInputStreamExchange() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, ObjectHelper.getDefaultCharacterSet()); -- To stop receiving notification emails like this one, please contact ['"commits@camel.apache.org" <commits@camel.apache.org>'].