Description
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:
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); } }
and:
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); } }
When I collect the results of my method, it gives me
[]
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`.