CSVObjects Framework

net.sf.anupam.csv
Class CSVReader

java.lang.Object
  extended by net.sf.anupam.csv.CSVReader
All Implemented Interfaces:
Iterable<List<String>>

 class CSVReader
extends Object
implements Iterable<List<String>>

Reads a CSV file and parses the individual fields for each CSV record in the file. The default delimiter is assumed to be the , (comma).

The class uses the CSV Parser engines from Steven Ostermiller's site.

Since:
1.5
Version:
$Revision: 1.3 $
Author:
Anupam Sengupta
See Also:
CSVParse

Constructor Summary
CSVReader(Reader csvReader, boolean headerPresent)
          Constructor which accepts a reader on the CSV stream to parse.
 
Method Summary
 void close()
          Releases all system resources.
protected  void finalize()
          Finalizes this CSV reader and closes the IO connections.
protected  CSVParse getParser()
          Returns the internal CSV parser engine instance for this reader.
 boolean isHeaderPresent()
          Indicates whether the header row is present or not.
 boolean isReadingComplete()
          Indicates whether the reader has read all CSV lines.
 Iterator<List<String>> iterator()
          Returns an iterator over the parsed lines.
protected  void readingIsComplete()
          Sets the flag to denote that all lines have been read.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader(Reader csvReader,
                 boolean headerPresent)
Constructor which accepts a reader on the CSV stream to parse. The presence of a CSV header row is also specified. If present, the header row will be skipped.

Parameters:
csvReader - the CSV stream reader from which to parse
headerPresent - indicates whether the CSV stream has a header record
Method Detail

close

public void close()
Releases all system resources.


finalize

protected void finalize()
                 throws Throwable
Finalizes this CSV reader and closes the IO connections.

Overrides:
finalize in class Object
Throws:
Throwable - thrown if the finalization fails.
See Also:
Object.finalize()

iterator

public Iterator<List<String>> iterator()
Returns an iterator over the parsed lines. The iterator returns a list of the CSV field values as a single value over each iteration.

Specified by:
iterator in interface Iterable<List<String>>
Returns:
an iterator over the lines.

isHeaderPresent

public boolean isHeaderPresent()
Indicates whether the header row is present or not.

Returns:
Returns true if the header row is present

isReadingComplete

public boolean isReadingComplete()
Indicates whether the reader has read all CSV lines.

Returns:
Returns true if all CSV lines have been read

readingIsComplete

protected void readingIsComplete()
Sets the flag to denote that all lines have been read.


getParser

protected CSVParse getParser()
Returns the internal CSV parser engine instance for this reader.

Returns:
Returns the parser instance

SourceForge.net Logo

© Anupam Sengupta 2005