Package com.opencsv
Interface ICSVParser
-
- All Known Implementing Classes:
AbstractCSVParser
,CSVParser
,RFC4180Parser
public interface ICSVParser
This interface defines all of the behaviorCSVReader
needs from a parser to tokenize an input line for further processing.- Since:
- 3.9
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_BUNDLE_NAME
The name of the resource bundle for translations of error messages in opencsv.static char
DEFAULT_ESCAPE_CHARACTER
The default escape character to use if none is supplied to the constructor.static boolean
DEFAULT_IGNORE_LEADING_WHITESPACE
The default leading whitespace behavior to use if none is supplied to the constructor.static boolean
DEFAULT_IGNORE_QUOTATIONS
If the quote character is set to null then there is no quote character.static CSVReaderNullFieldIndicator
DEFAULT_NULL_FIELD_INDICATOR
Denotes what field contents will cause the parser to return null: EMPTY_SEPARATORS, EMPTY_QUOTES, BOTH, NEITHER (default).static char
DEFAULT_QUOTE_CHARACTER
The default quote character to use if none is supplied to the constructor.static char
DEFAULT_SEPARATOR
The default separator to use if none is supplied to the constructor.static boolean
DEFAULT_STRICT_QUOTES
The default strict quote behavior to use if none is supplied to the constructor.static int
INITIAL_READ_SIZE
The average size of a line read by opencsv (used for setting the size of StringBuilders).static int
MAX_SIZE_FOR_EMPTY_FIELD
When creating builders this should be the smallest size to account for quotes and any possible escape characters.static java.lang.String
NEWLINE
Default newline character for the parser.static char
NULL_CHARACTER
This is the "null" character - if a value is set to this then it is ignored.static int
READ_BUFFER_SIZE
In most cases we know the size of the line we want to read.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
getPendingText()
If a parser is in the middle of parsing a multiline field, this will return the text collected so far.char
getQuotechar()
char
getSeparator()
boolean
isPending()
CSVReaderNullFieldIndicator
nullFieldIndicator()
java.lang.String[]
parseLine(java.lang.String nextLine)
Parses an incoming String and returns an array of elements.java.lang.String[]
parseLineMulti(java.lang.String nextLine)
Parses an incoming String and returns an array of elements.java.lang.String
parseToLine(java.lang.String[] values, boolean applyQuotesToAll)
Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string.void
setErrorLocale(java.util.Locale errorLocale)
Sets the locale for all error messages.
-
-
-
Field Detail
-
DEFAULT_SEPARATOR
static final char DEFAULT_SEPARATOR
The default separator to use if none is supplied to the constructor.- See Also:
- Constant Field Values
-
INITIAL_READ_SIZE
static final int INITIAL_READ_SIZE
The average size of a line read by opencsv (used for setting the size of StringBuilders).- See Also:
- Constant Field Values
-
READ_BUFFER_SIZE
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.- See Also:
- Constant Field Values
-
DEFAULT_QUOTE_CHARACTER
static final char DEFAULT_QUOTE_CHARACTER
The default quote character to use if none is supplied to the constructor.- See Also:
- Constant Field Values
-
DEFAULT_ESCAPE_CHARACTER
static final char DEFAULT_ESCAPE_CHARACTER
The default escape character to use if none is supplied to the constructor.- See Also:
- Constant Field Values
-
DEFAULT_STRICT_QUOTES
static final boolean DEFAULT_STRICT_QUOTES
The default strict quote behavior to use if none is supplied to the constructor.- See Also:
- Constant Field Values
-
DEFAULT_IGNORE_LEADING_WHITESPACE
static final boolean DEFAULT_IGNORE_LEADING_WHITESPACE
The default leading whitespace behavior to use if none is supplied to the constructor.- See Also:
- Constant Field Values
-
DEFAULT_IGNORE_QUOTATIONS
static final boolean DEFAULT_IGNORE_QUOTATIONS
If the quote character is set to null then there is no quote character.- See Also:
- Constant Field Values
-
NULL_CHARACTER
static final char NULL_CHARACTER
This is the "null" character - if a value is set to this then it is ignored.- See Also:
- Constant Field Values
-
DEFAULT_NULL_FIELD_INDICATOR
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_BUNDLE_NAME
static final java.lang.String DEFAULT_BUNDLE_NAME
The name of the resource bundle for translations of error messages in opencsv.- See Also:
- Constant Field Values
-
MAX_SIZE_FOR_EMPTY_FIELD
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.- See Also:
- Constant Field Values
-
NEWLINE
static final java.lang.String NEWLINE
Default newline character for the parser.- See Also:
- Constant Field Values
-
-
Method Detail
-
getSeparator
char getSeparator()
- Returns:
- The default separator for this parser.
-
getQuotechar
char getQuotechar()
- Returns:
- The default quotation character for this parser.
-
isPending
boolean isPending()
- Returns:
- True if something was left over from last call(s)
-
parseLineMulti
java.lang.String[] parseLineMulti(java.lang.String nextLine) throws java.io.IOException
Parses an incoming String and returns an array of elements. This method is used when the data spans multiple lines.- Parameters:
nextLine
- Current line to be processed- Returns:
- The comma-tokenized list of elements, or null if nextLine is null
- Throws:
java.io.IOException
- If bad things happen during the read
-
parseLine
java.lang.String[] parseLine(java.lang.String nextLine) throws java.io.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
- Line to be parsed.- Returns:
- The list of elements, or null if nextLine is null
- Throws:
java.io.IOException
- If bad things happen during the read
-
parseToLine
java.lang.String parseToLine(java.lang.String[] values, boolean applyQuotesToAll)
Essentially a "Reverse parse" where an array of values are concatenating to a csv delimited string. NOTE: as of the 4.1 release this functionality is not considered production ready and has not been fully tested (and the ability to add a parser to the CSVWriter has not been implemented yet. I am adding this now because because I need to do the 4.1 release because of the number of defect fixes and I do not want to strip this out.- Parameters:
values
- List of elements to parse.applyQuotesToAll
- - 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:
- CSV formatted string representing the values in the array.
- Since:
- 4.1
-
nullFieldIndicator
CSVReaderNullFieldIndicator nullFieldIndicator()
- Returns:
- The null field indicator.
-
getPendingText
java.lang.String getPendingText()
If a parser is in the middle of parsing a multiline field, this will return the text collected so far.- Returns:
- The incomplete text for a multiline field. If there is no pending text, this returns an empty string.
- Since:
- 4.1
-
setErrorLocale
void setErrorLocale(java.util.Locale errorLocale)
Sets the locale for all error messages.- Parameters:
errorLocale
- Locale for error messages. If null, the default locale is used.- Since:
- 4.2
-
-