From: Mathieu Baudier Date: Mon, 12 Nov 2012 16:20:56 +0000 (+0000) Subject: Cosmetic improvements in CSV parser X-Git-Tag: argeo-commons-2.1.30~760 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d86cb72e79414596cb0b6a4a607404996bf08c6c;p=lgpl%2Fargeo-commons.git Cosmetic improvements in CSV parser git-svn-id: https://svn.argeo.org/commons/trunk@5776 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java b/base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java index 127d0f509..1f614b8b3 100644 --- a/base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java +++ b/base/runtime/org.argeo.util/src/main/java/org/argeo/util/CsvParser.java @@ -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 header, List 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); } }