|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.io.CSVReader
public final class CSVReader
CSVReader parses files in CSV (comma separated values) format. Subclassers should implement the consumeLineOfTokens method.
Field Summary | |
---|---|
static int |
AllLines
|
static int |
ErrorIllegalCharacterOrByteSequence
|
static int |
ErrorMissingComma
|
static int |
ErrorUnbalancedQuotes
|
Constructor Summary | |
---|---|
CSVReader(CSVConsumer csvConsumer)
Create a new CSVReader using a specific CSVConsumer to handle the rows. |
|
CSVReader(CSVConsumer csvConsumer,
CSVErrorHandler csvErrorHandler)
Create a new CSVReader using a specific CSVConsumer to handle the rows and a specified CSVErrorHandler to handle the errors. |
Method Summary | |
---|---|
java.lang.String |
getEncoding()
Return the encoding used for the last read operation. |
boolean |
isEncodingExplicitlySet()
Returns true if the file had the encoding as the first line in the file, e.g. |
static void |
main(java.lang.String[] args)
Reads a CSV file and outputs the results. |
void |
read(java.io.File file,
java.lang.String encoding)
Reads the specified file, using the character encoding for the default locale. |
void |
read(java.io.Reader reader,
java.lang.String location)
The primitive read entry point. |
void |
read(java.net.URL url,
java.lang.String defaultEncoding)
Reads the specified URL, using the character encoding for the default locale. |
static java.util.List |
readAllLines(java.io.File file,
java.lang.String encoding)
Reads all the lines into the memory specified in the input file and returns a list of list each of which contain one line of input. |
static java.util.List |
readAllLines(java.io.File file,
java.lang.String encoding,
boolean ignoreComments)
Reads all the lines into the memory specified in the input file and returns a list of list each of which contain one line of input. |
static java.util.List |
readAllLines(java.io.File file,
java.lang.String encoding,
boolean ignoreComments,
boolean emptyValueAsNull)
Reads all the lines into the memory specified in the input file and returns a list of list each of which contain one line of input. |
static java.util.List |
readAllLines(java.io.File file,
java.lang.String encoding,
boolean ignoreComments,
java.lang.String commentMarker,
boolean emptyValueAsNull)
Reads all the lines into the memory specified in the input file and returns a list of list each of which contain one line of input. |
void |
readForSpecifiedEncoding(java.io.File file)
Will read from the specified stream in the encoding specified on the first line of the stream. |
void |
readForSpecifiedEncoding(java.io.File file,
java.lang.String altEncoding)
Will read from the specified stream in the encoding specified on the first line of the stream. |
void |
readForSpecifiedEncoding(java.io.InputStream inputStream,
java.lang.String location)
Will read from the specified stream in the encoding specified on the first line of the stream. |
void |
readForSpecifiedEncoding(java.io.InputStream inputStream,
java.lang.String location,
java.lang.String altEncoding)
Will read from the specified stream in the encoding specified on the first line of the stream. |
void |
readForSpecifiedEncoding(java.net.URL url)
Will read from the specified stream in the encoding specified on the first line of the stream. |
static java.util.List |
readNLines(java.io.File file,
java.lang.String encoding,
boolean ignoreComments,
java.lang.String commentMarker,
boolean emptyValueAsNull,
int nLines)
|
void |
setNumberOfLines(int n)
Sets the number of lines consider while reading. |
void |
setReturnEmptyValueAsNull(boolean value)
Alters the behavior of the CSV Reader when parsing empty value (i.e an unquoted empty or blank string). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ErrorMissingComma
public static final int ErrorUnbalancedQuotes
public static final int ErrorIllegalCharacterOrByteSequence
public static final int AllLines
Constructor Detail |
---|
public CSVReader(CSVConsumer csvConsumer)
csvConsumer
- CSVConsumer for handling rowspublic CSVReader(CSVConsumer csvConsumer, CSVErrorHandler csvErrorHandler)
csvConsumer
- CSVConsumer for handling rowscsvErrorHandler
- CSVErrorHandler for handling CSV format errors;
if null, CSVDefaultErrorHandler will be usedMethod Detail |
---|
public java.lang.String getEncoding()
public boolean isEncodingExplicitlySet()
public void setNumberOfLines(int n)
n
- number of linespublic void setReturnEmptyValueAsNull(boolean value)
true
empty values are returned as null
while when set to false
they are returned as empty String.
The default behavior is to return empty Strings,
value
- the new value for the toggling attributepublic void read(java.net.URL url, java.lang.String defaultEncoding) throws java.io.IOException
url
- the URL to read the data fromdefaultEncoding
- the encoding to use to read the data if
none can be determined from the URLConnection
java.io.IOException
- any IOException reading from the URLpublic void read(java.io.File file, java.lang.String encoding) throws java.io.IOException
file
- a path to the file to readencoding
- the encoding to use to read the data
java.io.IOException
- any IOException reading from the file
could not be read.public void readForSpecifiedEncoding(java.net.URL url) throws java.io.IOException
url
- the URL to read the data from
java.io.IOException
- any IOException reading from the URLpublic final void readForSpecifiedEncoding(java.io.File file) throws java.io.IOException
file
- the path to the file to read
java.io.IOException
- if an IOException occurs while reading
the fileread(Reader, String)
public final void readForSpecifiedEncoding(java.io.File file, java.lang.String altEncoding) throws java.io.IOException
file
- the path to the file to readaltEncoding
- alternate encoding to be used if not specified
java.io.IOException
- if an IOException occurs while reading
the fileread(Reader, String)
public final void readForSpecifiedEncoding(java.io.InputStream inputStream, java.lang.String location) throws java.io.IOException
inputStream
- the InputStream to read the data fromlocation
- the path to the data source for debugging messages
java.io.IOException
- if an IOException occurs while reading
the fileread(Reader, String)
public final void readForSpecifiedEncoding(java.io.InputStream inputStream, java.lang.String location, java.lang.String altEncoding) throws java.io.IOException
inputStream
- the InputStream to read the data fromlocation
- the path to the data source for debugging messagesaltEncoding
- alternate encoding to be used if not specified
java.io.IOException
- if an IOException occurs while reading
the fileread(Reader, String)
public final void read(java.io.Reader reader, java.lang.String location) throws java.io.IOException
reader
- the data source as passed in by one of the
higher level read methodslocation
- the path for debugging messages
java.io.IOException
- if an IOException occurs while reading
from readerCSVConsumer.consumeLineOfTokens(java.lang.String, int, java.util.List)
public static java.util.List readAllLines(java.io.File file, java.lang.String encoding) throws java.io.IOException
file
- the data source as passed in by one of the
higher level read methodsencoding
- the encoding to use to read the data
java.io.IOException
public static java.util.List readAllLines(java.io.File file, java.lang.String encoding, boolean ignoreComments) throws java.io.IOException
file
- the data source as passed in by one of the
higher level read methodsencoding
- the encoding to use to read the dataignoreComments
- if true it ignores all lines starting with '#'
java.io.IOException
public static java.util.List readAllLines(java.io.File file, java.lang.String encoding, boolean ignoreComments, boolean emptyValueAsNull) throws java.io.IOException
file
- the data source as passed in by one of the
higher level read methodsencoding
- the encoding to use to read the dataignoreComments
- if true it ignores all lines starting with '#'emptyValueAsNull
- see setReturnEmptyValueAsNull(boolean)
java.io.IOException
public static java.util.List readAllLines(java.io.File file, java.lang.String encoding, boolean ignoreComments, java.lang.String commentMarker, boolean emptyValueAsNull) throws java.io.IOException
file
- the data source as passed in by one of the
higher level read methodsencoding
- the encoding to use to read the dataignoreComments
- if true it ignores all lines starting with
the commentMarker StringcommentMarker
- String that marks the begin of a comment. It
has to be at the beginning of a line. If null is specified
and ignoreComments is true '#' is used as comment markeremptyValueAsNull
- see setReturnEmptyValueAsNull(boolean)
java.io.IOException
public static java.util.List readNLines(java.io.File file, java.lang.String encoding, boolean ignoreComments, java.lang.String commentMarker, boolean emptyValueAsNull, int nLines) throws java.io.IOException
nLines
- number of lines to read
java.io.IOException
readAllLines(File, String, boolean, String, boolean)
public static void main(java.lang.String[] args) throws java.io.IOException
args
- command-line arguments; arg[0] is the CSV filename, arg[1]
is the encoding type
java.io.IOException
- I/O error occurred while reading the file
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |