Package com.github.skjolber.stcsv
Class AbstractCsvReader<T>
- java.lang.Object
-
- com.github.skjolber.stcsv.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 Summary
Fields Modifier and Type Field Description protected char[]currentprotected intdataLengthstatic intDEFAULT_RANGE_LENGTHprotected intendOfLineIndexprotected booleaneofprotected intmaxDataLengthprotected intoffsetprotected Readerreader
-
Constructor Summary
Constructors Constructor Description AbstractCsvReader(Reader reader, char[] current, int offset, int length)Construct new instance.AbstractCsvReader(Reader reader, int length)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()intfill()intfill(int keep)protected intfindEndOfLine(int currentRange)intgetEndOfLineIndex()RawReadergetReader()abstract Tnext()
-
-
-
Field Detail
-
DEFAULT_RANGE_LENGTH
public static final int DEFAULT_RANGE_LENGTH
- See Also:
- Constant Field Values
-
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 inputcurrent- current bufferoffset- buffer offsetlength- buffer payload length
-
AbstractCsvReader
public AbstractCsvReader(Reader reader, int length)
-
-
Method Detail
-
findEndOfLine
protected int findEndOfLine(int currentRange)
-
fill
public int fill(int keep) throws IOException- Throws:
IOException
-
fill
public int fill() throws IOException- Throws:
IOException
-
getEndOfLineIndex
public int getEndOfLineIndex()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-