public class CSVReader extends Object implements Closeable, ICommonsIterable<ICommonsList<String>>
| Constructor and Description |
|---|
CSVReader(Reader aReader)
Constructs CSVReader using a comma for the separator.
|
CSVReader(Reader aReader,
boolean bKeepCR)
Constructs
CSVReader using a comma for the separator. |
CSVReader(Reader aReader,
CSVParser aParser,
boolean bKeepCR)
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the underlying reader.
|
char |
getEscapeChar() |
CSVParser |
getParser() |
char |
getQuoteChar() |
char |
getSeparatorChar() |
int |
getSkipLines()
Returns the number of lines in the csv file to skip before processing.
|
boolean |
isIgnoreLeadingWhiteSpace() |
boolean |
isIgnoreQuotations() |
boolean |
isKeepCarriageReturns()
Returns if the reader will keep carriage returns found in data or remove
them.
|
boolean |
isStrictQuotes() |
boolean |
isVerifyReader()
Returns if the
CSVReader will verify the reader before each read. |
Iterator<ICommonsList<String>> |
iterator()
Creates an Iterator for processing the csv data.
|
ICommonsList<ICommonsList<String>> |
readAll()
Reads the entire file into a list with each element being a list of
String of tokens. |
void |
readAll(Consumer<? super ICommonsList<String>> aLineConsumer)
Reads the entire file line by line and invoke a callback for each line.
|
ICommonsList<String> |
readNext()
Reads the next line from the buffer and converts to a string array.
|
CSVReader |
setEscapeChar(char cEscapeChar)
Sets the character to use for escaping a separator or quote.
|
CSVReader |
setIgnoreLeadingWhiteSpace(boolean bIgnoreLeadingWhiteSpace)
Sets the ignore leading whitespace setting - if true, white space in front
of a quote in a field is ignored.
|
CSVReader |
setIgnoreQuotations(boolean bIgnoreQuotations)
Sets the ignore quotations mode - if
true, quotations are
ignored. |
CSVReader |
setQuoteChar(char cQuoteChar)
Sets the character to use for quoted elements.
|
CSVReader |
setSeparatorChar(char cSeparator)
Sets the delimiter to use for separating entries.
|
CSVReader |
setSkipLines(int nSkipLines)
Sets the line number to skip for start reading.
|
CSVReader |
setStrictQuotes(boolean bStrictQuotes)
Sets the strict quotes setting - if true, characters outside the quotes are
ignored.
|
CSVReader |
setVerifyReader(boolean bVerifyReader)
Checks to see if the CSVReader should verify the reader state before reads
or not.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEach, forEachBreakable, forEachByIndex, getCount, getCountforEach, spliteratorpublic CSVReader(@Nonnull @WillCloseWhenClosed Reader aReader)
aReader - the reader to an underlying CSV source.public CSVReader(@Nonnull @WillCloseWhenClosed Reader aReader, boolean bKeepCR)
CSVReader using a comma for the separator.aReader - the reader to an underlying CSV source.bKeepCR - true to keep carriage returns in data read,
false otherwisepublic CSVReader(@Nonnull @WillCloseWhenClosed Reader aReader, @Nonnull CSVParser aParser, boolean bKeepCR)
aReader - the reader to an underlying CSV source.aParser - the parser to use to parse inputbKeepCR - true to keep carriage returns in data read,
false otherwisepublic char getSeparatorChar()
@Nonnull public CSVReader setSeparatorChar(char cSeparator)
cSeparator - the delimiter to use for separating entriespublic char getQuoteChar()
@Nonnull public CSVReader setQuoteChar(char cQuoteChar)
cQuoteChar - the character to use for quoted element.public char getEscapeChar()
@Nonnull public CSVReader setEscapeChar(char cEscapeChar)
cEscapeChar - the character to use for escaping a separator or quote.public boolean isStrictQuotes()
@Nonnull public CSVReader setStrictQuotes(boolean bStrictQuotes)
bStrictQuotes - if true, characters outside the quotes are ignoredpublic boolean isIgnoreLeadingWhiteSpace()
@Nonnull public CSVReader setIgnoreLeadingWhiteSpace(boolean bIgnoreLeadingWhiteSpace)
bIgnoreLeadingWhiteSpace - if true, white space in front of a quote in a field is
ignoredpublic boolean isIgnoreQuotations()
@Nonnull public CSVReader setIgnoreQuotations(boolean bIgnoreQuotations)
true, quotations are
ignored.bIgnoreQuotations - if true, quotations are ignored@Nonnegative public int getSkipLines()
@Nonnull public CSVReader setSkipLines(@Nonnegative int nSkipLines)
nSkipLines - the line number to skip for start reading.public boolean isKeepCarriageReturns()
public boolean isVerifyReader()
CSVReader will verify the reader before each read.
true if CSVReader will verify the reader before reads.
false otherwise.@Nonnull public CSVReader setVerifyReader(boolean bVerifyReader)
bVerifyReader - true if CSVReader should verify reader before each
read, false otherwise.@Nonnull @ReturnsMutableCopy public ICommonsList<ICommonsList<String>> readAll() throws IOException
String of tokens.String
representing a line of the file.IOException - if bad things happen during the readpublic void readAll(@Nonnull Consumer<? super ICommonsList<String>> aLineConsumer) throws IOException
aLineConsumer - The consumer that is invoked for every line. May not be
null.IOException - if bad things happen during the read@Nullable public ICommonsList<String> readNext() throws IOException
IOException - if bad things happen during the readpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - if the close fails@Nonnull public Iterator<ICommonsList<String>> iterator()
iterator in interface Iterable<ICommonsList<String>>Copyright © 2014–2020 Philip Helger. All rights reserved.