|
-bottom | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.csv4j.CSVStreamProcessor
public class CSVStreamProcessor
Provides an easy to use mechanism to process CSV streams. The details of reading and parsing the CSV stream along with its header are managed.
The API provides a callback processor interface (CSVLineProcessor
)
which is called as the stream is processed to receive the CSV header and data lines.
A simpler interface, CSVFieldMapProcessor
,
provides the field name and values for each line as an easy to access Map.
Example usage with CSVLineProcessor:
final CSVStreamProcessor fp = new CSVStreamProcessor(); fp.processStream( "data.csv", new CSVLineProcessor() { public void processHeaderLine( int linenumber, List<String> fields ) { // use / save the header } public void processDataLine( int linenumber, List<String> fields ) { // use the data } } );
Example usage with CSVFieldMapProcessor:
final CSVStreamProcessor fp = new CSVStreamProcessor(); fp.processStream( "data.csv", new CSVFieldMapProcessor() { public void processDataLine( int linenumber, Map<String,String> fields ) { // use the data } } );
Constructor Summary | |
---|---|
CSVStreamProcessor()
Constructor. |
Method Summary | |
---|---|
char |
getComment()
Returns the comment setting. |
boolean |
isHasHeader()
Indicates if the file has a header line. |
int |
processStream(InputStreamReader is,
CSVFieldMapProcessor processor)
Processes the CSV file using the provided processor. |
int |
processStream(InputStreamReader is,
CSVLineProcessor processor)
Processes the CSV file using the provided processor. |
int |
processStream(InputStreamReader is,
CSVSortedFieldMapProcessor processor)
Processes the CSV file using the provided processor. |
void |
setComment(char comment)
Sets the comment string value. |
void |
setHasHeader(boolean hasHeader)
Sets the hasHeader value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CSVStreamProcessor()
Method Detail |
---|
public char getComment()
public void setComment(char comment)
comment
- the new comment string valuepublic boolean isHasHeader()
public void setHasHeader(boolean hasHeader)
hasHeader
- true if file has a header line; false if notpublic int processStream(InputStreamReader is, CSVLineProcessor processor) throws IOException, ProcessingException, ParseException
is
- stream to read CSV fromprocessor
- handler to process the CSV lines
FileNotFoundException
- if file not found
IOException
- if a read error occurs
ProcessingException
- if an exception is thrown by the processor
ParseException
- if a error occurs parsing the CSV linepublic int processStream(InputStreamReader is, CSVFieldMapProcessor processor) throws IOException, ProcessingException, ParseException
is
- stream to read CSV fromprocessor
- handler to process the CSV lines
FileNotFoundException
- if file not found
IOException
- if a read error occurs
ProcessingException
- if an exception is thrown by the processor
ParseException
- if a error occurs parsing the CSV linepublic int processStream(InputStreamReader is, CSVSortedFieldMapProcessor processor) throws IOException, ProcessingException, ParseException
is
- stream to read CSV fromprocessor
- handler to process the CSV lines
FileNotFoundException
- if file not found
IOException
- if a read error occurs
ProcessingException
- if an exception is thrown by the processor
ParseException
- if a error occurs parsing the CSV line
|
-bottom | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |