diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 78d96358..83c3e796 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -29,6 +29,7 @@ import java.io.StringReader; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -309,7 +310,22 @@ public final class CSVParser implements Iterable, Closeable { * on parse error or input read-failure */ public List getRecords() throws IOException { - final List records = new ArrayList(); + return getRecords(new ArrayList()); + } + + /** + * Parses the CSV input according to the given format and adds the content to the collection of {@link CSVRecord + * CSVRecords}. + *

+ * The returned content starts at the current parse-position in the stream. + * + * @param records + * The collection to add to. + * @return a collection of {@link CSVRecord CSVRecords}, may be empty + * @throws IOException + * on parse error or input read-failure + */ + public > T getRecords(T records) throws IOException { CSVRecord rec; while ((rec = this.nextRecord()) != null) { records.add(rec);