Top Description Fields Constructors Methods
org.jooq.tools.csv

public Class CSVReader

extends Object
implements Closeable, Iterator<String[]>
Class Inheritance
All Implemented Interfaces
java.util.Iterator, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.BufferedReader, .Closeable, .IOException, .Reader, java.util.ArrayList, .Iterator, .List

A very simple CSV reader released under a commercial-friendly license.
Author
Glen Smith

Field Summary

Modifier and TypeField and Description
private BufferedReader
public static final int
DEFAULT_SKIP_LINES

The default line to start reading.

private boolean
private boolean
private CSVParser
private int

Constructor Summary

AccessConstructor and Description
public
CSVReader(Reader
the reader to an underlying CSV source.
reader
)

Constructs CSVReader using a comma for the separator.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries.
separator
)

Constructs CSVReader with supplied separator.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
)

Constructs CSVReader with supplied separator and quote char.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
boolean
sets if characters outside the quotes are ignored
strictQuotes
)

Constructs CSVReader with supplied separator, quote char and quote handling behavior.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
char
the character to use for escaping a separator or quote
escape
)

Constructs CSVReader with supplied separator and quote char.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
int
the line number to skip for start reading
line
)

Constructs CSVReader with supplied separator and quote char.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
char
the character to use for escaping a separator or quote
escape
,
int
the line number to skip for start reading
line
)

Constructs CSVReader with supplied separator and quote char.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
char
the character to use for escaping a separator or quote
escape
,
int
the line number to skip for start reading
line
,
boolean
sets if characters outside the quotes are ignored
strictQuotes
)

Constructs CSVReader with supplied separator and quote char.

public
CSVReader(Reader
the reader to an underlying CSV source.
reader
,
char
the delimiter to use for separating entries
separator
,
char
the character to use for quoted elements
quotechar
,
char
the character to use for escaping a separator or quote
escape
,
int
the line number to skip for start reading
line
,
boolean
sets if characters outside the quotes are ignored
strictQuotes
,
boolean
it true, parser should ignore white space before a quote in a field
ignoreLeadingWhiteSpace
)

Constructs CSVReader with supplied separator and quote char.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes the underlying reader.
private String

Returns:

the next line from the file without trailing newline
getNextLine
()

Reads the next line from the file.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public String[]
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public List<String[]>

Returns:

a List of String[], with each String[] representing a line of the file.
readAll
()

Reads the entire file into a List with each element being a String[] of tokens.

public String[]

Returns:

a string array with each comma-separated element as a separate entry.
readNext
()

Reads the next line from the buffer and converts to a string array.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

brback to summary
private BufferedReader br
DEFAULT_SKIP_LINESback to summary
public static final int DEFAULT_SKIP_LINES

The default line to start reading.

hasNextback to summary
private boolean hasNext
linesSkipedback to summary
private boolean linesSkiped
parserback to summary
private CSVParser parser
skipLinesback to summary
private int skipLines

Constructor Detail

CSVReaderback to summary
public CSVReader(Reader reader)

Constructs CSVReader using a comma for the separator.

Parameters
reader:Reader

the reader to an underlying CSV source.

CSVReaderback to summary
public CSVReader(Reader reader, char separator)

Constructs CSVReader with supplied separator.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries.

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, boolean strictQuotes)

Constructs CSVReader with supplied separator, quote char and quote handling behavior.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

strictQuotes:boolean

sets if characters outside the quotes are ignored

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, char escape)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

escape:char

the character to use for escaping a separator or quote

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, int line)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

line:int

the line number to skip for start reading

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, char escape, int line)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

escape:char

the character to use for escaping a separator or quote

line:int

the line number to skip for start reading

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

escape:char

the character to use for escaping a separator or quote

line:int

the line number to skip for start reading

strictQuotes:boolean

sets if characters outside the quotes are ignored

CSVReaderback to summary
public CSVReader(Reader reader, char separator, char quotechar, char escape, int line, boolean strictQuotes, boolean ignoreLeadingWhiteSpace)

Constructs CSVReader with supplied separator and quote char.

Parameters
reader:Reader

the reader to an underlying CSV source.

separator:char

the delimiter to use for separating entries

quotechar:char

the character to use for quoted elements

escape:char

the character to use for escaping a separator or quote

line:int

the line number to skip for start reading

strictQuotes:boolean

sets if characters outside the quotes are ignored

ignoreLeadingWhiteSpace:boolean

it true, parser should ignore white space before a quote in a field

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes the underlying reader.

Annotations
@Override
Exceptions
IOException:
if the close fails
getNextLineback to summary
private String getNextLine() throws IOException

Reads the next line from the file.

Returns:String

the next line from the file without trailing newline

Exceptions
IOException:
if bad things happen during the read
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public String[] next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:String[]

the next element in the iteration

Annotations
@Override
readAllback to summary
public List<String[]> readAll() throws IOException

Reads the entire file into a List with each element being a String[] of tokens.

Returns:List<String[]>

a List of String[], with each String[] representing a line of the file.

Exceptions
IOException:
if bad things happen during the read
readNextback to summary
public String[] readNext() throws IOException

Reads the next line from the buffer and converts to a string array.

Returns:String[]

a string array with each comma-separated element as a separate entry.

Exceptions
IOException:
if bad things happen during the read
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override