Package org.refcodes.tabular
Class CsvFileRecordsImpl<T>
- java.lang.Object
-
- org.refcodes.tabular.CsvInputStreamRecordsImpl<T>
-
- org.refcodes.tabular.CsvFileRecordsImpl<T>
-
- Type Parameters:
T- The type managed by theRecords.
- All Implemented Interfaces:
java.util.Iterator<Record<? extends T>>,HeaderAccessor<T>,InputStreamRecords<T>,Records<T>
public class CsvFileRecordsImpl<T> extends CsvInputStreamRecordsImpl<T>
TheCsvFileRecordsImplis an implementation of theRecordsinterface and provides functionality to parse CSV files. It extends the more genericCsvInputStreamRecordsImplfor parsing CSV input streams.
-
-
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 Constructor Description CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, boolean isStrict)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, boolean isStrict)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator)Constructs aCsvFileRecordsImplwith the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict)Constructs aCsvFileRecordsImplwith the given parameters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.StringtoFileNameFromZip(java.lang.String aZipFileName)Truncates the ".zip" suffix from the filename and returns the result.protected static java.io.InputStreamtoInputStream(java.io.File aFile)Returns anInputStreamfrom the providedFile.-
Methods inherited from class org.refcodes.tabular.CsvInputStreamRecordsImpl
getErroneousRecordCount, getHeader, hasNext, next, remove
-
-
-
-
Constructor Detail
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, boolean isStrict) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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 countCsvInputStreamRecordsImpl.getErroneousRecordCount()is incremented by each erroneousRecord.- Throws:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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 countCsvInputStreamRecordsImpl.getErroneousRecordCount()is incremented by each erroneousRecord.- Throws:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, boolean isStrict) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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 countCsvInputStreamRecordsImpl.getErroneousRecordCount()is incremented by each erroneousRecord.- Throws:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
CsvFileRecordsImpl
public CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict) throws java.io.FileNotFoundException, java.io.IOException, java.util.zip.ZipException
Constructs aCsvFileRecordsImplwith 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 countCsvInputStreamRecordsImpl.getErroneousRecordCount()is incremented by each erroneousRecord.- Throws:
java.io.FileNotFoundException- the file not found exceptionjava.io.IOException- in case there were problems working with the givenFile.java.util.zip.ZipException- the zip exception
-
-
Method Detail
-
toInputStream
protected static java.io.InputStream toInputStream(java.io.File aFile) throws java.util.zip.ZipException, java.io.IOException, java.io.FileNotFoundExceptionReturns anInputStreamfrom the providedFile. In case the file points to a ZIP compressed file, then the uncompressed data is provided by theInputStream.- Parameters:
aFile- TheFilefor which to get theInputStream.- Returns:
- An
InputStream, in case of a ZIP compressedFile, an uncompressedInputStreamis returned. - Throws:
java.util.zip.ZipException- in case there were problems when accessing the ZIP compressedFile.java.io.IOException- in case there were problems working with theFile.java.io.FileNotFoundException- in case there was none suchFilefound.
-
toFileNameFromZip
protected static java.lang.String toFileNameFromZip(java.lang.String aZipFileName)
Truncates the ".zip" suffix from the filename and returns the result. For example a file with name "log-2023-07-12.txt.zip" results in "log-2023-07-12.txt".- Parameters:
aZipFileName- The file name of the ZIP file for which to get the "inner" file name.- Returns:
- The "inner" file name if the file suffix was ".zip", else null.
-
-