File tree Expand file tree Collapse file tree
src/main/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929import java .net .URL ;
3030import java .nio .charset .Charset ;
3131import java .util .ArrayList ;
32+ import java .util .Collection ;
3233import java .util .Iterator ;
3334import java .util .LinkedHashMap ;
3435import java .util .List ;
@@ -309,7 +310,22 @@ public long getRecordNumber() {
309310 * on parse error or input read-failure
310311 */
311312 public List <CSVRecord > getRecords () throws IOException {
312- final List <CSVRecord > records = new ArrayList <CSVRecord >();
313+ return getRecords (new ArrayList <CSVRecord >());
314+ }
315+
316+ /**
317+ * Parses the CSV input according to the given format and adds the content to the collection of {@link CSVRecord
318+ * CSVRecords}.
319+ * <p/>
320+ * The returned content starts at the current parse-position in the stream.
321+ *
322+ * @param records
323+ * The collection to add to.
324+ * @return a collection of {@link CSVRecord CSVRecords}, may be empty
325+ * @throws IOException
326+ * on parse error or input read-failure
327+ */
328+ public <T extends Collection <CSVRecord >> T getRecords (T records ) throws IOException {
313329 CSVRecord rec ;
314330 while ((rec = this .nextRecord ()) != null ) {
315331 records .add (rec );
You can’t perform that action at this time.
0 commit comments