[
https://issues.apache.org/jira/browse/CSV-274?focusedWorklogId=814696&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-814696
]
ASF GitHub Bot logged work on CSV-274:
--------------------------------------
Author: ASF GitHub Bot
Created on: 07/Oct/22 14:49
Start Date: 07/Oct/22 14:49
Worklog Time Spent: 10m
Work Description: garydgregory merged PR #270:
URL: https://github.com/apache/commons-csv/pull/270
Issue Time Tracking
-------------------
Worklog Id: (was: 814696)
Time Spent: 1h (was: 50m)
> CSVParser.iterator() does not iterate over result set as expected.
> ------------------------------------------------------------------
>
> Key: CSV-274
> URL: https://issues.apache.org/jira/browse/CSV-274
> Project: Commons CSV
> Issue Type: Bug
> Components: Parser
> Affects Versions: 1.8
> Reporter: David Guiney
> Priority: Major
> Time Spent: 1h
> Remaining Estimate: 0h
>
> To return a stream of `CSVRecords` in a Spliterators, I need to call
> `CSVParser.getRecords().iterator()`. I worry that the `getRecords()` will
> load the records from the parser into memory, before creating the iterator
> which can be a problem with large CSV files.
> My code:
> {code:java}
> public Stream<CSVRecord> convertFileToMaps(Path path) throws IOException {
> try (CSVParser parser = CSVParser.parse(path,
> Charset.defaultCharset(), CSVFormat.RFC4180
> .withFirstRecordAsHeader())) {
> return
> StreamSupport.stream(Spliterators.spliteratorUnknownSize(parser.iterator(),
> 0), false);
> }
> }
> {code}
> and:
> {code:java}
> public Stream<CSVRecord> convertFileToMaps(Path path) throws IOException {
> try (CSVParser parser = CSVParser.parse(path,
> Charset.defaultCharset(), CSVFormat.RFC4180
> .withFirstRecordAsHeader())) {
> return StreamSupport.stream(parser.spliterator(), false);
> }
> }
> {code}
> When I collect the results of my method, it gives me
> {code:java}
> []
> {code}
>
> If I replace `parser.iterator()` with `parser.getRecords().iterator()` then I
> get the desired results. Is the iterator not meant to be an iterator of the
> list of `CSVRecord`.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)