Top Description Inners Fields Constructors Methods
de.siegmar.fastcsv.reader

public final Class CsvReader<T>

extends Object
implements Iterable<T>, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable
Type Parameters
<T>
the type of the CSV record.
Imports
java.io.Closeable, .EOFException, .IOException, .InputStream, .InputStreamReader, .Reader, .UncheckedIOException, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .Path, java.util.NoSuchElementException, .Objects, .Spliterator, .StringJoiner, java.util.function.Consumer, .Predicate, java.util.stream.Stream, .StreamSupport, de.siegmar.fastcsv.util.Nullable, .Preconditions

This is the main class for reading CSV data.

The CSV records are read iteratively, regardless of whether the Iterable, the Iterator, or the Stream is used. Once all records are read, the data is consumed. If you need to repeatedly read records, you should collect the records in a List or another collection.

Example use:

try (CsvReader&lt;CsvRecord&gt; csv = CsvReader.builder().ofCsvRecord(file)) { for (CsvRecord csvRecord : csv) { // ... } }
try (CsvReader&lt;CsvRecord&gt; csv = CsvReader.builder().ofCsvRecord(file)) {
    for (CsvRecord csvRecord : csv) {
        // ...
    }
}

Example for named records:

try (CsvReader&lt;NamedCsvRecord&gt; csv = CsvReader.builder().ofNamedCsvRecord(file)) { for (NamedCsvRecord csvRecord : csv) { // ... } }
try (CsvReader&lt;NamedCsvRecord&gt; csv = CsvReader.builder().ofNamedCsvRecord(file)) {
    for (NamedCsvRecord csvRecord : csv) {
        // ...
    }
}

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CsvReader.CsvReaderBuilder

This builder is used to create configured instances of CsvReader.

private class
private class

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private final CsvCallbackHandler<T>
private final CommentStrategy
private final CsvParser
private final CloseableIterator<T>
private final boolean
private int
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
CsvReader(final CsvParser csvParser, final CsvCallbackHandler<T> callbackHandler, final CommentStrategy commentStrategy, final boolean skipEmptyLines, final boolean allowExtraFields, final boolean allowMissingFields)

Method Summary

Modifier and TypeMethod and Description
public static CsvReader.CsvReaderBuilder

Returns:

a new CsvReaderBuilder instance.
builder
()

Constructs a CsvReaderBuilder to configure and build instances of this class.

private String
private void
checkFieldCountConsistency(final int fieldCount)

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private T
private T
public CloseableIterator<T>

Returns:

an iterator over elements of type CsvRecord.
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type CsvRecord.

private T
public void
skipLines(final int
the number of lines to skip.
lineCount
)

Skips the specified number of lines.

public int

Returns:

the number of lines actually skipped.
skipLines
(final Predicate<String>
the predicate to match the lines.
predicate
,
final int
the maximum number of lines to skip.
maxLines
)

Skip lines until the specified predicate matches.

public Spliterator<T>

Returns:

a spliterator over the CSV records.
spliterator
()

Overrides default java.lang.Iterable.spliterator.

Constructs a Spliterator for splitting and traversing the elements of this reader.

public Stream<T>

Returns:

a sequential Stream over the CSV records.
stream
()

Constructs a new sequential Stream with this reader as its source.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait