Class CsvRecordReader<T>

java.lang.Object
org.refcodes.tabular.CsvRecordReader<T>
Type Parameters:
T - The type managed by the Records.
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 ); } }
  • Constructor Details

    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, File aCsvFile) throws FileNotFoundException, IOException, ZipException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      aCsvSeparator - The delimiter being expected for the CSV input stream.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      ZipException - thrown in case processing a ZIP compressed file encountered problems.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, File aCsvFile) throws FileNotFoundException, IOException, ZipException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      aCsvSeparator - The delimiter being expected for the CSV input stream.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      ZipException - thrown in case processing a ZIP compressed file encountered problems.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      aCsvDelimiter - The delimiter being expected for the CSV input stream.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aCsvDelimiter - The delimiter being expected for the CSV input stream.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, char aCsvDelimiter, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, File aCsvFile, Charset aEncoding) throws FileNotFoundException, IOException, ZipException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for the character encoding to use.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for the character encoding to use.
      aCsvSeparator - The delimiter being expected for the CSV input stream.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for the character encoding to use.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for the character encoding to use.
      aCsvSeparator - The delimiter being expected for the CSV input stream.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      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 a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvFile - The CSV File which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      FileNotFoundException - the file not found exception
      IOException - in case there were problems working with the given File.
      ZipException - thrown in case processing a ZIP compressed file encountered problems.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for the character encoding to use.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - the encoding
      aCsvDelimiter - The delimiter being expected for the CSV input stream.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(Header<T> aHeader, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. Internally Column instances are generated according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for the character encoding to use.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 given InputStream.
    • CsvRecordReader

      public CsvRecordReader(ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type.
      Parameters:
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
    • CsvRecordReader

      protected CsvRecordReader(Header<T> aHeader, ColumnFactory<T> aColumnFactory, InputStream aCsvInputStream, Charset aEncoding, char aCsvDelimiter, boolean isStrict) throws IOException
      Constructs a CsvRecordReader with the given parameters. This constructor supports a ColumnFactory for creating Column instance according to the keys found in the CSV top line. The Column instances are required to convert the CSV line values from the storage format to the actual required type. If a Header is provided, then the Header is used for generating the Column instances instead of the top line of the CSV file.
      Parameters:
      aHeader - The Header to use when parsing the lines retrieved from the InputStream.
      aColumnFactory - A ColumnFactory to be used to generate Column instances from the top line of the CSF file, required for parsing the CSV lines and converting them to Record instances.
      aCsvInputStream - The CSV InputStream which to parse.
      aEncoding - The Charset for 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 count getErroneousRecordCount() is incremented by each erroneous Record.
      Throws:
      IOException - in case there were problems working with the given InputStream.
  • Method Details

    • readHeader

      public Header<T> readHeader() throws IOException
      Creates a Header from 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, placeholder Column instances are inserted if needed, created by the provided (default) ColumnFactory.
      Specified by:
      readHeader in interface RecordReader<T>
      Returns:
      Returns the Header being read.
      Throws:
      IOException - thrown in case reading from IO failed.
    • readHeader

      public Header<T> readHeader(Column<T>... aColumns) throws IOException
      Creates a Header from the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holder Column instances are inserted if needed, created by the provided (default) ColumnFactory.
      Specified by:
      readHeader in interface RecordReader<T>
      Parameters:
      aColumns - The Column instances for creating the actual Header.
      Returns:
      Returns the Header being read.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • readHeader

      public Header<T> readHeader(Header<T> aHeader) throws IOException
      Creates a Header from the next line to be read. The provided header is matched against the next line being read and ordered accordingly, place holder Column instances are inserted if needed, created by the provided (default) ColumnFactory.
      Specified by:
      readHeader in interface RecordReader<T>
      Parameters:
      aHeader - The Header for creating the actual Header.
      Returns:
      Returns the Header being read.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • skipHeader

      public String skipHeader() throws IOException
      Skips the next line to be read. This line will not be processed by the Iterator.next() method. This methods is useful when skipping the first line (header).
      Specified by:
      skipHeader in interface RecordReader<T>
      Returns:
      The line being skipped.
      Throws:
      IOException - thrown in case if IO problems.
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
      Specified by:
      hasNext in interface org.refcodes.io.RowReader<T>
    • nextRow

      public String[] nextRow()
      Reads the next line from the (standard) input (stream or file) and returns an array of its String representation.
      Specified by:
      nextRow in interface RecordReader<T>
      Specified by:
      nextRow in interface org.refcodes.io.RowReader<T>
      Returns:
      The String array representation of the next Record instance read.
    • nextRaw

      public String nextRaw()
      Specified by:
      nextRaw in interface org.refcodes.io.RowReader<T>
    • next

      public Record<T> next()
      Specified by:
      next in interface Iterator<T>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • getHeader

      public Header<T> getHeader()
      Retrieves the Header property.
      Specified by:
      getHeader in interface HeaderAccessor<T>
      Returns:
      The Header being stored by this property.
    • setCommentPrefixes

      public void setCommentPrefixes(String... aCommentPrefixes)
      Specified by:
      setCommentPrefixes in interface org.refcodes.textual.CsvMixin
    • getCommentPrefixes

      public String[] getCommentPrefixes()
      Specified by:
      getCommentPrefixes in interface org.refcodes.textual.CsvMixin
    • clearCommentPrefixes

      public void clearCommentPrefixes()
      Specified by:
      clearCommentPrefixes in interface org.refcodes.textual.CsvMixin
    • withCommentPrefixes

      public CsvRecordReader<T> withCommentPrefixes(String... aCommentPrefixes)
      Specified by:
      withCommentPrefixes in interface org.refcodes.textual.CsvMixin
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException
    • getCsvEscapeMode

      public org.refcodes.textual.CsvEscapeMode getCsvEscapeMode()
      Specified by:
      getCsvEscapeMode in interface org.refcodes.textual.CsvEscapeModeAccessor
    • isTrim

      public boolean isTrim()
      Specified by:
      isTrim in interface org.refcodes.mixin.TrimAccessor
    • getDelimiter

      public char getDelimiter()
      Specified by:
      getDelimiter in interface org.refcodes.mixin.DelimiterAccessor
    • setTrim

      public void setTrim(boolean isTrim)
      Specified by:
      setTrim in interface org.refcodes.mixin.TrimAccessor.TrimMutator
    • setDelimiter

      public void setDelimiter(char aCsvDelimiter)
      Specified by:
      setDelimiter in interface org.refcodes.mixin.DelimiterAccessor.DelimiterMutator
    • withTrim

      public CsvRecordReader<T> withTrim(boolean isTrim)
      Specified by:
      withTrim in interface org.refcodes.mixin.TrimAccessor.TrimBuilder<T>
    • withCsvEscapeMode

      public CsvRecordReader<T> withCsvEscapeMode(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode)
      Specified by:
      withCsvEscapeMode in interface org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeBuilder<T>
    • withDelimiter

      public CsvRecordReader<T> withDelimiter(char aCsvDelimiter)
      Specified by:
      withDelimiter in interface org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<T>
    • setCsvEscapeMode

      public void setCsvEscapeMode(org.refcodes.textual.CsvEscapeMode aCsvEscapeMode)
      Specified by:
      setCsvEscapeMode in interface org.refcodes.textual.CsvEscapeModeAccessor.CsvEscapeModeMutator
    • getErroneousRecordCount

      public long getErroneousRecordCount()
      Gets the erroneous record count.
      Specified by:
      getErroneousRecordCount in interface RecordReader<T>
      Returns:
      the erroneous record count