]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java
Add dep folder
[lgpl/argeo-commons.git] / base / runtime / org.argeo.util / src / main / java / org / argeo / util / CsvParser.java
index 127d0f50928f9b358c5f376a9ba8704f9d9ba697..7680b3267c7d0739be7ca34a99fefac93118f3e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -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);
                }
        }