java.lang.Object
io.jenetics.ext.util.CsvSupport.LineReader
- Enclosing class:
CsvSupport
This class reads CSV files and splits it into lines. It takes a quote
character as a parameter, which is necessary for not splitting on quoted
line feeds.
final var csv = """
0.0,0.0000
0.1,0.0740
0.2,0.1120
0.3,0.1380
0.4,0.1760
0.5,0.2500
0.6,0.3840
0.7,0.6020
0.8,0.9280
0.9,1.3860
1.0,2.0000
""";
final var reader = new LineReader(new Quote('"'));
try (Stream<String> lines = reader.read(new StringReader(csv))) {
lines.forEach(System.out::println);
}
- Since:
- 8.1
- Version:
- 8.1
- API Note:
- This reader obeys escaped line breaks according RFC-4180.
-
Constructor Summary
ConstructorDescriptionCreate a new line reader with default quote character'"'
(CsvSupport.Quote.DEFAULT
).LineReader
(CsvSupport.Quote quote) Create a new line-reader with the givenquote
character, which is used in the CSV file which is read. -
Method Summary
-
Constructor Details
-
LineReader
Create a new line-reader with the givenquote
character, which is used in the CSV file which is read.- Parameters:
quote
- the quoting character- Throws:
NullPointerException
- if thequote
character isnull
-
LineReader
public LineReader()Create a new line reader with default quote character'"'
(CsvSupport.Quote.DEFAULT
).
-
-
Method Details
-
read
Reads all CSV lines from the givenreader
.- Parameters:
reader
- the reader from which to read the CSV content- Returns:
- the CSV lines from the file as a
Stream
- API Note:
- This method must be used within a try-with-resources statement or similar control structure to ensure that the stream's open file is closed promptly after the stream's operations have completed.
-