net.sf.jmatchparser.util.csv
Class CSVReader

java.lang.Object
  extended by net.sf.jmatchparser.util.csv.AbstractCSVReader
      extended by net.sf.jmatchparser.util.csv.CSVReader

public class CSVReader
extends AbstractCSVReader

Class to read data from a CSV (Comma Separated Value) file, supporting different separator characters and quoted values.


Constructor Summary
CSVReader(BufferedReader br)
          Create a new CSVReader that reads from the given buffered reader.
CSVReader(InputStream in, String charsetName)
          Create a new CSVReader that reads from the given stream.
CSVReader(Reader r)
          Create a new CSVReader that reads from the given reader.
 
Method Summary
 void close()
          Close this reader.
 char getSeparator()
          Return the separator character (usually comma, tab or semicolon), or 0 to auto-detect.
 String[] read()
          Read a line from the CSV file.
 void setSeparator(char separator)
          Set the separator character (usually comma, tab or semicolon), or 0 to auto-detect.
 void setStripComments(boolean stripComments)
          Set whether comments (lines starting with # or empty lines) should be stripped.
 void setSupportFullyQuotedLines(boolean supportFullyQuotedLines)
          Some broken CSV writers quote the whole line if no field of the line needs to be quoted.
 void setSupportMultiLineCells(boolean supportMutiLineCells)
          Enable support for multi-line values in cells.
 
Methods inherited from class net.sf.jmatchparser.util.csv.AbstractCSVReader
read, read, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader(BufferedReader br)
Create a new CSVReader that reads from the given buffered reader.


CSVReader

public CSVReader(Reader r)
Create a new CSVReader that reads from the given reader.


CSVReader

public CSVReader(InputStream in,
                 String charsetName)
          throws UnsupportedEncodingException
Create a new CSVReader that reads from the given stream.

Throws:
UnsupportedEncodingException
Method Detail

getSeparator

public char getSeparator()
Return the separator character (usually comma, tab or semicolon), or 0 to auto-detect.


setSeparator

public void setSeparator(char separator)
Set the separator character (usually comma, tab or semicolon), or 0 to auto-detect.


setStripComments

public void setStripComments(boolean stripComments)
Set whether comments (lines starting with # or empty lines) should be stripped.


setSupportFullyQuotedLines

public void setSupportFullyQuotedLines(boolean supportFullyQuotedLines)
Some broken CSV writers quote the whole line if no field of the line needs to be quoted. In that case, a standard-compliant CSV parser will read everything into one field. To support these files, this option can be enabled. In that case, if there is only a quote character at the beginning and the end of the line, it is stripped.


setSupportMultiLineCells

public void setSupportMultiLineCells(boolean supportMutiLineCells)
Enable support for multi-line values in cells. In that case, if a quotation mark is not closed within the same line, more lines are read to find the closing quotation mark. Lines will be combined with newline characters \n regardless of the original line delimiter character. If disabled, quotation marks that are not closed within the same line are treated as a parse error.


close

public void close()
           throws IOException
Description copied from class: AbstractCSVReader
Close this reader.

Specified by:
close in class AbstractCSVReader
Throws:
IOException

read

public String[] read()
              throws IOException
Description copied from class: AbstractCSVReader
Read a line from the CSV file.

Specified by:
read in class AbstractCSVReader
Throws:
IOException


Copyright © 2011. All Rights Reserved.