org.supercsv.io
Class AbstractCsvReader
- java.lang.Object
-
- org.supercsv.io.AbstractCsvReader
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable, ICsvReader
- Direct Known Subclasses:
- CsvBeanReader, CsvListReader, CsvMapReader
public abstract class AbstractCsvReader extends java.lang.Object implements ICsvReader
Defines the standard behaviour of a CSV reader.
-
-
Constructor Summary
Constructors Constructor and Description AbstractCsvReader(ITokenizer tokenizer, CsvPreference preferences)Constructs a new AbstractCsvReader, using a customTokenizer(which should have already been set up with the Reader, CsvPreference, and CsvContext).AbstractCsvReader(java.io.Reader reader, CsvPreference preferences)Constructs a new AbstractCsvReader, using the defaultTokenizer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Closes the Tokenizer and its associated Reader.java.lang.Stringget(int n)Get column N of the current line (column indexes begin at 1).java.lang.String[]getHeader(boolean firstLineCheck)This method is used to get an optional header of the CSV file and move the file cursor to the first row containing data (the second row from the top).intgetLineNumber()Gets the current position in the file.intgetRowNumber()Gets the current row number (i.e.java.lang.StringgetUntokenizedRow()Returns the untokenized CSV row that was just read (which can potentially span multiple lines in the file).intlength()Returns the length (i.e.
-
-
-
Constructor Detail
-
AbstractCsvReader
public AbstractCsvReader(java.io.Reader reader, CsvPreference preferences)Constructs a new AbstractCsvReader, using the defaultTokenizer.- Parameters:
reader- the readerpreferences- the CSV preferences- Throws:
java.lang.NullPointerException- if reader or preferences are null
-
AbstractCsvReader
public AbstractCsvReader(ITokenizer tokenizer, CsvPreference preferences)
Constructs a new AbstractCsvReader, using a customTokenizer(which should have already been set up with the Reader, CsvPreference, and CsvContext). This constructor should only be used if the default Tokenizer doesn't provide the required functionality.- Parameters:
tokenizer- the tokenizerpreferences- the CSV preferences- Throws:
java.lang.NullPointerException- if tokenizer or preferences are null
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionCloses the Tokenizer and its associated Reader.- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
get
public java.lang.String get(int n)
Get column N of the current line (column indexes begin at 1).- Specified by:
getin interfaceICsvReader- Parameters:
n- the index of the column to get- Returns:
- the n'th column
-
getHeader
public java.lang.String[] getHeader(boolean firstLineCheck) throws java.io.IOExceptionThis method is used to get an optional header of the CSV file and move the file cursor to the first row containing data (the second row from the top). The header can subsequently be used as thenameMappingarray for read operations.- Specified by:
getHeaderin interfaceICsvReader- Parameters:
firstLineCheck- if true, ensures that this method is only called when reading the first line (as that's where the header is meant to be)- Returns:
- the array of header fields, or null if EOF is encountered
- Throws:
java.io.IOException- if an I/O exception occurs
-
getLineNumber
public int getLineNumber()
Gets the current position in the file. The first line of the file is line number 1.- Specified by:
getLineNumberin interfaceICsvReader
-
getUntokenizedRow
public java.lang.String getUntokenizedRow()
Returns the untokenized CSV row that was just read (which can potentially span multiple lines in the file).- Specified by:
getUntokenizedRowin interfaceICsvReader- Returns:
- the untokenized CSV row that was just read
-
getRowNumber
public int getRowNumber()
Gets the current row number (i.e. the number of CSV records - including the header - that have been read). This differs from the lineNumber, which is the number of real lines that have been read in the file. The first row is row 1 (which is typically the header row).- Specified by:
getRowNumberin interfaceICsvReader
-
length
public int length()
Returns the length (i.e. number of columns) of the current row.- Specified by:
lengthin interfaceICsvReader
-
-
DMelt 3.0 © DataMelt by jWork.ORG