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>
TheCsvFileRecordsImpl
is an implementation of theRecords
interface and provides functionality to parse CSV files. It extends the more genericCsvInputStreamRecordsImpl
for 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 aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, boolean isStrict)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(ColumnFactory<T> aColumnFactory, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, boolean isStrict)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator)
Constructs aCsvFileRecordsImpl
with the given parameters.CsvFileRecordsImpl(Header<T> aHeader, java.io.File aCsvFile, char aCsvSeparator, boolean isStrict)
Constructs aCsvFileRecordsImpl
with the given parameters.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.String
toFileNameFromZip(java.lang.String aZipFileName)
Truncates the ".zip" suffix from the filename and returns the result.protected static java.io.InputStream
toInputStream(java.io.File aFile)
Returns anInputStream
from 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 aCsvFileRecordsImpl
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:
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 aCsvFileRecordsImpl
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:
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 aCsvFileRecordsImpl
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 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 aCsvFileRecordsImpl
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 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 aCsvFileRecordsImpl
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:
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 aCsvFileRecordsImpl
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:
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 aCsvFileRecordsImpl
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 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 aCsvFileRecordsImpl
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 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.FileNotFoundException
Returns anInputStream
from the providedFile
. In case the file points to a ZIP compressed file, then the uncompressed data is provided by theInputStream
.- Parameters:
aFile
- TheFile
for which to get theInputStream
.- Returns:
- An
InputStream
, in case of a ZIP compressedFile
, an uncompressedInputStream
is 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 suchFile
found.
-
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.
-
-