Cosmetic improvements in CSV parser
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Nov 2012 16:20:56 +0000 (16:20 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 12 Nov 2012 16:20:56 +0000 (16:20 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5776 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java

index 127d0f50928f9b358c5f376a9ba8704f9d9ba697..1f614b8b3373b1dd0d75494ee1734ce138ab1904 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.argeo.ArgeoException;
+import org.argeo.StreamUtils;
 
 /**
  * Parses a CSV file interpreting the first line as a header. The
@@ -54,10 +55,16 @@ public abstract class CsvParser {
        protected abstract void processLine(Integer lineNumber,
                        List<String> header, List<String> tokens);
 
+       /**
+        * Parses the CSV file (stream is closed at the end)
+        */
        public synchronized void parse(InputStream in) {
                parse(in, null);
        }
 
+       /**
+        * Parses the CSV file (stream is closed at the end)
+        */
        public synchronized void parse(InputStream in, String encoding) {
                BufferedReader reader = null;
                Integer lineCount = 0;
@@ -122,12 +129,7 @@ public abstract class CsvParser {
                        throw new ArgeoException("Cannot parse CSV file (line: "
                                        + lineCount + ")", e);
                } finally {
-                       if (reader != null)
-                               try {
-                                       reader.close();
-                               } catch (Exception e2) {
-                                       // silent
-                               }
+                       StreamUtils.closeQuietly(reader);
                }
        }