|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nrs.util.CSVParser
Parses a CSV file and informs a listener of new values.
To use, declare the class that wants to parse CSV values as implementing the nrs.util.CSVListener interface along with implementations of the newCSVValue(String value, boolean newLine) and noMoreCSVValues() methods. Then create a new instance of CSVParser and pass in a BufferedReader which wraps the CSV source, field and text delimiters and the listening class. Calling the parse() method will start parsing. If you want to stop halfway through the file then call the stop() method.
This class can also be called directly as java nrs.util.CSVParser -csv file.csv to see how it works.
Constructor Summary | |
CSVParser()
Create a new instance of CSVParser using default values for the field and text delimiter. |
|
CSVParser(java.io.BufferedReader reader,
java.lang.String fieldDelimiter,
java.lang.String textDelimiter,
CSVListener listener)
Creates a new instance of CSVReader |
Method Summary | |
java.lang.String |
getFieldDelimiter()
Get the currect field delimiter |
CSVListener |
getListener()
Get the currect CSVListener |
java.io.BufferedReader |
getReader()
Get the current BufferedReader |
java.lang.String |
getTextDelimiter()
Get the current text delimiter |
boolean |
hasReadAll()
Check to see if the CSV source has a) finished being parsed, and b) all values were read |
boolean |
isNoTextDelimiter()
|
static void |
main(java.lang.String[] args)
Main method for testing |
void |
newCSVValue(java.lang.String value,
int lineNum)
A new CSV value has been found |
void |
noMoreCSVValues()
Finished parsing the input |
void |
parse()
Parse the data from the specified BufferedReader |
void |
setFieldDelimiter(java.lang.String fDelim)
Set the field delimiter |
void |
setListener(CSVListener listener)
Set the listener of CSV events |
void |
setNoTextDelimiter(boolean noTextDelimiter)
If set the parser won't look for text delimiters. |
void |
setReader(java.io.BufferedReader reader)
Set the BufferedReader which will read the CSV source |
void |
setTextDelimiter(java.lang.String tDelim)
Set the text delimiter |
void |
stop()
Tell the CSVReader not to continue parsing |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CSVParser()
setReader(BufferedReader)
,
setListener(CSVListener)
public CSVParser(java.io.BufferedReader reader, java.lang.String fieldDelimiter, java.lang.String textDelimiter, CSVListener listener)
reader
- BufferedReader of the CSV sourcefieldDelimiter
- the field delimiter, e.g. ,textDelimiter
- the text delimiter, e.g. "listener
- the class that wants to be informed of CSV valuesMethod Detail |
public void setReader(java.io.BufferedReader reader)
reader
- the CSV sourcepublic java.io.BufferedReader getReader()
public void setListener(CSVListener listener)
listener
- CSVListenerpublic CSVListener getListener()
public void setFieldDelimiter(java.lang.String fDelim)
fDelim
- the field delimiter characterpublic java.lang.String getFieldDelimiter()
public void setTextDelimiter(java.lang.String tDelim)
tDelim
- the text delimiter characterpublic java.lang.String getTextDelimiter()
public boolean isNoTextDelimiter()
public void setNoTextDelimiter(boolean noTextDelimiter)
noTextDelimiter
- set to true to not scan for text delimiterpublic void parse() throws java.io.IOException
java.io.IOException
- an error occured reading the CSV sourcepublic void stop()
public boolean hasReadAll()
public void newCSVValue(java.lang.String value, int lineNum)
newCSVValue
in interface CSVListener
value
- the new valuelineNum
- line number, starting from 0public void noMoreCSVValues()
CSVListener
noMoreCSVValues
in interface CSVListener
public static void main(java.lang.String[] args)
args
- command line arguments
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |