Class AbstractCsvReader<T>

  • Type Parameters:
    T - the target class (output from each line of CSV file).
    All Implemented Interfaces:
    CsvReader<T>, AutoCloseable
    Direct Known Subclasses:
    EmptyCsvReader, StringArrayCsvReader

    public abstract class AbstractCsvReader<T>
    extends Object
    implements CsvReader<T>
    Base class for CSV data-binding. Generated parsers extend this class.

    Implementation note: The buffering is done so that reading plain (not quoted) content is speed up at the cost of reading quoted content. Essentially there is a terminator scheme, where newline is the terminator.

    Each time the buffer is filled, the underlying implementation scans backwards for a newline. The quoted parse loop must check whether the buffer must be filled upon encountering a quote.

    If the file ends without a newline, one is inserted.
    • Field Detail

      • reader

        protected final Reader reader
      • current

        protected final char[] current
      • maxDataLength

        protected final int maxDataLength
      • offset

        protected int offset
      • endOfLineIndex

        protected int endOfLineIndex
      • dataLength

        protected int dataLength
      • eof

        protected boolean eof
    • Constructor Detail

      • AbstractCsvReader

        public AbstractCsvReader​(Reader reader,
                                 char[] current,
                                 int offset,
                                 int length)
        Construct new instance. The current buffer must at least contain a single row, ending with a newline.
        Parameters:
        reader - read input
        current - current buffer
        offset - buffer offset
        length - buffer payload length
      • AbstractCsvReader

        public AbstractCsvReader​(Reader reader,
                                 int length)