X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=base%2Fruntime%2Forg.argeo.util%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Futil%2FCsvParser.java;h=7680b3267c7d0739be7ca34a99fefac93118f3e5;hb=3a3d316af102ba410d1d9e6de349d0c8f7ac044f;hp=127d0f50928f9b358c5f376a9ba8704f9d9ba697;hpb=5e65b1c0f228622aebfe03b23706cb6a02a5a96a;p=lgpl%2Fargeo-commons.git 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..7680b3267 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 @@ -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 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); } }