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.CsvEscapeModePropertyNested 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.DelimiterPropertyNested 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
ConstructorsModifierConstructorDescriptionCsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, char aCsvSeparator) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding, char aCsvSeparator, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) Constructs aCsvRecordReaderwith the given parameters.CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters.protectedCsvRecordReader(Header<T> aHeader, ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) Constructs aCsvRecordReaderwith the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()String[]org.refcodes.textual.CsvEscapeModecharlongGets the erroneous record count.Retrieves theHeaderproperty.booleanhasNext()booleanisTrim()next()nextRaw()String[]nextRow()Reads the next line from the (standard) input (stream or file) and returns an array of itsStringrepresentation.Creates aHeaderfrom the next line to be read.readHeader(Column<T>... aColumns) Creates aHeaderfrom the next line to be read.readHeader(Header<T> aHeader) Creates aHeaderfrom the next line to be read.voidremove()voidsetCommentPrefixes(String... aCommentPrefixes) voidsetCsvEscapeMode(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode) voidsetDelimiter(char aCsvDelimiter) voidsetTrim(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, waitMethods inherited from interface org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeProperty
letCsvEscapeModeMethods inherited from interface org.refcodes.textual.CsvMixin
isComment, toComment, uncommentMethods inherited from interface org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
letDelimiterMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemainingMethods inherited from interface org.refcodes.tabular.RecordReader
nextType, toHeaderMethods inherited from interface org.refcodes.mixin.TrimAccessor.TrimProperty
letTrim
-
Constructor Details
-
CsvRecordReader
public CsvRecordReader(Header<T> aHeader, File aCsvFile) throws FileNotFoundException, IOException, ZipException Constructs aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvFile- The CSVFilewhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich 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 aCsvRecordReaderwith the given parameters. InternallyColumninstances are generated according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type.- Parameters:
aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aCsvRecordReaderwith the given parameters. This constructor supports aColumnFactoryfor creatingColumninstance according to the keys found in the CSV top line. TheColumninstances are required to convert the CSV line values from the storage format to the actual required type. If aHeaderis provided, then theHeaderis used for generating theColumninstances instead of the top line of the CSV file.- Parameters:
aHeader- TheHeaderto use when parsing the lines retrieved from theInputStream.aColumnFactory- AColumnFactoryto be used to generateColumninstances from the top line of the CSF file, required for parsing the CSV lines and converting them toRecordinstances.aCsvInputStream- The CSVInputStreamwhich to parse.aEncoding- TheCharsetfor 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 aHeaderfrom 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, placeholderColumninstances are inserted if needed, created by the provided (default)ColumnFactory.- Specified by:
readHeaderin interfaceRecordReader<T>- Returns:
- Returns the
Headerbeing read. - Throws:
IOException- thrown in case reading from IO failed.
-
readHeader
Creates aHeaderfrom the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holderColumninstances are inserted if needed, created by the provided (default)ColumnFactory.- Specified by:
readHeaderin interfaceRecordReader<T>- Parameters:
aColumns- TheColumninstances for creating the actualHeader.- Returns:
- Returns the
Headerbeing read. - Throws:
IOException- Signals that an I/O exception has occurred.
-
readHeader
Creates aHeaderfrom the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holderColumninstances are inserted if needed, created by the provided (default)ColumnFactory.- Specified by:
readHeaderin interfaceRecordReader<T>- Parameters:
aHeader- TheHeaderfor creating the actualHeader.- Returns:
- Returns the
Headerbeing 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:
skipHeaderin 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 itsStringrepresentation. -
nextRaw
- Specified by:
nextRawin interfaceorg.refcodes.io.RowReader<T>
-
next
-
remove
public void remove() -
getHeader
Retrieves theHeaderproperty.- Specified by:
getHeaderin interfaceHeaderAccessor<T>- Returns:
- The
Headerbeing stored by this property.
-
setCommentPrefixes
- Specified by:
setCommentPrefixesin interfaceorg.refcodes.textual.CsvMixin
-
getCommentPrefixes
- Specified by:
getCommentPrefixesin interfaceorg.refcodes.textual.CsvMixin
-
clearCommentPrefixes
public void clearCommentPrefixes()- Specified by:
clearCommentPrefixesin interfaceorg.refcodes.textual.CsvMixin
-
withCommentPrefixes
- Specified by:
withCommentPrefixesin interfaceorg.refcodes.textual.CsvMixin
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
getCsvEscapeMode
public org.refcodes.textual.CsvEscapeMode getCsvEscapeMode()- Specified by:
getCsvEscapeModein interfaceorg.refcodes.textual.CsvEscapeModeAccessor
-
isTrim
public boolean isTrim()- Specified by:
isTrimin interfaceorg.refcodes.mixin.TrimAccessor
-
getDelimiter
public char getDelimiter()- Specified by:
getDelimiterin interfaceorg.refcodes.mixin.DelimiterAccessor
-
setTrim
public void setTrim(boolean isTrim) - Specified by:
setTrimin interfaceorg.refcodes.mixin.TrimAccessor.TrimMutator
-
setDelimiter
public void setDelimiter(char aCsvDelimiter) - Specified by:
setDelimiterin interfaceorg.refcodes.mixin.DelimiterAccessor.DelimiterMutator
-
withTrim
- Specified by:
withTrimin interfaceorg.refcodes.mixin.TrimAccessor.TrimBuilder<T>
-
withCsvEscapeMode
- Specified by:
withCsvEscapeModein interfaceorg.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<T>
-
withDelimiter
- Specified by:
withDelimiterin interfaceorg.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<T>
-
setCsvEscapeMode
public void setCsvEscapeMode(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode) - Specified by:
setCsvEscapeModein interfaceorg.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeMutator
-
getErroneousRecordCount
public long getErroneousRecordCount()Gets the erroneous record count.- Specified by:
getErroneousRecordCountin interfaceRecordReader<T>- Returns:
- the erroneous record count
-