|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jidesoft.csv.CsvReader
public class CsvReader
A class for reading comma-separated values files and streams. Actually the inputs do not have to be comma-separated - you can specify the character that is used as a separator.
Values containing commas can be provided by putting the value in double quotes. For example, p,"a,b,c",q is a sequence of three values, not five.
Apparently it is a contentious issue whether spaces around the values (and next to a separator) are trimmed. It appears
to be common practice and yet contrary to RFC 4180, so I have provided a property trimmingValues
that allows
the user to specify whether values should be trimmed. By default, trimming is switched on.
If you need to provide a double quote character while inside a quoted token, use two double-quotes next to one another.
Constructor Summary | |
---|---|
CsvReader()
|
|
CsvReader(char separator)
|
|
CsvReader(Reader reader)
|
|
CsvReader(Reader reader,
char separator)
|
Method Summary | |
---|---|
void |
ensureCapacity(int numLines)
Provide some forewarning of the number of lines that will need to be processed, so that data structures do not have to be resized dynamically. |
Reader |
getReader()
Returns a BufferedReader. |
char |
getSeparator()
|
static boolean |
isBufferedReader(Reader reader)
|
boolean |
isTrimmingValues()
|
List<List<String>> |
parse()
|
List<List<String>> |
parse(File file)
|
List<List<String>> |
parse(InputStream is)
|
List<List<String>> |
parse(Reader reader)
|
void |
parseForEffects(CsvParseListener listener)
A special method that does not return any parsed data but relies on the supplied listener to do any necessary processing. |
void |
setReader(Reader reader)
Sets the reader as the source of data. |
void |
setSeparator(char separator)
|
void |
setTrimmingValues(boolean trimmingValues)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CsvReader()
public CsvReader(char separator)
public CsvReader(Reader reader)
public CsvReader(Reader reader, char separator)
Method Detail |
---|
public void ensureCapacity(int numLines)
numLines
- the number of lines to expect in the inputpublic void setReader(Reader reader)
reader
- the reader that provides the datapublic Reader getReader()
public void setSeparator(char separator)
public char getSeparator()
public boolean isTrimmingValues()
public void setTrimmingValues(boolean trimmingValues)
public List<List<String>> parse(File file) throws IOException
IOException
public List<List<String>> parse(InputStream is) throws IOException
IOException
public static boolean isBufferedReader(Reader reader)
public List<List<String>> parse() throws IOException
IOException
public List<List<String>> parse(Reader reader) throws IOException
IOException
public void parseForEffects(CsvParseListener listener) throws IOException
We call this parseForEffects
to emphasize that the responsibility
for dealing with the results of parsing is with the user of this class, through
the supplied CsvParseListener
.
listener
- the listener that will be notified of events and associated data during parsing
IOException
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |