Top Description Fields Methods
com.opencsv

public Interface ICSVParser

Known Direct Implementers
com.opencsv.AbstractCSVParser
Imports
com.opencsv.enums.CSVReaderNullFieldIndicator, java.io.IOException, java.util.Locale

This interface defines all of the behavior com.opencsv.CSVReader needs from a parser to tokenize an input line for further processing.
Since
3.9

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_BUNDLE_NAME

The name of the resource bundle for translations of error messages in opencsv.

public static final char
DEFAULT_ESCAPE_CHARACTER

The default escape character to use if none is supplied to the constructor.

public static final boolean
DEFAULT_IGNORE_LEADING_WHITESPACE

The default leading whitespace behavior to use if none is supplied to the constructor.

public static final boolean
DEFAULT_IGNORE_QUOTATIONS

If the quote character is set to null then there is no quote character.

public static final CSVReaderNullFieldIndicator
DEFAULT_NULL_FIELD_INDICATOR

Denotes what field contents will cause the parser to return null: EMPTY_SEPARATORS, EMPTY_QUOTES, BOTH, NEITHER (default).

public static final char
DEFAULT_QUOTE_CHARACTER

The default quote character to use if none is supplied to the constructor.

public static final char
DEFAULT_SEPARATOR

The default separator to use if none is supplied to the constructor.

public static final boolean
DEFAULT_STRICT_QUOTES

The default strict quote behavior to use if none is supplied to the constructor.

public static final int
INITIAL_READ_SIZE

The average size of a line read by opencsv (used for setting the size of StringBuilders).

public static final int
MAX_SIZE_FOR_EMPTY_FIELD

When creating builders this should be the smallest size to account for quotes and any possible escape characters.

public static final String
NEWLINE

Default newline character for the parser.

public static final char
NULL_CHARACTER

This is the "null" character - if a value is set to this then it is ignored.

public static final int
READ_BUFFER_SIZE

In most cases we know the size of the line we want to read.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The incomplete text for a multiline field. If there is no pending text, this returns an empty string.
getPendingText
()

If a parser is in the middle of parsing a multiline field, this will return the text collected so far.

public char
getQuotechar()

Returns: The default quotation character for this parser.

public char
getSeparator()

Returns: The default separator for this parser.

public boolean
isPending()

Returns: True if something was left over from last call(s)

public CSVReaderNullFieldIndicator
nullFieldIndicator()

Returns: The null field indicator.

public String[]

Returns:

The list of elements, or null if nextLine is null
parseLine
(String
Line to be parsed.
nextLine
)

Parses an incoming String and returns an array of elements.

public String[]

Returns:

The comma-tokenized list of elements, or null if nextLine is null
parseLineMulti
(String
Current line to be processed
nextLine
)

Parses an incoming String and returns an array of elements.

public String

Returns:

CSV formatted string representing the values in the array.
parseToLine
(String[]
List of elements to parse.
values
,
boolean
- If true all strings in the array will have quotes if it needs it or not. If false then it will only have quotes if it needs it (i.e. contains a quote character).
applyQuotesToAll
)

Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string.

public void
parseToLine(String[]
List of elements to parse.
values
,
boolean
- If true all strings in the array will have quotes if it needs it or not. If false then it will only have quotes if it needs it (i.e. contains a quote character).
applyQuotesToAll
,
Appendable
The Appendable that the parsed values will be appended to
appendable
)

Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string.

public void
setErrorLocale(Locale
Locale for error messages. If null, the default locale is used.
errorLocale
)

Sets the locale for all error messages.

Field Detail

DEFAULT_BUNDLE_NAMEback to summary
public static final String DEFAULT_BUNDLE_NAME

The name of the resource bundle for translations of error messages in opencsv.

DEFAULT_ESCAPE_CHARACTERback to summary
public static final char DEFAULT_ESCAPE_CHARACTER

The default escape character to use if none is supplied to the constructor.

DEFAULT_IGNORE_LEADING_WHITESPACEback to summary
public static final boolean DEFAULT_IGNORE_LEADING_WHITESPACE

The default leading whitespace behavior to use if none is supplied to the constructor.

DEFAULT_IGNORE_QUOTATIONSback to summary
public static final boolean DEFAULT_IGNORE_QUOTATIONS

If the quote character is set to null then there is no quote character.

DEFAULT_NULL_FIELD_INDICATORback to summary
public static final CSVReaderNullFieldIndicator DEFAULT_NULL_FIELD_INDICATOR

Denotes what field contents will cause the parser to return null: EMPTY_SEPARATORS, EMPTY_QUOTES, BOTH, NEITHER (default).

DEFAULT_QUOTE_CHARACTERback to summary
public static final char DEFAULT_QUOTE_CHARACTER

The default quote character to use if none is supplied to the constructor.

DEFAULT_SEPARATORback to summary
public static final char DEFAULT_SEPARATOR

The default separator to use if none is supplied to the constructor.

DEFAULT_STRICT_QUOTESback to summary
public static final boolean DEFAULT_STRICT_QUOTES

The default strict quote behavior to use if none is supplied to the constructor.

INITIAL_READ_SIZEback to summary
public static final int INITIAL_READ_SIZE

The average size of a line read by opencsv (used for setting the size of StringBuilders).

MAX_SIZE_FOR_EMPTY_FIELDback to summary
public static final int MAX_SIZE_FOR_EMPTY_FIELD

When creating builders this should be the smallest size to account for quotes and any possible escape characters.

NEWLINEback to summary
public static final String NEWLINE

Default newline character for the parser.

NULL_CHARACTERback to summary
public static final char NULL_CHARACTER

This is the "null" character - if a value is set to this then it is ignored.

READ_BUFFER_SIZEback to summary
public static final int READ_BUFFER_SIZE

In most cases we know the size of the line we want to read. In that case we will set the initial read to that plus an buffer size.

Method Detail

getPendingTextback to summary
public String getPendingText()

If a parser is in the middle of parsing a multiline field, this will return the text collected so far.

Returns:String

The incomplete text for a multiline field. If there is no pending text, this returns an empty string.

Since
4.1
getQuotecharback to summary
public char getQuotechar()
Returns:char

The default quotation character for this parser.

getSeparatorback to summary
public char getSeparator()
Returns:char

The default separator for this parser.

isPendingback to summary
public boolean isPending()
Returns:boolean

True if something was left over from last call(s)

nullFieldIndicatorback to summary
public CSVReaderNullFieldIndicator nullFieldIndicator()
Returns:CSVReaderNullFieldIndicator

The null field indicator.

parseLineback to summary
public String[] parseLine(String nextLine) throws IOException

Parses an incoming String and returns an array of elements. This method is used when all data is contained in a single line.

Parameters
nextLine:String

Line to be parsed.

Returns:String[]

The list of elements, or null if nextLine is null

Exceptions
IOException:
If bad things happen during the read
parseLineMultiback to summary
public String[] parseLineMulti(String nextLine) throws IOException

Parses an incoming String and returns an array of elements. This method is used when the data spans multiple lines.

Parameters
nextLine:String

Current line to be processed

Returns:String[]

The comma-tokenized list of elements, or null if nextLine is null

Exceptions
IOException:
If bad things happen during the read
parseToLineback to summary
public String parseToLine(String[] values, boolean applyQuotesToAll)

Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string.

Parameters
values:String[]

List of elements to parse.

applyQuotesToAll:boolean

- If true all strings in the array will have quotes if it needs it or not. If false then it will only have quotes if it needs it (i.e. contains a quote character).

Returns:String

CSV formatted string representing the values in the array.

Since
4.1
parseToLineback to summary
public void parseToLine(String[] values, boolean applyQuotesToAll, Appendable appendable) throws IOException

Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string.

Note

This functionality is for testing only in the 5.7.2 release in an effort to optimize the number of strings created when parsing large files.

Parameters
values:String[]

List of elements to parse.

applyQuotesToAll:boolean

- If true all strings in the array will have quotes if it needs it or not. If false then it will only have quotes if it needs it (i.e. contains a quote character).

appendable:Appendable

The Appendable that the parsed values will be appended to

Since
5.7.2
setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Sets the locale for all error messages.

Parameters
errorLocale:Locale

Locale for error messages. If null, the default locale is used.

Since
4.2