|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectliquibase.util.csv.opencsv.CSVReader
public class CSVReader
A very simple CSV reader released under a commercial-friendly license.
| Field Summary | |
|---|---|
static boolean |
DEFAULT_KEEP_CR
|
static int |
DEFAULT_SKIP_LINES
The default line to start reading. |
static boolean |
DEFAULT_VERIFY_READER
|
static int |
READ_AHEAD_LIMIT
|
| Constructor Summary | |
|---|---|
CSVReader(Reader reader)
Constructs CSVReader using a comma for the separator. |
|
CSVReader(Reader reader,
char separator)
Constructs CSVReader with supplied separator. |
|
CSVReader(Reader reader,
char separator,
char quotechar)
Constructs CSVReader with supplied separator and quote char. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
boolean strictQuotes)
Constructs CSVReader with supplied separator, quote char and quote handling behavior. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
char escape)
Constructs CSVReader. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line)
Constructs CSVReader. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes)
Constructs CSVReader. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes,
boolean ignoreLeadingWhiteSpace)
Constructs CSVReader with all data entered. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes,
boolean ignoreLeadingWhiteSpace,
boolean keepCR)
Constructs CSVReader with all data entered. |
|
CSVReader(Reader reader,
char separator,
char quotechar,
int line)
Constructs CSVReader. |
|
CSVReader(Reader reader,
int line,
CSVParser csvParser)
Constructs CSVReader with supplied CSVParser. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying reader. |
protected String[] |
combineResultsFromMultipleReads(String[] buffer,
String[] lastRead)
For multi line records this method combines the current result with the result from previous read(s). |
long |
getLinesRead()
Used for debugging purposes this method returns the number of lines that has been read from the reader passed into the CSVReader. |
protected String |
getNextLine()
Reads the next line from the file. |
CSVParser |
getParser()
|
long |
getRecordsRead()
Used for debugging purposes this method returns the number of records that has been read from the CSVReader. |
int |
getSkipLines()
Returns the number of lines in the csv file to skip before processing. |
Iterator<String[]> |
iterator()
Creates an Iterator for processing the csv data. |
boolean |
keepCarriageReturns()
Returns if the reader will keep carriage returns found in data or remove them. |
List<String[]> |
readAll()
Reads the entire file into a List with each element being a String[] of tokens. |
String[] |
readNext()
Reads the next line from the buffer and converts to a string array. |
protected String[] |
validateResult(String[] result)
Increments the number of records read if the result passed in is not null. |
boolean |
verifyReader()
Returns if the CSVReader will verify the reader before each read. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final boolean DEFAULT_KEEP_CR
public static final boolean DEFAULT_VERIFY_READER
public static final int DEFAULT_SKIP_LINES
public static final int READ_AHEAD_LIMIT
| Constructor Detail |
|---|
public CSVReader(Reader reader)
reader - the reader to an underlying CSV source.
public CSVReader(Reader reader,
char separator)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entries.
public CSVReader(Reader reader,
char separator,
char quotechar)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elements
public CSVReader(Reader reader,
char separator,
char quotechar,
boolean strictQuotes)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsstrictQuotes - sets if characters outside the quotes are ignored
public CSVReader(Reader reader,
char separator,
char quotechar,
char escape)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescape - the character to use for escaping a separator or quote
public CSVReader(Reader reader,
char separator,
char quotechar,
int line)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsline - the line number to skip for start reading
public CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescape - the character to use for escaping a separator or quoteline - the line number to skip for start reading
public CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescape - the character to use for escaping a separator or quoteline - the line number to skip for start readingstrictQuotes - sets if characters outside the quotes are ignored
public CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes,
boolean ignoreLeadingWhiteSpace)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescape - the character to use for escaping a separator or quoteline - the line number to skip for start readingstrictQuotes - sets if characters outside the quotes are ignoredignoreLeadingWhiteSpace - it true, parser should ignore white space before a quote in a field
public CSVReader(Reader reader,
char separator,
char quotechar,
char escape,
int line,
boolean strictQuotes,
boolean ignoreLeadingWhiteSpace,
boolean keepCR)
reader - the reader to an underlying CSV source.separator - the delimiter to use for separating entriesquotechar - the character to use for quoted elementsescape - the character to use for escaping a separator or quoteline - the line number to skip for start readingstrictQuotes - sets if characters outside the quotes are ignoredignoreLeadingWhiteSpace - if true, parser should ignore white space before a quote in a fieldkeepCR - if true the reader will keep carriage returns, otherwise it will discard them.
public CSVReader(Reader reader,
int line,
CSVParser csvParser)
reader - the reader to an underlying CSV source.line - the line number to skip for start readingcsvParser - the parser to use to parse input| Method Detail |
|---|
public CSVParser getParser()
public int getSkipLines()
public boolean keepCarriageReturns()
public List<String[]> readAll()
throws IOException
IOException - if bad things happen during the read
public String[] readNext()
throws IOException
IOException - if bad things happen during the readprotected String[] validateResult(String[] result)
result -
protected String[] combineResultsFromMultipleReads(String[] buffer,
String[] lastRead)
buffer - - previous data read for this recordlastRead - - latest data read for this record.
protected String getNextLine()
throws IOException
IOException - if bad things happen during the read
public void close()
throws IOException
close in interface CloseableIOException - if the close failspublic Iterator<String[]> iterator()
iterator in interface Iterable<String[]>public boolean verifyReader()
public long getLinesRead()
First line in the file
some other descriptive line
a,b,c
a,"b\nb",c
With a CSVReader constructed like so
CSVReader c = builder.withCSVParser(new CSVParser())
.withSkipLines(2)
.build();
The initial call to getLinesRead will be 0.
public long getRecordsRead()
First line in the file
some other descriptive line
a,b,c
a,"b\nb",c
With a CSVReader constructed like so
CSVReader c = builder.withCSVParser(new CSVParser())
.withSkipLines(2)
.build();
The initial call to getRecordsRead will be 0.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||