Top Description Inners Fields Constructors Methods
org.apache.commons.csv

public final Class CSVParser

extends Object
implements Iterable<CSVRecord>, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable
Static Imports
org.apache.commons.csv.Token.Type.TOKEN

Parses CSV files according to the specified format. Because CSV appears in many different dialects, the parser supports many formats by allowing the specification of a CSVFormat. The parser works record-wise. It is not possible to go back, once a record has been parsed from the input stream.

Creating instances

There are several static factory methods that can be used to create instances for various types of resources:

Alternatively parsers can also be created by passing a Reader directly to the sole constructor. For those who like fluent APIs, parsers can be created using CSVFormat#parse(java.io.Reader) as a shortcut:

for (CSVRecord record : CSVFormat.EXCEL.parse(in)) {
    ...
}

Parsing record wise

To parse a CSV input from a file, you write:

File csvData = new File("/path/to/csv");
CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180);
for (CSVRecord csvRecord : parser) {
    ...
}

This will read the parse the contents of the file using the RFC 4180 format.

To parse CSV input in a format like Excel, you write:

CSVParser parser = CSVParser.parse(csvData, CSVFormat.EXCEL);
for (CSVRecord csvRecord : parser) {
    ...
}

If the predefined formats don't match the format at hand, custom formats can be defined. More information about customizing CSVFormats is available in CSVFormat Javadoc.

Parsing into memory

If parsing record-wise is not desired, the contents of the input can be read completely into memory.

Reader in = new StringReader("a;b\nc;d");
CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
List<CSVRecord> list = parser.getRecords();

There are two constraints that have to be kept in mind:

  1. Parsing into memory starts at the current position of the parser. If you have already parsed records from the input, those records will not end up in the in-memory representation of your CSV data.
  2. Parsing into memory may consume a lot of system resources depending on the input. For example, if you're parsing a 150MB file of CSV data the contents will be read completely into memory.

Notes

The internal parser state is completely covered by the format and the reader state.

See Also
package documentation for more details

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
pack-priv class
private static class
CSVParser.Headers

Header information based on name and position.

Field Summary

Modifier and TypeField and Description
private final long
characterOffset

Lexer offset when the parser does not start parsing at the beginning of the source.

private final CSVParser.CSVRecordIterator
private final CSVFormat
private String
private final CSVParser.Headers
private final Lexer
private final List<String>
recordList

A record buffer for getRecord().

private long
recordNumber

The next record number to assign.

private final Token
private String

Constructor Summary

AccessConstructor and Description
public
CSVParser(final Reader
a Reader containing CSV-formatted input. Must not be null.
reader
,
final CSVFormat
the CSVFormat used for CSV parsing. Must not be null.
format
)
Deprecated Will be removed in the next major version, use Builder#get().

Constructs a new instance using the given CSVFormat.

public
CSVParser(final Reader
a Reader containing CSV-formatted input. Must not be null.
reader
,
final CSVFormat
the CSVFormat used for CSV parsing. Must not be null.
format
,
final long
Lexer offset when the parser does not start parsing at the beginning of the source.
characterOffset
,
final long
The next record number to assign.
recordNumber
)
Deprecated Will be removed in the next major version, use Builder#get().

Constructs a new instance using the given CSVFormat.

private
CSVParser(final Reader
a Reader containing CSV-formatted input. Must not be null.
reader
,
final CSVFormat
the CSVFormat used for CSV parsing. Must not be null.
format
,
final long
Lexer offset when the parser does not start parsing at the beginning of the source.
characterOffset
,
final long
The next record number to assign.
recordNumber
,
final Charset
The character encoding to be used for the reader when enableByteTracking is true.
charset
,
final boolean
true to enable byte tracking for the parser; false to disable it.
trackBytes
)

Constructs a new instance using the given CSVFormat.

Method Summary

Modifier and TypeMethod and Description
private void
addRecordValue(final boolean lastRecord)

public static CSVParser.Builder

Returns:

a new builder.
builder
()

Creates a new builder.

public void
close()

Implements java.io.Closeable.close.

Closes resources.

private Map<String, Integer>
private CSVParser.Headers

Returns:

null if the format has no header.
createHeaders
()

Creates the name to index mapping if the format defines a header.

public long

Returns:

current line number.
getCurrentLineNumber
()

Gets the current line number in the input stream.

public String

Returns:

the first end-of-line string.
getFirstEndOfLine
()

Gets the first end-of-line string encountered.

public String

Returns:

the header comment for this stream, or null if no comment is available.
getHeaderComment
()

Gets the header comment, if any.

public Map<String, Integer>

Returns:

a copy of the header map.
getHeaderMap
()

Gets a copy of the header map as defined in the CSVFormat's header.

pack-priv Map<String, Integer>

Returns:

the underlying header map.
getHeaderMapRaw
()

Gets the underlying header map.

public List<String>

Returns:

read-only list of header names that iterates in column order.
getHeaderNames
()

Gets a read-only list of header names that iterates in column order as defined in the CSVFormat's header.

public long

Returns:

current record number
getRecordNumber
()

Gets the current record number in the input stream.

public List<CSVRecord>

Returns:

list of CSVRecords, may be empty
getRecords
()

Parses the CSV input according to the given format and returns the content as a list of CSVRecords.

public String

Returns:

the trailer comment for this stream, or null if no comment is available.
getTrailerComment
()

Gets the trailer comment, if any.

private String

Returns:

null if input is parsed as null, or input itself if the input isn't parsed as null
handleNull
(final String
the cell data to further processed
input
)

Handles whether the input is parsed as null

public boolean

Returns:

true if this parser has seen a header comment, false otherwise
hasHeaderComment
()

Checks whether there is a header comment.

public boolean

Returns:

true if this parser has seen a trailer comment, false otherwise
hasTrailerComment
()

Checks whether there is a trailer comment.

public boolean

Returns:

whether this parser is closed.
isClosed
()

Tests whether this parser is closed.

private boolean
public Iterator<CSVRecord>
iterator()

Implements java.lang.Iterable.iterator.

Returns the record iterator.

pack-priv CSVRecord

Returns:

the record as an array of values, or null if the end of the stream has been reached.
nextRecord
()

Parses the next record from the current point in the stream.

public static CSVParser

Returns:

a new parser
parse
(final File
a CSV file. Must not be null.
file
,
final Charset
The Charset to decode the given file, null maps to the default Charset.
charset
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates a parser for the given File.

public static CSVParser

Returns:

a new CSVParser configured with the given reader and format.
parse
(final InputStream
an InputStream containing CSV-formatted input, null maps to CSVFormat#DEFAULT.
inputStream
,
final Charset
The Charset to decode the given file, null maps to the default Charset.
charset
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates a CSV parser using the given CSVFormat.

public static CSVParser

Returns:

a new parser
parse
(final Path
a CSV file. Must not be null.
path
,
final Charset
The Charset to decode the given file, null maps to the default Charset.
charset
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates and returns a parser for the given Path, which the caller MUST close.

public static CSVParser

Returns:

a new CSVParser configured with the given reader and format.
parse
(final Reader
a Reader containing CSV-formatted input. Must not be null.
reader
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates a CSV parser using the given CSVFormat

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

public static CSVParser

Returns:

a new parser
parse
(final String
a CSV string. Must not be null.
string
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates a parser for the given String.

public static CSVParser

Returns:

a new parser
parse
(final URL
a URL. Must not be null.
url
,
final Charset
the charset for the resource, null maps to the default Charset.
charset
,
final CSVFormat
the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.
format
)

Creates and returns a parser for the given URL, which the caller MUST close.

public Stream<CSVRecord>

Returns:

a sequential Stream with this collection as its source.
stream
()

Returns a sequential Stream with this collection as its source.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

characterOffsetback to summary
private final long characterOffset

Lexer offset when the parser does not start parsing at the beginning of the source. Usually used in combination with recordNumber.

csvRecordIteratorback to summary
private final CSVParser.CSVRecordIterator csvRecordIterator
formatback to summary
private final CSVFormat format
headerCommentback to summary
private String headerComment
headersback to summary
private final CSVParser.Headers headers
lexerback to summary
private final Lexer lexer
recordListback to summary
private final List<String> recordList

A record buffer for getRecord(). Grows as necessary and is reused.

recordNumberback to summary
private long recordNumber

The next record number to assign.

reusableTokenback to summary
private final Token reusableToken
trailerCommentback to summary
private String trailerComment

Constructor Detail

CSVParserback to summary
public CSVParser(final Reader reader, final CSVFormat format) throws IOException

Deprecated

Will be removed in the next major version, use Builder#get().

Constructs a new instance using the given CSVFormat.

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

Parameters
reader:Reader

a Reader containing CSV-formatted input. Must not be null.

format:CSVFormat

the CSVFormat used for CSV parsing. Must not be null.

Annotations
@Deprecated
Exceptions
IOException:
If there is a problem reading the header or skipping the first record
IllegalArgumentException:
If the parameters of the format are inconsistent or if either reader or format are null.
CSVException:
Thrown on invalid CSV input data.
CSVParserback to summary
public CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber) throws IOException

Deprecated

Will be removed in the next major version, use Builder#get().

Constructs a new instance using the given CSVFormat.

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

Parameters
reader:Reader

a Reader containing CSV-formatted input. Must not be null.

format:CSVFormat

the CSVFormat used for CSV parsing. Must not be null.

characterOffset:long

Lexer offset when the parser does not start parsing at the beginning of the source.

recordNumber:long

The next record number to assign.

Annotations
@Deprecated
Exceptions
IOException:
if there is a problem reading the header or skipping the first record
IllegalArgumentException:
If the parameters of the format are inconsistent or if either the reader or format is null.
CSVException:
on invalid input.
Since
1.1
CSVParserback to summary
private CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber, final Charset charset, final boolean trackBytes) throws IOException

Constructs a new instance using the given CSVFormat.

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

Parameters
reader:Reader

a Reader containing CSV-formatted input. Must not be null.

format:CSVFormat

the CSVFormat used for CSV parsing. Must not be null.

characterOffset:long

Lexer offset when the parser does not start parsing at the beginning of the source.

recordNumber:long

The next record number to assign.

charset:Charset

The character encoding to be used for the reader when enableByteTracking is true.

trackBytes:boolean

true to enable byte tracking for the parser; false to disable it.

Exceptions
IOException:
If there is a problem reading the header or skipping the first record.
IllegalArgumentException:
If the parameters of the format are inconsistent or if either the reader or format is null.
CSVException:
Thrown on invalid CSV input data.

Method Detail

addRecordValueback to summary
private void addRecordValue(final boolean lastRecord)
builderback to summary
public static CSVParser.Builder builder()

Creates a new builder.

Returns:CSVParser.Builder

a new builder.

Since
1.13.0
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes resources.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
createEmptyHeaderMapback to summary
private Map<String, Integer> createEmptyHeaderMap()
createHeadersback to summary
private CSVParser.Headers createHeaders() throws IOException

Creates the name to index mapping if the format defines a header.

Returns:CSVParser.Headers

null if the format has no header.

Exceptions
IOException:
if there is a problem reading the header or skipping the first record
CSVException:
on invalid input.
getCurrentLineNumberback to summary
public long getCurrentLineNumber()

Gets the current line number in the input stream.

Note

If your CSV input has multi-line values, the returned number does not correspond to the record number.

Returns:long

current line number.

getFirstEndOfLineback to summary
public String getFirstEndOfLine()

Gets the first end-of-line string encountered.

Returns:String

the first end-of-line string.

Since
1.5
getHeaderCommentback to summary
public String getHeaderComment()

Gets the header comment, if any. The header comment appears before the header record.

Returns:String

the header comment for this stream, or null if no comment is available.

Since
1.10.0
getHeaderMapback to summary
public Map<String, Integer> getHeaderMap()

Gets a copy of the header map as defined in the CSVFormat's header.

The map keys are column names. The map values are 0-based indices.

Note

The map can only provide a one-to-one mapping when the format did not contain null or duplicate column names.

Returns:Map<String, Integer>

a copy of the header map.

getHeaderMapRawback to summary
pack-priv Map<String, Integer> getHeaderMapRaw()

Gets the underlying header map.

Returns:Map<String, Integer>

the underlying header map.

getHeaderNamesback to summary
public List<String> getHeaderNames()

Gets a read-only list of header names that iterates in column order as defined in the CSVFormat's header.

Note

The list provides strings that can be used as keys in the header map. The list will not contain null column names if they were present in the input format.

Returns:List<String>

read-only list of header names that iterates in column order.

Since
1.7
See Also
getHeaderMap()
getRecordNumberback to summary
public long getRecordNumber()

Gets the current record number in the input stream.

Note

If your CSV input has multi-line values, the returned number does not correspond to the line number.

Returns:long

current record number

getRecordsback to summary
public List<CSVRecord> getRecords()

Parses the CSV input according to the given format and returns the content as a list of CSVRecords.

The returned content starts at the current parse-position in the stream.

You can use CSVFormat.Builder#setMaxRows(long) to limit how many rows this method produces.

Returns:List<CSVRecord>

list of CSVRecords, may be empty

Exceptions
UncheckedIOException:
on parse error or input read-failure
getTrailerCommentback to summary
public String getTrailerComment()

Gets the trailer comment, if any. Trailer comments are located between the last record and EOF

Returns:String

the trailer comment for this stream, or null if no comment is available.

Since
1.10.0
handleNullback to summary
private String handleNull(final String input)

Handles whether the input is parsed as null

Parameters
input:String

the cell data to further processed

Returns:String

null if input is parsed as null, or input itself if the input isn't parsed as null

hasHeaderCommentback to summary
public boolean hasHeaderComment()

Checks whether there is a header comment. The header comment appears before the header record. Note that if the parser's format has been given an explicit header (with CSVFormat.Builder#setHeader(String...) or another overload) and the header record is not being skipped (CSVFormat.Builder#setSkipHeaderRecord is false) then any initial comments will be associated with the first record, not the header.

Returns:boolean

true if this parser has seen a header comment, false otherwise

Since
1.10.0
hasTrailerCommentback to summary
public boolean hasTrailerComment()

Checks whether there is a trailer comment. Trailer comments are located between the last record and EOF. The trailer comments will only be available after the parser has finished processing this stream.

Returns:boolean

true if this parser has seen a trailer comment, false otherwise

Since
1.10.0
isClosedback to summary
public boolean isClosed()

Tests whether this parser is closed.

Returns:boolean

whether this parser is closed.

isStrictQuoteModeback to summary
private boolean isStrictQuoteMode()

Tests whether the format's QuoteMode is QuoteMode#ALL_NON_NULL or QuoteMode#NON_NUMERIC.

Returns:boolean

true if the format's QuoteMode is QuoteMode#ALL_NON_NULL or QuoteMode#NON_NUMERIC.

iteratorback to summary
public Iterator<CSVRecord> iterator()

Implements java.lang.Iterable.iterator.

Returns the record iterator.

An IOException caught during the iteration is re-thrown as an IllegalStateException.

If the parser is closed, the iterator will not yield any more records. A call to Iterator#hasNext() will return false and a call to Iterator#next() will throw a NoSuchElementException.

If it is necessary to construct an iterator which is usable after the parser is closed, one option is to extract all records as a list with getRecords(), and return an iterator to that list.

You can use CSVFormat.Builder#setMaxRows(long) to limit how many rows an Iterator produces.

Returns:Iterator<CSVRecord>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
nextRecordback to summary
pack-priv CSVRecord nextRecord() throws IOException

Parses the next record from the current point in the stream.

Returns:CSVRecord

the record as an array of values, or null if the end of the stream has been reached.

Exceptions
IOException:
on parse error or input read-failure.
CSVException:
on invalid CSV input data.
parseback to summary
public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException

Creates a parser for the given File.

Parameters
file:File

a CSV file. Must not be null.

charset:Charset

The Charset to decode the given file, null maps to the default Charset.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new parser

Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the parameters of the format are inconsistent.
CSVException:
Thrown on invalid CSV input data.
NullPointerException:
if file is null.
parseback to summary
public static CSVParser parse(final InputStream inputStream, final Charset charset, final CSVFormat format) throws IOException

Creates a CSV parser using the given CSVFormat.

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

Parameters
inputStream:InputStream

an InputStream containing CSV-formatted input, null maps to CSVFormat#DEFAULT.

charset:Charset

The Charset to decode the given file, null maps to the default Charset.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new CSVParser configured with the given reader and format.

Exceptions
IOException:
If there is a problem reading the header or skipping the first record
IllegalArgumentException:
If the parameters of the format are inconsistent or if either reader or format are null.
CSVException:
Thrown on invalid CSV input data.
Since
1.5
parseback to summary
public static CSVParser parse(final Path path, final Charset charset, final CSVFormat format) throws IOException

Creates and returns a parser for the given Path, which the caller MUST close.

Parameters
path:Path

a CSV file. Must not be null.

charset:Charset

The Charset to decode the given file, null maps to the default Charset.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new parser

Annotations
@SuppressWarnings:resource
Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the parameters of the format are inconsistent.
CSVException:
Thrown on invalid CSV input data.
NullPointerException:
if path is null.
Since
1.5
parseback to summary
public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException

Creates a CSV parser using the given CSVFormat

If you do not read all records from the given reader, you should call close() on the parser, unless you close the reader.

Parameters
reader:Reader

a Reader containing CSV-formatted input. Must not be null.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new CSVParser configured with the given reader and format.

Exceptions
IOException:
If there is a problem reading the header or skipping the first record
IllegalArgumentException:
If the parameters of the format are inconsistent or if either reader or format are null.
CSVException:
Thrown on invalid CSV input data.
Since
1.5
parseback to summary
public static CSVParser parse(final String string, final CSVFormat format) throws IOException

Creates a parser for the given String.

Parameters
string:String

a CSV string. Must not be null.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new parser

Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the parameters of the format are inconsistent.
CSVException:
Thrown on invalid CSV input data.
NullPointerException:
if string is null.
parseback to summary
public static CSVParser parse(final URL url, final Charset charset, final CSVFormat format) throws IOException

Creates and returns a parser for the given URL, which the caller MUST close.

If you do not read all records from the given url, you should call close() on the parser, unless you close the url.

Parameters
url:URL

a URL. Must not be null.

charset:Charset

the charset for the resource, null maps to the default Charset.

format:CSVFormat

the CSVFormat used for CSV parsing, null maps to CSVFormat#DEFAULT.

Returns:CSVParser

a new parser

Annotations
@SuppressWarnings:resource
Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the parameters of the format are inconsistent.
CSVException:
Thrown on invalid CSV input data.
NullPointerException:
if url is null.
streamback to summary
public Stream<CSVRecord> stream()

Returns a sequential Stream with this collection as its source.

If the parser is closed, the stream will not produce any more values. See the comments in iterator().

You can use CSVFormat.Builder#setMaxRows(long) to limit how many rows a Stream produces.

Returns:Stream<CSVRecord>

a sequential Stream with this collection as its source.

Since
1.9.0
org.apache.commons.csv back to summary

public Class CSVParser.Builder

extends AbstractStreamBuilder<CSVParser, CSVParser.Builder>
Class Inheritance

Builds a new CSVParser.
Since
1.13.0

Field Summary

Modifier and TypeField and Description
private long
private CSVFormat
private long
private boolean

Constructor Summary

AccessConstructor and Description
protected
Builder()

Constructs a new instance.

Method Summary

Modifier and TypeMethod and Description
public CSVParser
public CSVParser.Builder

Returns:

this instance.
setCharacterOffset
(final long
the lexer offset.
characterOffset
)

Sets the lexer offset when the parser does not start parsing at the beginning of the source.

public CSVParser.Builder

Returns:

this instance.
setFormat
(final CSVFormat
the CSV format, null resets to CSVFormat#DEFAULT.
format
)

Sets the CSV format.

public CSVParser.Builder

Returns:

this instance.
setRecordNumber
(final long
the next record number to assign.
recordNumber
)

Sets the next record number to assign, defaults to 1.

public CSVParser.Builder

Returns:

this instance.
setTrackBytes
(final boolean
true to enable byte tracking; false to disable it.
trackBytes
)

Sets whether to enable byte tracking for the parser.

Inherited from org.apache.commons.io.build.AbstractStreamBuilder:
getBufferSizegetBufferSizeDefaultgetCharSequencegetCharsetgetCharsetDefaultgetFilegetInputStreamgetOpenOptionsgetOutputStreamgetPathgetRandomAccessFilegetReadergetWritersetBufferSizesetBufferSizesetBufferSizeCheckersetBufferSizeDefaultsetBufferSizeMaxsetCharsetsetCharsetsetCharsetDefaultsetOpenOptions

Field Detail

characterOffsetback to summary
private long characterOffset
formatback to summary
private CSVFormat format
recordNumberback to summary
private long recordNumber
trackBytesback to summary
private boolean trackBytes

Constructor Detail

Builderback to summary
protected Builder()

Constructs a new instance.

Method Detail

getback to summary
public CSVParser get() throws IOException

Implements org.apache.commons.io.function.IOSupplier.get.

Doc from org.apache.commons.io.function.IOSupplier.get.

Gets a result.

Returns:CSVParser

a result.

Annotations
@SuppressWarnings:resource
@Override
Exceptions
IOException:
if an I/O error occurs.
setCharacterOffsetback to summary
public CSVParser.Builder setCharacterOffset(final long characterOffset)

Sets the lexer offset when the parser does not start parsing at the beginning of the source.

Parameters
characterOffset:long

the lexer offset.

Returns:CSVParser.Builder

this instance.

setFormatback to summary
public CSVParser.Builder setFormat(final CSVFormat format)

Sets the CSV format. A copy of the given format is kept.

Parameters
format:CSVFormat

the CSV format, null resets to CSVFormat#DEFAULT.

Returns:CSVParser.Builder

this instance.

setRecordNumberback to summary
public CSVParser.Builder setRecordNumber(final long recordNumber)

Sets the next record number to assign, defaults to 1.

Parameters
recordNumber:long

the next record number to assign.

Returns:CSVParser.Builder

this instance.

setTrackBytesback to summary
public CSVParser.Builder setTrackBytes(final boolean trackBytes)

Sets whether to enable byte tracking for the parser.

Parameters
trackBytes:boolean

true to enable byte tracking; false to disable it.

Returns:CSVParser.Builder

this instance.

Since
1.13.0
org.apache.commons.csv back to summary

pack-priv final Class CSVParser.CSVRecordIterator

extends Object
implements Iterator<CSVRecord>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private CSVRecord

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private CSVRecord

Returns:

the next record, or null if the end of the stream has been reached.
getNextRecord
()

Gets the next record or null at the end of stream or max rows read.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public CSVRecord
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

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

currentback to summary
private CSVRecord current

Constructor Detail

CSVRecordIteratorback to summary
pack-priv CSVRecordIterator()

Method Detail

getNextRecordback to summary
private CSVRecord getNextRecord()

Gets the next record or null at the end of stream or max rows read.

Returns:CSVRecord

the next record, or null if the end of the stream has been reached.

Exceptions
IOException:
on parse error or input read-failure
CSVException:
on invalid input.
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 CSVRecord next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:CSVRecord

the next element in the iteration

Annotations
@Override
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
org.apache.commons.csv back to summary

private final Class CSVParser.Headers

extends Object
Class Inheritance

Header information based on name and position.

Field Summary

Modifier and TypeField and Description
pack-priv final Map<String, Integer>
headerMap

Header column positions (0-based)

pack-priv final List<String>
headerNames

Header names in column order

Constructor Summary

AccessConstructor and Description
pack-priv
Headers(final Map<String, Integer> headerMap, final List<String> headerNames)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headerMapback to summary
pack-priv final Map<String, Integer> headerMap

Header column positions (0-based)

headerNamesback to summary
pack-priv final List<String> headerNames

Header names in column order

Constructor Detail

Headersback to summary
pack-priv Headers(final Map<String, Integer> headerMap, final List<String> headerNames)