Cosmetic improvements in CSV parser
[lgpl/argeo-commons.git] / 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);
                }
        }