Updated Branches: refs/heads/camel-2.12.x 79b6f562d -> 8c252179f
CAMEL-7080 Fixed JDK6 build and unit test error Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8c252179 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8c252179 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8c252179 Branch: refs/heads/camel-2.12.x Commit: 8c252179fb3f04a2f8c936a79461229e59a750e0 Parents: 79b6f56 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Wed Dec 25 11:19:17 2013 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Wed Dec 25 11:20:20 2013 +0800 ---------------------------------------------------------------------- .../camel/dataformat/csv/CsvDataFormat.java | 20 ++++++++++++++++++-- .../camel/dataformat/csv/CsvIteratorTest.java | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/8c252179/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java index 0396b83..da2651f 100644 --- a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java +++ b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java @@ -23,11 +23,13 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.ArrayList; -import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; + import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; import org.apache.camel.util.ExchangeHelper; @@ -106,7 +108,7 @@ public class CsvDataFormat implements DataFormat { CSVParser parser = createParser(in); if (parser == null) { IOHelper.close(in); - return Collections.emptyIterator(); + return emptyIterator(); } csvIterator = new CsvIterator(parser, in); } catch (IOException e) { @@ -205,4 +207,18 @@ public class CsvDataFormat implements DataFormat { } } } + + @SuppressWarnings("unchecked") + public static <T> Iterator<T> emptyIterator() { + return (Iterator<T>) EmptyIterator.EMPTY_ITERATOR; + } + + private static class EmptyIterator<E> implements Iterator<E> { + static final EmptyIterator<Object> EMPTY_ITERATOR + = new EmptyIterator<Object>(); + + public boolean hasNext() { return false; } + public E next() { throw new NoSuchElementException(); } + public void remove() { throw new IllegalStateException(); } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/8c252179/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvIteratorTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvIteratorTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvIteratorTest.java index 385123b..091faf6 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvIteratorTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvIteratorTest.java @@ -46,10 +46,12 @@ public class CsvIteratorTest { parser.getLine(); result = new IOException(HDD_CRASH); + // The reader will be closed when there is nothing left reader.close(); } }; + @SuppressWarnings("resource") CsvIterator iterator = new CsvIterator(parser, reader); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Arrays.asList("1"), iterator.next()); @@ -70,7 +72,6 @@ public class CsvIteratorTest { } catch (NoSuchElementException e) { // okay } - iterator.close(); } @Test @@ -87,10 +88,12 @@ public class CsvIteratorTest { parser.getLine(); result = null; + // The reader will be closed when there is nothing left reader.close(); } }; + @SuppressWarnings("resource") CsvIterator iterator = new CsvIterator(parser, reader); Assert.assertTrue(iterator.hasNext()); Assert.assertEquals(Arrays.asList("1"), iterator.next()); @@ -106,7 +109,6 @@ public class CsvIteratorTest { } catch (NoSuchElementException e) { // okay } - iterator.close(); - + } }