Package org.refcodes.tabular
Class CsvInputStreamRecordsImpl<T>
- java.lang.Object
-
- org.refcodes.tabular.CsvInputStreamRecordsImpl<T>
-
- Type Parameters:
T
- The type managed by theRecords
.
- All Implemented Interfaces:
java.util.Iterator<Record<? extends T>>
,HeaderAccessor<T>
,InputStreamRecords<T>
,Records<T>
- Direct Known Subclasses:
CsvFileRecordsImpl
public class CsvInputStreamRecordsImpl<T> extends java.lang.Object implements InputStreamRecords<T>
TheCsvInputStreamRecordsImpl
is an implementation of theRecords
interface and provides functionality to parse CSV input streams.TODO: This class is still to be unit tested.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.tabular.HeaderAccessor
HeaderAccessor.HeaderBuilder<T extends HeaderAccessor.HeaderBuilder<?>>, HeaderAccessor.HeaderMutator<T>, HeaderAccessor.HeaderProperty<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, boolean isStrict)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, boolean isStrict)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.protected
CsvInputStreamRecordsImpl(Header<T> aHeader, ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)
Constructs aCsvInputStreamRecordsImpl
with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getErroneousRecordCount()
Gets the erroneous record count.Header<T>
getHeader()
Retrieves theHeader
property.boolean
hasNext()
Record<T>
next()
Next.void
remove()
-
-
-
Constructor Detail
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, boolean isStrict) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, boolean isStrict) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
CsvInputStreamRecordsImpl
protected CsvInputStreamRecordsImpl(Header<T> aHeader, ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws java.io.IOException
Constructs aCsvInputStreamRecordsImpl
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.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:
java.io.IOException
- in case there were problems working with the givenInputStream
.
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
next
public Record<T> next()
Next.- Specified by:
next
in interfacejava.util.Iterator<T>
- Returns:
- the record
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<T>
-
getHeader
public Header<T> getHeader()
Retrieves theHeader
property.- Specified by:
getHeader
in interfaceHeaderAccessor<T>
- Returns:
- The
Header
being stored by this property.
-
getErroneousRecordCount
public long getErroneousRecordCount()
Gets the erroneous record count.- Specified by:
getErroneousRecordCount
in interfaceInputStreamRecords<T>
- Returns:
- the erroneous record count
-
-