JIDE 3.5.15

com.jidesoft.csv
Class CsvReader

java.lang.Object
  extended by com.jidesoft.csv.CsvReader

public class CsvReader
extends Object

A class for reading comma-separated values files and streams. Actually the inputs do not have to be comma-separated - you can specify the character that is used as a separator.

Values containing commas can be provided by putting the value in double quotes. For example, p,"a,b,c",q is a sequence of three values, not five.

Apparently it is a contentious issue whether spaces around the values (and next to a separator) are trimmed. It appears to be common practice and yet contrary to RFC 4180, so I have provided a property trimmingValues that allows the user to specify whether values should be trimmed. By default, trimming is switched on.

If you need to provide a double quote character while inside a quoted token, use two double-quotes next to one another.

Author:
Simon White (swhite@catalysoft.com)

Constructor Summary
CsvReader()
           
CsvReader(char separator)
           
CsvReader(Reader reader)
           
CsvReader(Reader reader, char separator)
           
 
Method Summary
 void ensureCapacity(int numLines)
          Provide some forewarning of the number of lines that will need to be processed, so that data structures do not have to be resized dynamically.
 Reader getReader()
          Returns a BufferedReader.
 char getSeparator()
           
static boolean isBufferedReader(Reader reader)
           
 boolean isTrimmingValues()
           
 List<List<String>> parse()
           
 List<List<String>> parse(File file)
           
 List<List<String>> parse(InputStream is)
           
 List<List<String>> parse(Reader reader)
           
 void parseForEffects(CsvParseListener listener)
          A special method that does not return any parsed data but relies on the supplied listener to do any necessary processing.
 void setReader(Reader reader)
          Sets the reader as the source of data.
 void setSeparator(char separator)
           
 void setTrimmingValues(boolean trimmingValues)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvReader

public CsvReader()

CsvReader

public CsvReader(char separator)

CsvReader

public CsvReader(Reader reader)

CsvReader

public CsvReader(Reader reader,
                 char separator)
Method Detail

ensureCapacity

public void ensureCapacity(int numLines)
Provide some forewarning of the number of lines that will need to be processed, so that data structures do not have to be resized dynamically.

Parameters:
numLines - the number of lines to expect in the input

setReader

public void setReader(Reader reader)
Sets the reader as the source of data. If the Reader is not a BufferedReader, it will automatically be wrapped in a BufferedReader

Parameters:
reader - the reader that provides the data

getReader

public Reader getReader()
Returns a BufferedReader. If a BufferedReader was not supplied in the setter, then the supplied reader will have been wrapped in BufferedReader, which will be returned here.

Returns:
a BufferedReader

setSeparator

public void setSeparator(char separator)

getSeparator

public char getSeparator()

isTrimmingValues

public boolean isTrimmingValues()

setTrimmingValues

public void setTrimmingValues(boolean trimmingValues)

parse

public List<List<String>> parse(File file)
                         throws IOException
Throws:
IOException

parse

public List<List<String>> parse(InputStream is)
                         throws IOException
Throws:
IOException

isBufferedReader

public static boolean isBufferedReader(Reader reader)

parse

public List<List<String>> parse()
                         throws IOException
Throws:
IOException

parse

public List<List<String>> parse(Reader reader)
                         throws IOException
Throws:
IOException

parseForEffects

public void parseForEffects(CsvParseListener listener)
                     throws IOException
A special method that does not return any parsed data but relies on the supplied listener to do any necessary processing. This can be useful when processing large files, as the whole of the input file does not need to stored in main memory.

We call this parseForEffects to emphasize that the responsibility for dealing with the results of parsing is with the user of this class, through the supplied CsvParseListener.

Parameters:
listener - the listener that will be notified of events and associated data during parsing
Throws:
IOException

JIDE 3.5.15