public class CsvReader
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
static int |
ESCAPE_MODE_BACKSLASH |
Use a backslash character before the text qualifier to represent an
occurance of the text qualifier.
|
static int |
ESCAPE_MODE_DOUBLED |
Double up the text qualifier to represent an occurance of the text
qualifier.
|
| Constructor | Description |
|---|---|
CsvReader(java.io.InputStream inputStream,
char delimiter,
java.nio.charset.Charset charset) |
Constructs a
CsvReader object using an
InputStream object as the data source. |
CsvReader(java.io.InputStream inputStream,
java.nio.charset.Charset charset) |
Constructs a
CsvReader object using an
InputStream object as the data
source. Uses a comma as the column delimiter. |
CsvReader(java.io.Reader inputStream) |
Constructs a
CsvReader object using a
Reader object as the data source. Uses a
comma as the column delimiter. |
CsvReader(java.io.Reader inputStream,
char delimiter) |
Constructs a
CsvReader object using a
Reader object as the data source. |
CsvReader(java.lang.String fileName) |
Creates a
CsvReader object using a file
as the data source. Uses a comma as the column delimiter and
ISO-8859-1 as the Charset. |
CsvReader(java.lang.String fileName,
char delimiter) |
Creates a
CsvReader object using a file
as the data source. Uses ISO-8859-1 as the
Charset. |
CsvReader(java.lang.String fileName,
char delimiter,
java.nio.charset.Charset charset) |
Creates a
CsvReader object using a file
as the data source. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Closes and releases all related resources.
|
java.lang.String |
get(int columnIndex) |
Returns the current column value for a given column index.
|
java.lang.String |
get(java.lang.String headerName) |
Returns the current column value for a given column header name.
|
boolean |
getCaptureRawRecord() |
|
int |
getColumnCount() |
Gets the count of columns found in this record.
|
char |
getComment() |
Gets the character being used as a comment signal.
|
long |
getCurrentRecord() |
Gets the index of the current record.
|
char |
getDelimiter() |
Gets the character being used as the column delimiter.
|
int |
getEscapeMode() |
Gets the current way to escape an occurance of the text qualifier inside
qualified data.
|
java.lang.String |
getHeader(int columnIndex) |
Returns the column header value for a given column index.
|
int |
getHeaderCount() |
Gets the count of headers read in by a previous call to
readHeaders(). |
java.lang.String[] |
getHeaders() |
Returns the header values as a string array.
|
int |
getIndex(java.lang.String headerName) |
Gets the corresponding column index for a given column header name.
|
java.lang.String |
getRawRecord() |
|
char |
getRecordDelimiter() |
|
boolean |
getSafetySwitch() |
Safety caution to prevent the parser from using large amounts of memory
in the case where parsing settings like file encodings don't end up
matching the actual format of a file.
|
boolean |
getSkipEmptyRecords() |
|
char |
getTextQualifier() |
Gets the character to use as a text qualifier in the data.
|
boolean |
getTrimWhitespace() |
Gets whether leading and trailing whitespace characters are being trimmed
from non-textqualified column data.
|
boolean |
getUseComments() |
Gets whether comments are being looked for while parsing or not.
|
boolean |
getUseTextQualifier() |
Whether text qualifiers will be used while parsing or not.
|
java.lang.String[] |
getValues() |
|
boolean |
isQualified(int columnIndex) |
|
static CsvReader |
parse(java.lang.String data) |
Creates a
CsvReader object using a string
of data as the source. Uses ISO-8859-1 as the
Charset. |
boolean |
readHeaders() |
Read the first record of data as column headers.
|
boolean |
readRecord() |
Reads another record.
|
void |
setCaptureRawRecord(boolean captureRawRecord) |
|
void |
setComment(char comment) |
Sets the character to use as a comment signal.
|
void |
setDelimiter(char delimiter) |
Sets the character to use as the column delimiter.
|
void |
setEscapeMode(int escapeMode) |
Sets the current way to escape an occurance of the text qualifier inside
qualified data.
|
void |
setHeaders(java.lang.String[] headers) |
|
void |
setRecordDelimiter(char recordDelimiter) |
Sets the character to use as the record delimiter.
|
void |
setSafetySwitch(boolean safetySwitch) |
Safety caution to prevent the parser from using large amounts of memory
in the case where parsing settings like file encodings don't end up
matching the actual format of a file.
|
void |
setSkipEmptyRecords(boolean skipEmptyRecords) |
|
void |
setTextQualifier(char textQualifier) |
Sets the character to use as a text qualifier in the data.
|
void |
setTrimWhitespace(boolean trimWhitespace) |
Sets whether leading and trailing whitespace characters should be trimmed
from non-textqualified column data or not.
|
void |
setUseComments(boolean useComments) |
Sets whether comments are being looked for while parsing or not.
|
void |
setUseTextQualifier(boolean useTextQualifier) |
Sets whether text qualifiers will be used while parsing or not.
|
boolean |
skipLine() |
Skips the next line of data using the standard end of line characters and
does not do any column delimited parsing.
|
boolean |
skipRecord() |
Skips the next record of data by parsing each column. Does not
increment
getCurrentRecord(). |
public static final int ESCAPE_MODE_DOUBLED
public static final int ESCAPE_MODE_BACKSLASH
public CsvReader(java.lang.String fileName,
char delimiter,
java.nio.charset.Charset charset)
throws java.io.FileNotFoundException
CsvReader object using a file
as the data source.fileName - The path to the file to use as the data source.delimiter - The character to use as the column delimiter.charset - The Charset to use while
parsing the data.java.io.FileNotFoundExceptionpublic CsvReader(java.lang.String fileName,
char delimiter)
throws java.io.FileNotFoundException
CsvReader object using a file
as the data source. Uses ISO-8859-1 as the
Charset.fileName - The path to the file to use as the data source.delimiter - The character to use as the column delimiter.java.io.FileNotFoundExceptionpublic CsvReader(java.lang.String fileName)
throws java.io.FileNotFoundException
CsvReader object using a file
as the data source. Uses a comma as the column delimiter and
ISO-8859-1 as the Charset.fileName - The path to the file to use as the data source.java.io.FileNotFoundExceptionpublic CsvReader(java.io.Reader inputStream,
char delimiter)
CsvReader object using a
Reader object as the data source.inputStream - The stream to use as the data source.delimiter - The character to use as the column delimiter.public CsvReader(java.io.Reader inputStream)
CsvReader object using a
Reader object as the data source. Uses a
comma as the column delimiter.inputStream - The stream to use as the data source.public CsvReader(java.io.InputStream inputStream,
char delimiter,
java.nio.charset.Charset charset)
CsvReader object using an
InputStream object as the data source.inputStream - The stream to use as the data source.delimiter - The character to use as the column delimiter.charset - The Charset to use while
parsing the data.public CsvReader(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
CsvReader object using an
InputStream object as the data
source. Uses a comma as the column delimiter.inputStream - The stream to use as the data source.charset - The Charset to use while
parsing the data.public boolean getCaptureRawRecord()
public void setCaptureRawRecord(boolean captureRawRecord)
public java.lang.String getRawRecord()
public boolean getTrimWhitespace()
public void setTrimWhitespace(boolean trimWhitespace)
trimWhitespace - Whether leading and trailing whitespace characters should be
trimmed from non-textqualified column data or not.public char getDelimiter()
public void setDelimiter(char delimiter)
delimiter - The character to use as the column delimiter.public char getRecordDelimiter()
public void setRecordDelimiter(char recordDelimiter)
recordDelimiter - The character to use as the record delimiter. Default is
combination of standard end of line characters for Windows,
Unix, or Mac.public char getTextQualifier()
public void setTextQualifier(char textQualifier)
textQualifier - The character to use as a text qualifier in the data.public boolean getUseTextQualifier()
public void setUseTextQualifier(boolean useTextQualifier)
useTextQualifier - Whether to use a text qualifier while parsing or not.public char getComment()
public void setComment(char comment)
comment - The character to use as a comment signal.public boolean getUseComments()
public void setUseComments(boolean useComments)
useComments - Whether comments are being looked for while parsing or not.public int getEscapeMode()
public void setEscapeMode(int escapeMode)
throws java.lang.IllegalArgumentException
escapeMode - The way to escape an occurance of the text qualifier inside
qualified data.java.lang.IllegalArgumentException - When an illegal value is specified for escapeMode.public boolean getSkipEmptyRecords()
public void setSkipEmptyRecords(boolean skipEmptyRecords)
public boolean getSafetySwitch()
public void setSafetySwitch(boolean safetySwitch)
safetySwitch - public int getColumnCount()
public long getCurrentRecord()
public int getHeaderCount()
readHeaders().readHeaders().public java.lang.String[] getHeaders()
throws java.io.IOException
java.io.IOException - Thrown if this object has already been closed.public void setHeaders(java.lang.String[] headers)
public java.lang.String[] getValues()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String get(int columnIndex)
throws java.io.IOException
columnIndex - The index of the column.java.io.IOException - Thrown if this object has already been closed.public java.lang.String get(java.lang.String headerName)
throws java.io.IOException
headerName - The header name of the column.java.io.IOException - Thrown if this object has already been closed.public static CsvReader parse(java.lang.String data)
CsvReader object using a string
of data as the source. Uses ISO-8859-1 as the
Charset.data - The String of data to use as the source.CsvReader object using the
String of data as the source.public boolean readRecord()
throws java.io.IOException
java.io.IOException - Thrown if an error occurs while reading data from the
source stream.public boolean readHeaders()
throws java.io.IOException
java.io.IOException - Thrown if an error occurs while reading data from the
source stream.public java.lang.String getHeader(int columnIndex)
throws java.io.IOException
columnIndex - The index of the header column being requested.java.io.IOException - Thrown if this object has already been closed.public boolean isQualified(int columnIndex)
throws java.io.IOException
java.io.IOExceptionpublic int getIndex(java.lang.String headerName)
throws java.io.IOException
headerName - The header name of the column.java.io.IOException - Thrown if this object has already been closed.public boolean skipRecord()
throws java.io.IOException
getCurrentRecord().java.io.IOException - Thrown if an error occurs while reading data from the
source stream.public boolean skipLine()
throws java.io.IOException
java.io.IOException - Thrown if an error occurs while reading data from the
source stream.public void close()