|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tbee.csv.CSVFileParser
public class CSVFileParser
This class provides file level access to the CSV parser.
It requires an input stream, where it will read lines upto the line separator and then use the StringParser to split it into fields.
Usage of this class is simple:
// create the parser
CSVFileParser lCSVFileParser = new CSVFileParser( new FileInputStream(new File(...)) );
// start reading
String[] lFields = null;
while ( (lFields = lCSVFileParser.parseNextLine()) != null)
{ ... }
The default line separator is per default a newline (\n) but can be set prior to parsing.
The field separator can be set in the StringParser using getStringParser().
The parser recognizes comment lines if the first character in a line is a comment marker, default (#).
The first line may contain header information. In this case the identifiers are used in the map.
The file parsers counts the lines it has parsed according to the line separator.
| Field Summary | |
|---|---|
static String |
SOURCECODE_VERSION
Standard variable for determining version of a class file. |
| Constructor Summary | |
|---|---|
CSVFileParser()
Just the basic constructor Note that a inputstream must be set before the parse method is called |
|
CSVFileParser(InputStream pInputStream)
Usually there is a stream that is parsed This need not be a file inputstream |
|
CSVFileParser(Reader pReader)
Usually there is a stream that is parsed This need not be a file inputstream |
|
| Method Summary | |
|---|---|
char |
getComment()
|
boolean |
getFirstLineContainsHeader()
|
String[] |
getHeader()
If present, get the header |
long |
getLineNumber()
|
Reader |
getReader()
|
String |
getSeparator()
|
boolean |
getSkipEmptyLines()
|
CSVStringParser |
getStringParser()
|
String[] |
parseNextLine()
Read and parse the next line and return the fields |
Map |
parseNextLineAsMap()
Read and rarse the next line and return the fields as a map |
String |
readNextLine()
Read the next line This method will skip comment lines |
void |
setComment(char pComment)
|
void |
setFirstLineContainsHeader(boolean pFirstLineContainsHeader)
|
void |
setInputStream(InputStream pInputStream)
convenience method |
void |
setReader(Reader pReader)
|
void |
setSeparator(String pSeparator)
|
void |
setSkipEmptyLines(boolean pSkipEmptyLines)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String SOURCECODE_VERSION
| Constructor Detail |
|---|
public CSVFileParser()
public CSVFileParser(InputStream pInputStream)
public CSVFileParser(Reader pReader)
| Method Detail |
|---|
public void setSeparator(String pSeparator)
public String getSeparator()
public void setComment(char pComment)
public char getComment()
public void setReader(Reader pReader)
public Reader getReader()
public void setInputStream(InputStream pInputStream)
pInputStream - public long getLineNumber()
public CSVStringParser getStringParser()
public void setFirstLineContainsHeader(boolean pFirstLineContainsHeader)
public boolean getFirstLineContainsHeader()
public void setSkipEmptyLines(boolean pSkipEmptyLines)
public boolean getSkipEmptyLines()
public String readNextLine()
throws IOException
IOException
public String[] getHeader()
throws IOException
IOException
public String[] parseNextLine()
throws IOException
IOException
public Map parseNextLineAsMap()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||