com.continuent.tungsten.common.csv
Class CsvReader

java.lang.Object
  extended by com.continuent.tungsten.common.csv.CsvReader

public class CsvReader
extends java.lang.Object

Reads CSV format output with appropriate conversions to Java data types.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
CsvReader(java.io.BufferedReader reader)
          Instantiate a new instance with input from provided buffered reader.
CsvReader(java.io.Reader reader)
          Instantiate a new instance with input from provided reader.
 
Method Summary
 java.lang.String getInputSeparators()
          Returns input separate characters.
 java.util.List<java.lang.String> getNames()
          Return names in column order.
 int getRowCount()
          Returns the current count of rows read.
 java.lang.String getString(int index)
          Gets a value from the current row.
 java.lang.String getString(java.lang.String key)
          Gets a string from the current row.
 int getWidth()
          Return the number of columns.
 boolean isCollapseSeparators()
          Returns true if successive input separators should be treated as a single separator.
 boolean isUseHeaders()
          Returns true if input should contain column headers in first row.
 boolean next()
          Positions to next row and returns true if there are data to be read.
 void setCollapseSeparators(boolean collapseSeparators)
          If set to true treat successive input separators as a single separator.
 void setInputSeparators(java.lang.String inputSeparators)
          Sets the input separator characters.
 void setUseHeaders(boolean useHeaders)
          If set to true first row must contain column headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvReader

public CsvReader(java.io.Reader reader)
Instantiate a new instance with input from provided reader.


CsvReader

public CsvReader(java.io.BufferedReader reader)
Instantiate a new instance with input from provided buffered reader. This call allows clients to set buffering parameters themselves.

Method Detail

setInputSeparators

public void setInputSeparators(java.lang.String inputSeparators)
Sets the input separator characters.


getInputSeparators

public java.lang.String getInputSeparators()
Returns input separate characters.


isCollapseSeparators

public boolean isCollapseSeparators()
Returns true if successive input separators should be treated as a single separator.


setCollapseSeparators

public void setCollapseSeparators(boolean collapseSeparators)
If set to true treat successive input separators as a single separator.


isUseHeaders

public boolean isUseHeaders()
Returns true if input should contain column headers in first row.


setUseHeaders

public void setUseHeaders(boolean useHeaders)
If set to true first row must contain column headers.


getRowCount

public int getRowCount()
Returns the current count of rows read.


getNames

public java.util.List<java.lang.String> getNames()
Return names in column order.


getWidth

public int getWidth()
Return the number of columns.


next

public boolean next()
             throws java.io.IOException
Positions to next row and returns true if there are data to be read.

Throws:
java.io.IOException - Thrown if there is an IO error.

getString

public java.lang.String getString(int index)
                           throws CsvException
Gets a value from the current row.

Parameters:
index - Column index where indexes are numbered 1,2,3,...,N with N being the width of the row in columns
Throws:
CsvException - Thrown if read is invalid

getString

public java.lang.String getString(java.lang.String key)
                           throws CsvException
Gets a string from the current row.

Throws:
CsvException