java.lang.Object
org.refcodes.tabular.CsvRecordReader<T>
- Type Parameters:
T
- The type managed by theRecords
.
- All Implemented Interfaces:
AutoCloseable
,Iterable<Record<T>>
,Iterator<Record<T>>
,org.refcodes.io.RowReader<String[]>
,org.refcodes.mixin.DelimiterAccessor
,org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<org.refcodes.textual.CsvMixin>
,org.refcodes.mixin.DelimiterAccessor.DelimiterMutator
,org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
,org.refcodes.mixin.TrimAccessor
,org.refcodes.mixin.TrimAccessor.TrimBuilder<org.refcodes.textual.CsvMixin>
,org.refcodes.mixin.TrimAccessor.TrimMutator
,org.refcodes.mixin.TrimAccessor.TrimProperty
,HeaderAccessor<T>
,RecordReader<T>
,Records<T>
,org.refcodes.textual.CsvEscapeModeAccessor
,org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<org.refcodes.textual.CsvMixin>
,org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeMutator
,org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeProperty
,org.refcodes.textual.CsvMixin
- Direct Known Subclasses:
CsvStringRecordReader
public class CsvRecordReader<T>
extends Object
implements org.refcodes.textual.CsvMixin, RecordReader<T>
The
CsvRecordReader
is an implementation of the RecordReader
interface and provides functionality to parse CSV input streams:
Column<Float> floatColumn = floatColumn( "volume" );
Column<String> stringColumn = floatColumn( "name" );
Column<Integer> intColumn = floatColumn( "length" );
Column<Date> dateColumn = floatColumn( "time" );
try (CsvRecordReader<?> theCsvReader = new CsvRecordReader<>( headerOf( stringColumn, intColumn, dateColumn, floatColumn ), theSourceFile, theSourceDelimiter )) {
theCsvReader.readHeader(); // Level the CsvRecordReader's header with the actual file's header
Record<?> eRecord;
while ( theCsvReader.hasNext() ) {
record = theCsvReader.next();
float volume = floatColumn.get( record );
String name = stringColumn.get( record );
Date time = dateColumn.get( record );
int length = intColumn.get( record );
}
}
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.textual.CsvEscapeModeAccessor
org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<B extends org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<?>>, org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeMutator, org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeProperty
Nested classes/interfaces inherited from interface org.refcodes.mixin.DelimiterAccessor
org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B extends org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B>>, org.refcodes.mixin.DelimiterAccessor.DelimiterMutator, org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
Nested classes/interfaces inherited from interface org.refcodes.tabular.HeaderAccessor
HeaderAccessor.HeaderBuilder<T extends HeaderAccessor.HeaderBuilder<?>>, HeaderAccessor.HeaderMutator<T>, HeaderAccessor.HeaderProperty<T>
Nested classes/interfaces inherited from interface org.refcodes.mixin.TrimAccessor
org.refcodes.mixin.TrimAccessor.TrimBuilder<B extends org.refcodes.mixin.TrimAccessor.TrimBuilder<B>>, org.refcodes.mixin.TrimAccessor.TrimMutator, org.refcodes.mixin.TrimAccessor.TrimProperty
-
Constructor Summary
ModifierConstructorDescriptionCsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, char aCsvSeparator) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, Charset aEncoding) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) Constructs aCsvRecordReader
with the given parameters.CsvRecordReader
(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReader
with the given parameters.protected
CsvRecordReader
(Header<T> aHeader, ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReader
with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
close()
String[]
org.refcodes.textual.CsvEscapeMode
char
long
Gets the erroneous record count.Retrieves theHeader
property.boolean
hasNext()
boolean
isTrim()
next()
nextRaw()
String[]
nextRow()
Reads the next line from the (standard) input (stream or file) and returns an array of itsString
representation.Creates aHeader
from the next line to be read.readHeader
(Column<T>... aColumns) Creates aHeader
from the next line to be read.readHeader
(Header<T> aHeader) Creates aHeader
from the next line to be read.void
remove()
void
setCommentPrefixes
(String... aCommentPrefixes) void
setCsvEscapeMode
(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode) void
setDelimiter
(char aCsvDelimiter) void
setTrim
(boolean isTrim) Skips the next line to be read.withCommentPrefixes
(String... aCommentPrefixes) withCsvEscapeMode
(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode) withDelimiter
(char aCsvDelimiter) withTrim
(boolean isTrim) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeProperty
letCsvEscapeMode
Methods inherited from interface org.refcodes.textual.CsvMixin
isComment, toComment, uncomment
Methods inherited from interface org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
letDelimiter
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface java.util.Iterator
forEachRemaining
Methods inherited from interface org.refcodes.tabular.RecordReader
nextType, toHeader
Methods inherited from interface org.refcodes.mixin.TrimAccessor.TrimProperty
letTrim
-
Constructor Details
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, char aCsvSeparator) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aCsvSeparator
- The delimiter being expected for the CSV input stream.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, char aCsvSeparator, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aCsvSeparator
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aCsvSeparator
- The delimiter being expected for the CSV input stream.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aCsvSeparator
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aCsvDelimiter
- The delimiter being expected for the CSV input stream.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aCsvDelimiter
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aCsvDelimiter
- The delimiter being expected for the CSV input stream.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aCsvDelimiter
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvSeparator
- The delimiter being expected for the CSV input stream.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvSeparator
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvSeparator
- The delimiter being expected for the CSV input stream.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvFile
- The CSVFile
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvSeparator
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
FileNotFoundException
- the file not found exceptionIOException
- in case there were problems working with the givenFile
.ZipException
- thrown in case processing a ZIP compressed file encountered problems.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- the encodingaCsvDelimiter
- The delimiter being expected for the CSV input stream.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. InternallyColumn
instances are generated according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvDelimiter
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvDelimiter
- The delimiter being expected for the CSV input stream.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvDelimiter
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
CsvRecordReader
protected CsvRecordReader(Header<T> aHeader, ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException Constructs aCsvRecordReader
with the given parameters. This constructor supports aColumnFactory
for creatingColumn
instance according to the keys found in the CSV top line. TheColumn
instances are required to convert the CSV line values from the storage format to the actual required type. If aHeader
is provided, then theHeader
is used for generating theColumn
instances instead of the top line of the CSV file.- Parameters:
aHeader
- TheHeader
to use when parsing the lines retrieved from theInputStream
.aColumnFactory
- AColumnFactory
to be used to generateColumn
instances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecord
instances.aCsvInputStream
- The CSVInputStream
which to parse.aEncoding
- TheCharset
for the character encoding to use.aCsvDelimiter
- The delimiter being expected for the CSV input stream.isStrict
- When true, then parsing will abort with an exception in case of parsing problems, else parsing is gracefully continued and erroneous records are skipped. The error countgetErroneousRecordCount()
is incremented by each erroneousRecord
.- Throws:
IOException
- in case there were problems working with the givenInputStream
.
-
-
Method Details
-
readHeader
Creates aHeader
from the next line to be read. In case a header has already been provided (in the constructor), then the according header is matched against the next line being read and ordered accordingly, placeholderColumn
instances are inserted if needed, created by the provided (default)ColumnFactory
.- Specified by:
readHeader
in interfaceRecordReader<T>
- Returns:
- Returns the
Header
being read. - Throws:
IOException
- thrown in case reading from IO failed.
-
readHeader
Creates aHeader
from the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holderColumn
instances are inserted if needed, created by the provided (default)ColumnFactory
.- Specified by:
readHeader
in interfaceRecordReader<T>
- Parameters:
aColumns
- TheColumn
instances for creating the actualHeader
.- Returns:
- Returns the
Header
being read. - Throws:
IOException
- Signals that an I/O exception has occurred.
-
readHeader
Creates aHeader
from the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holderColumn
instances are inserted if needed, created by the provided (default)ColumnFactory
.- Specified by:
readHeader
in interfaceRecordReader<T>
- Parameters:
aHeader
- TheHeader
for creating the actualHeader
.- Returns:
- Returns the
Header
being read. - Throws:
IOException
- Signals that an I/O exception has occurred.
-
skipHeader
Skips the next line to be read. This line will not be processed by theIterator.next()
method. This methods is useful when skipping the first line (header).- Specified by:
skipHeader
in interfaceRecordReader<T>
- Returns:
- The line being skipped.
- Throws:
IOException
- thrown in case if IO problems.
-
hasNext
public boolean hasNext() -
nextRow
Reads the next line from the (standard) input (stream or file) and returns an array of itsString
representation. -
nextRaw
- Specified by:
nextRaw
in interfaceorg.refcodes.io.RowReader<T>
-
next
-
remove
public void remove() -
getHeader
Retrieves theHeader
property.- Specified by:
getHeader
in interfaceHeaderAccessor<T>
- Returns:
- The
Header
being stored by this property.
-
setCommentPrefixes
- Specified by:
setCommentPrefixes
in interfaceorg.refcodes.textual.CsvMixin
-
getCommentPrefixes
- Specified by:
getCommentPrefixes
in interfaceorg.refcodes.textual.CsvMixin
-
clearCommentPrefixes
public void clearCommentPrefixes()- Specified by:
clearCommentPrefixes
in interfaceorg.refcodes.textual.CsvMixin
-
withCommentPrefixes
- Specified by:
withCommentPrefixes
in interfaceorg.refcodes.textual.CsvMixin
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
getCsvEscapeMode
public org.refcodes.textual.CsvEscapeMode getCsvEscapeMode()- Specified by:
getCsvEscapeMode
in interfaceorg.refcodes.textual.CsvEscapeModeAccessor
-
isTrim
public boolean isTrim()- Specified by:
isTrim
in interfaceorg.refcodes.mixin.TrimAccessor
-
getDelimiter
public char getDelimiter()- Specified by:
getDelimiter
in interfaceorg.refcodes.mixin.DelimiterAccessor
-
setTrim
public void setTrim(boolean isTrim) - Specified by:
setTrim
in interfaceorg.refcodes.mixin.TrimAccessor.TrimMutator
-
setDelimiter
public void setDelimiter(char aCsvDelimiter) - Specified by:
setDelimiter
in interfaceorg.refcodes.mixin.DelimiterAccessor.DelimiterMutator
-
withTrim
- Specified by:
withTrim
in interfaceorg.refcodes.mixin.TrimAccessor.TrimBuilder<T>
-
withCsvEscapeMode
- Specified by:
withCsvEscapeMode
in interfaceorg.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<T>
-
withDelimiter
- Specified by:
withDelimiter
in interfaceorg.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<T>
-
setCsvEscapeMode
public void setCsvEscapeMode(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode) - Specified by:
setCsvEscapeMode
in interfaceorg.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeMutator
-
getErroneousRecordCount
public long getErroneousRecordCount()Gets the erroneous record count.- Specified by:
getErroneousRecordCount
in interfaceRecordReader<T>
- Returns:
- the erroneous record count
-