olg.csv.base.csv
Class CSVReader

Package class diagram package CSVReader
java.lang.Object
  extended by olg.csv.base.csv.CSVReader
All Implemented Interfaces:
Closeable, Iterator<Row>, IReader

public final class CSVReader
extends Object
implements IReader

CSV Reader. CSV Implementation of IReader.


Field Summary
private  String charset
          Read file Charset.
private  String ddelimiter
          Double Delimiter.
private  char delimiter
          Cell delimiter.
private  int fieldIndex
          Current cell number.
private  FileInputStream fileInputStream
          the CSV file input stream.
private static org.slf4j.Logger LOGGER
          the class Logger.
private  CharSearchReader reader
          the char search reader applied on the stream.
private  int recordIndex
          current row number.
private  int rowSize
          Read Row size.
private  char separator
          cell separator.
private  boolean skipEmptyCell
          if true the returned rows will only contain not empty cells.
private  boolean withHeaders
          to skip headers.
 
Constructor Summary
  CSVReader(File file, CSVSettings settings)
          Constructor with custom settings.
protected CSVReader(File file, CSVSettings settings, int bufSize)
          Constructor with custom settings.
  CSVReader(InputStream input, CSVSettings settings)
          Constructor with custom settings.
 
Method Summary
 void close()
          Closes this stream and catches and logs IOException. if the parent stream is provided and passed to CSVReader constructor by user, user must close it (closes what you opens!)
private  String getFieldDelimiterCase()
          Get next field value in case field has delimiters around.
private  String getFieldNoDelimiterCase()
          Get next field value when a field has no delimiters around.
 boolean hasNext()
          
 boolean isWithHeaders()
          Indicates the CSV file has a header line.
 Row next()
          
private  Cell readCell()
          Read a cell.
 void remove()
           CSVReader throws an UnsupportedOperationException.
private  Row setNext()
          Returns next row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final org.slf4j.Logger LOGGER
the class Logger.


skipEmptyCell

private boolean skipEmptyCell
if true the returned rows will only contain not empty cells.


separator

private char separator
cell separator.


delimiter

private char delimiter
Cell delimiter.


ddelimiter

private String ddelimiter
Double Delimiter. Virtue of CSV rfc, delimiter character must be twice in a cell to represent it.


charset

private String charset
Read file Charset.


withHeaders

private boolean withHeaders
to skip headers.


fieldIndex

private int fieldIndex
Current cell number.


recordIndex

private int recordIndex
current row number.


fileInputStream

private FileInputStream fileInputStream
the CSV file input stream.


reader

private CharSearchReader reader
the char search reader applied on the stream.


rowSize

private int rowSize
Read Row size.

Constructor Detail

CSVReader

public CSVReader(File file,
                 CSVSettings settings)
          throws IOException
Constructor with custom settings.

throws UnsupportedCharsetException if charset is not supported.

throws FileNotFoundException if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.

throws IllegalArgumentException if file, CSVSettings, lineSeparator setting or charsetName setting is null

Parameters:
file - the file to be read.
settings - the settings.
Throws:
IOException - if error occurs on file opening.
See Also:
to see default parameters values

CSVReader

protected CSVReader(File file,
                    CSVSettings settings,
                    int bufSize)
             throws IOException
Constructor with custom settings.

throws UnsupportedCharsetException if charset is not supported.

throws FileNotFoundException if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.

Parameters:
file - the file.
settings - the settings
bufSize - the buffer size.
Throws:
IOException - if error occurs on file opening.
See Also:
to see default parameters values

CSVReader

public CSVReader(InputStream input,
                 CSVSettings settings)
          throws IOException
Constructor with custom settings.

throws UnsupportedCharsetException if charset is not supported.

throws IllegalArgumentException if input, CSVSettings or charsetName setting is null

Parameters:
input - the stream
settings - the settings.
Throws:
IOException - if error occurs on stream buffering.
See Also:
to see default parameters values
Method Detail

isWithHeaders

public boolean isWithHeaders()
Indicates the CSV file has a header line.

Specified by:
isWithHeaders in interface IReader
Returns:
if the CSV file has a header line.

hasNext

public boolean hasNext()

Specified by:
hasNext in interface Iterator<Row>

next

public Row next()

Specified by:
next in interface Iterator<Row>

remove

public void remove()
CSVReader throws an UnsupportedOperationException.

Specified by:
remove in interface Iterator<Row>

close

public void close()
Closes this stream and catches and logs IOException. if the parent stream is provided and passed to CSVReader constructor by user, user must close it (closes what you opens!)

Specified by:
close in interface Closeable

setNext

private Row setNext()
Returns next row.

Throws a ReaderException if a CSV constraint is not satisfied.

Returns:
the next row.

readCell

private Cell readCell()
               throws IOException
Read a cell.

Throws a ReaderException if a CSV constraint is not satisfied.

Returns:
the cell.
Throws:
IOException - if I/O error occurs on stream reading.

getFieldDelimiterCase

private String getFieldDelimiterCase()
                              throws IOException
Get next field value in case field has delimiters around.

Throws a ReaderException if a CSV constraint is not satisfied.

Returns:
the value.
Throws:
IOException - if I/O error occurs on stream reading.

getFieldNoDelimiterCase

private String getFieldNoDelimiterCase()
                                throws IOException
Get next field value when a field has no delimiters around.

Returns:
the value.
Throws:
IOException - if I/O error occurs on stream reading.


Copyright © 2014. All rights reserved.