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>
TheCsvInputStreamRecordsImplis an implementation of theRecordsinterface 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 aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, boolean isStrict)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, boolean isStrict)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter)Constructs aCsvInputStreamRecordsImplwith the given parameters.CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)Constructs aCsvInputStreamRecordsImplwith the given parameters.protectedCsvInputStreamRecordsImpl(Header<T> aHeader, ColumnFactory<T> aColumnFactory, java.io.InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict)Constructs aCsvInputStreamRecordsImplwith the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetErroneousRecordCount()Gets the erroneous record count.Header<T>getHeader()Retrieves theHeaderproperty.booleanhasNext()Record<T>next()Next.voidremove()
-
-
-
Constructor Detail
-
CsvInputStreamRecordsImpl
public CsvInputStreamRecordsImpl(Header<T> aHeader, java.io.InputStream aCsvInputStream) throws java.io.IOException
Constructs aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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:
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 aCsvInputStreamRecordsImplwith 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.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:
hasNextin interfacejava.util.Iterator<T>
-
next
public Record<T> next()
Next.- Specified by:
nextin interfacejava.util.Iterator<T>- Returns:
- the record
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<T>
-
getHeader
public Header<T> getHeader()
Retrieves theHeaderproperty.- Specified by:
getHeaderin interfaceHeaderAccessor<T>- Returns:
- The
Headerbeing stored by this property.
-
getErroneousRecordCount
public long getErroneousRecordCount()
Gets the erroneous record count.- Specified by:
getErroneousRecordCountin interfaceInputStreamRecords<T>- Returns:
- the erroneous record count
-
-