You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2013/12/26 16:31:34 UTC

git commit: CAMEL-7080: Do NOT copy&paste the Oracle licensed code inside the JDK (which could end up with legal issues) but better make use of the Camel own utilities. Removed the obsolete catch block (as the method signature is 'throws Exception' anywa

Updated Branches:
  refs/heads/master 3dbc9f979 -> bfd516ae8


CAMEL-7080: Do NOT copy&paste the Oracle licensed code inside the JDK (which could end up with legal issues) but better make use of the Camel own utilities. Removed the obsolete catch block (as the method signature is 'throws Exception' anyway). Also moved closing the stream into a finally block to avoid code-duplication.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bfd516ae
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bfd516ae
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bfd516ae

Branch: refs/heads/master
Commit: bfd516ae8c8a548c49ec384f60fef6a73cfad7a5
Parents: 3dbc9f9
Author: Babak Vahdat <bv...@apache.org>
Authored: Thu Dec 26 16:31:28 2013 +0100
Committer: Babak Vahdat <bv...@apache.org>
Committed: Thu Dec 26 16:31:28 2013 +0100

----------------------------------------------------------------------
 .../camel/dataformat/csv/CsvDataFormat.java     | 24 ++++----------------
 1 file changed, 5 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bfd516ae/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 da2651f..cfce7fa 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
@@ -29,11 +29,11 @@ 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;
 import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVStrategy;
 import org.apache.commons.csv.writer.CSVConfig;
@@ -107,13 +107,12 @@ public class CsvDataFormat implements DataFormat {
         try {
             CSVParser parser = createParser(in);
             if (parser == null) {
-                IOHelper.close(in);
-                return emptyIterator();
+                // return an empty Iterator
+                return ObjectHelper.createIterator(null);
             }
             csvIterator = new CsvIterator(parser, in);
-        } catch (IOException e) {
+        } finally {
             IOHelper.close(in);
-            throw e;
         }
         if (lazyLoad) {
             return csvIterator;
@@ -124,7 +123,7 @@ public class CsvDataFormat implements DataFormat {
     private CSVParser createParser(InputStreamReader in) throws IOException {
         CSVParser parser = new CSVParser(in, strategy);
         if (skipFirstLine) {
-            if (null == parser.getLine()) {
+            if (parser.getLine() == null) {
                 return null;
             }
         }
@@ -208,17 +207,4 @@ 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