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 2013/12/25 04:19:41 UTC
git commit: CAMEL-7080 Fixed JDK6 build and unit test error
Updated Branches:
refs/heads/master 2c3239eed -> 19b05db67
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/19b05db6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/19b05db6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/19b05db6
Branch: refs/heads/master
Commit: 19b05db67d085d2294be72915aded47f1ef24e02
Parents: 2c3239e
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 25 11:19:17 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 25 11:19:17 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/19b05db6/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/19b05db6/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();
-
+
}
}