Hi Claus, Thanks for pointing that out, I just committed a quick fix for it.
Regards, -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (English) http://jnn.iteye.com (Chinese) Twitter: willemjiang Weibo: 姜宁willem On September 28, 2014 at 1:28:22 PM, Claus Ibsen ([email protected]) wrote: > Hi > > Please use the unicode number of the non Ascii chars in the source > code, eg \uNNNN instead of those A characters. > > On Sun, Sep 28, 2014 at 5:30 AM, wrote: > > Repository: camel > > Updated Branches: > > refs/heads/master bd06a4a5f -> c9e1bc87e > > > > > > CAMEL-7876 ensure GroupIterator uses the exchange's CHARSET_NAME property > > > > > > Project: http://git-wip-us.apache.org/repos/asf/camel/repo > > Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/80518e29 > > Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/80518e29 > > Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/80518e29 > > > > Branch: refs/heads/master > > Commit: 80518e29d93745bcad341e5c02bef8a0e31ece61 > > Parents: bd06a4a > > Author: Tom Ellis > > Authored: Sat Sep 27 17:27:33 2014 +0100 > > Committer: Willem Jiang > > Committed: Sun Sep 28 11:17:55 2014 +0800 > > > > ---------------------------------------------------------------------- > > .../apache/camel/builder/ExpressionBuilder.java | 2 +- > > .../org/apache/camel/util/GroupIterator.java | 14 ++++---- > > .../apache/camel/util/GroupIteratorTest.java | 35 +++++++++++++++++++- > > 3 files changed, 42 insertions(+), 9 deletions(-) > > ---------------------------------------------------------------------- > > > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/80518e29/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java > > > > ---------------------------------------------------------------------- > > diff --git > > a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java > b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java > > index 4473fe7..20f00b9 100644 > > --- > > a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java > > +++ > > b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java > > @@ -1294,7 +1294,7 @@ public final class ExpressionBuilder { > > // evaluate expression as iterator > > Iterator it = expression.evaluate(exchange, Iterator.class); > > ObjectHelper.notNull(it, "expression: " + expression + " evaluated on " + > > exchange > + " must return an java.util.Iterator"); > > - return new GroupIterator(exchange.getContext(), it, token, group); > > + return new GroupIterator(exchange, it, token, group); > > } > > > > @Override > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/80518e29/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java > > > > ---------------------------------------------------------------------- > > diff --git > > a/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java > b/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java > > index 158dbed..4b6f9ad 100644 > > --- a/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java > > +++ b/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java > > @@ -23,7 +23,7 @@ import java.io.InputStream; > > import java.util.Iterator; > > import java.util.Scanner; > > > > -import org.apache.camel.CamelContext; > > +import org.apache.camel.Exchange; > > import org.apache.camel.NoTypeConversionAvailableException; > > > > /** > > @@ -37,7 +37,7 @@ import > > org.apache.camel.NoTypeConversionAvailableException; > > */ > > public final class GroupIterator implements Iterator, Closeable { > > > > - private final CamelContext camelContext; > > + private final Exchange exchange; > > private final Iterator it; > > private final String token; > > private final int group; > > @@ -53,8 +53,8 @@ public final class GroupIterator implements Iterator, > Closeable { > > * @param group number of parts to group together > > * @throws IllegalArgumentException is thrown if group is not a positive > > number > > */ > > - public GroupIterator(CamelContext camelContext, Iterator it, String > > token, > int group) { > > - this.camelContext = camelContext; > > + public GroupIterator(Exchange exchange, Iterator it, String token, int > > group) > { > > + this.exchange = exchange; > > this.it = it; > > this.token = token; > > this.group = group; > > @@ -130,15 +130,15 @@ public final class GroupIterator implements Iterator, > > > Closeable { > > bos.write(bytes); > > } else if (data != null) { > > // convert to input stream > > - InputStream is = > > camelContext.getTypeConverter().mandatoryConvertTo(InputStream.class, > data); > > + InputStream is = > > exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, > > > data); > > IOHelper.copy(is, bos); > > } > > > > count++; > > } > > > > - // prepare and return answer as String > > - String answer = bos.toString(); > > + // prepare and return answer as String using exchange's charset > > + String answer = bos.toString(IOHelper.getCharsetName(exchange)); > > bos.reset(); > > return answer; > > } > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/80518e29/camel-core/src/test/java/org/apache/camel/util/GroupIteratorTest.java > > > > ---------------------------------------------------------------------- > > diff --git > > a/camel-core/src/test/java/org/apache/camel/util/GroupIteratorTest.java > b/camel-core/src/test/java/org/apache/camel/util/GroupIteratorTest.java > > index 4dbbac5..c5c3e33 100644 > > --- a/camel-core/src/test/java/org/apache/camel/util/GroupIteratorTest.java > > > > +++ b/camel-core/src/test/java/org/apache/camel/util/GroupIteratorTest.java > > > > @@ -16,11 +16,17 @@ > > */ > > package org.apache.camel.util; > > > > +import java.io.ByteArrayInputStream; > > +import java.nio.charset.Charset; > > +import java.nio.charset.StandardCharsets; > > +import java.util.Arrays; > > import java.util.Scanner; > > > > import org.apache.camel.CamelContext; > > +import org.apache.camel.Exchange; > > import org.apache.camel.TestSupport; > > import org.apache.camel.impl.DefaultCamelContext; > > +import org.apache.camel.impl.DefaultExchange; > > > > /** > > * > > @@ -28,12 +34,15 @@ import org.apache.camel.impl.DefaultCamelContext; > > public class GroupIteratorTest extends TestSupport { > > > > private CamelContext context; > > + private Exchange exchange; > > > > @Override > > public void setUp() throws Exception { > > super.setUp(); > > context = new DefaultCamelContext(); > > context.start(); > > + exchange = new DefaultExchange(context); > > + > > } > > > > @Override > > @@ -47,7 +56,7 @@ public class GroupIteratorTest extends TestSupport { > > Scanner scanner = new Scanner(s); > > scanner.useDelimiter("\n"); > > > > - GroupIterator gi = new GroupIterator(context, scanner, "\n", 3); > > + GroupIterator gi = new GroupIterator(exchange, scanner, "\n", 3); > > > > assertTrue(gi.hasNext()); > > assertEquals("ABC\nDEF\nGHI", gi.next()); > > @@ -58,4 +67,28 @@ public class GroupIteratorTest extends TestSupport { > > IOHelper.close(gi); > > } > > > > + public void testGroupIteratorWithDifferentEncodingFromDefault() throws > > Exception > { > > + if (Charset.defaultCharset() == StandardCharsets.UTF_8) { > > + // can't think of test case where having default charset set to UTF-8 is > > affected > > + return; > > + } > > + > > + byte[] buf = "£1\n£2\n".getBytes(StandardCharsets.UTF_8); > > + > > + ByteArrayInputStream in = new ByteArrayInputStream(buf); > > + > > + Scanner scanner = new Scanner(in, StandardCharsets.UTF_8.displayName()); > > + scanner.useDelimiter("\n"); > > + > > + exchange.setProperty(Exchange.CHARSET_NAME, > > StandardCharsets.UTF_8.displayName()); > > + GroupIterator gi = new GroupIterator(exchange, scanner, "\n", 1); > > + > > + assertTrue(gi.hasNext()); > > + assertEquals("£1", gi.next()); > > + assertEquals("£2", gi.next()); > > + assertFalse(gi.hasNext()); > > + > > + IOHelper.close(gi); > > + } > > + > > } > > > > > > -- > Claus Ibsen > ----------------- > Red Hat, Inc. > Email: [email protected] > Twitter: davsclaus > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen > hawtio: http://hawt.io/ > fabric8: http://fabric8.io/ >
