java.lang.Object
de.siegmar.fastcsv.reader.CsvReader<T>
- Type Parameters:
T- the type of the CSV record.
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<T>
This is the main class for reading CSV data.
Example use:
try (CsvReader<CsvRecord> csv = CsvReader.builder().ofCsvRecord(file)) {
for (CsvRecord csvRecord : csv) {
// ...
}
}
Example for named records:
try (CsvReader<NamedCsvRecord> csv = CsvReader.builder().ofNamedCsvRecord(file)) {
for (NamedCsvRecord csvRecord : csv) {
// ...
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis builder is used to create configured instances ofCsvReader. -
Method Summary
Modifier and TypeMethodDescriptionstatic CsvReader.CsvReaderBuilderbuilder()Constructs aCsvReader.CsvReaderBuilderto configure and build instances of this class.voidclose()iterator()Returns an iterator over elements of typeCsvRecord.Returns aSpliteratorover elements of typeCsvRecord.stream()Returns a sequentialStreamwith this reader as its source.toString()
-
Method Details
-
builder
Constructs aCsvReader.CsvReaderBuilderto configure and build instances of this class.- Returns:
- a new
CsvReader.CsvReaderBuilderinstance.
-
iterator
Returns an iterator over elements of typeCsvRecord.The returned iterator is not thread-safe. Don't forget to close the returned iterator when you're done. Alternatively, use
stream().
This method is idempotent.- Specified by:
iteratorin interfaceIterable<T>- Returns:
- an iterator over the CSV records.
- Throws:
UncheckedIOException- if an I/O error occurs.CsvParseException- if any other problem occurs when parsing the CSV data.- See Also:
-
spliterator
Returns aSpliteratorover elements of typeCsvRecord.The returned spliterator is not thread-safe. Don't forget to invoke
close()when you're done. Alternatively, usestream().
This method is idempotent.- Specified by:
spliteratorin interfaceIterable<T>- Returns:
- a spliterator over the CSV records.
- Throws:
UncheckedIOException- if an I/O error occurs.CsvParseException- if any other problem occurs when parsing the CSV data.- See Also:
-
stream
Returns a sequentialStreamwith this reader as its source.The returned stream is not thread-safe. Don't forget to close the returned stream when you're done.
This method is idempotent.- Returns:
- a sequential
Streamover the CSV records. - Throws:
UncheckedIOException- if an I/O error occurs.CsvParseException- if any other problem occurs when parsing the CSV data.- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toString
-