org.tbee.csv
Class CSVFileParser

java.lang.Object
  extended by org.tbee.csv.CSVFileParser

public class CSVFileParser
extends Object

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.

Version:
$Revision: 1.10 $
Author:
$Author: cvs $

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

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

CSVFileParser

public CSVFileParser()
Just the basic constructor Note that a inputstream must be set before the parse method is called


CSVFileParser

public CSVFileParser(InputStream pInputStream)
Usually there is a stream that is parsed This need not be a file inputstream


CSVFileParser

public CSVFileParser(Reader pReader)
Usually there is a stream that is parsed This need not be a file inputstream

Method Detail

setSeparator

public void setSeparator(String pSeparator)

getSeparator

public String getSeparator()

setComment

public void setComment(char pComment)

getComment

public char getComment()

setReader

public void setReader(Reader pReader)

getReader

public Reader getReader()

setInputStream

public void setInputStream(InputStream pInputStream)
convenience method

Parameters:
pInputStream -

getLineNumber

public long getLineNumber()

getStringParser

public CSVStringParser getStringParser()

setFirstLineContainsHeader

public void setFirstLineContainsHeader(boolean pFirstLineContainsHeader)

getFirstLineContainsHeader

public boolean getFirstLineContainsHeader()

setSkipEmptyLines

public void setSkipEmptyLines(boolean pSkipEmptyLines)

getSkipEmptyLines

public boolean getSkipEmptyLines()

readNextLine

public String readNextLine()
                    throws IOException
Read the next line This method will skip comment lines

Throws:
IOException

getHeader

public String[] getHeader()
                   throws IOException
If present, get the header

Throws:
IOException

parseNextLine

public String[] parseNextLine()
                       throws IOException
Read and parse the next line and return the fields

Throws:
IOException

parseNextLineAsMap

public Map parseNextLineAsMap()
                       throws IOException
Read and rarse the next line and return the fields as a map

Throws:
IOException


Copyright © 2011 KnowledgePlaza. All Rights Reserved.