Skip to content

Commit 5daf49a

Browse files
committed
Add API org.apache.commons.csv.CSVParser.getRecords(T).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1584936 13f79535-47bb-0310-9956-ffa450edef68
1 parent c2ed3be commit 5daf49a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.net.URL;
3030
import java.nio.charset.Charset;
3131
import java.util.ArrayList;
32+
import java.util.Collection;
3233
import java.util.Iterator;
3334
import java.util.LinkedHashMap;
3435
import 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);

0 commit comments

Comments
 (0)