Package com.opencsv
Class CSVParser
- java.lang.Object
-
- com.opencsv.AbstractCSVParser
-
- com.opencsv.CSVParser
-
- All Implemented Interfaces:
ICSVParser
public class CSVParser extends AbstractCSVParser
A very simple CSV parser released under a commercial-friendly license. This just implements splitting a single line into fields. The purpose of the CSVParser is to take a single string and parse it into its elements based on the delimiter, quote and escape characters. The CSVParser has grown organically based on user requests and does not truly match any current requirements (though it can be configured to match or come close). There is no plans to change this as it will break existing requirements. Consider using the RFC4180Parser for less configurability but closer match to the RFC4180 requirements.- Author:
- Glen Smith, Rainer Pruy
-
-
Field Summary
-
Fields inherited from class com.opencsv.AbstractCSVParser
nullFieldIndicator, pending, quotechar, separator
-
Fields inherited from interface com.opencsv.ICSVParser
DEFAULT_BUNDLE_NAME, DEFAULT_ESCAPE_CHARACTER, DEFAULT_IGNORE_LEADING_WHITESPACE, DEFAULT_IGNORE_QUOTATIONS, DEFAULT_NULL_FIELD_INDICATOR, DEFAULT_QUOTE_CHARACTER, DEFAULT_SEPARATOR, DEFAULT_STRICT_QUOTES, INITIAL_READ_SIZE, MAX_SIZE_FOR_EMPTY_FIELD, NEWLINE, NULL_CHARACTER, READ_BUFFER_SIZE
-
-
Constructor Summary
Constructors Constructor Description CSVParser()
Constructs CSVParser using default values for everything.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
convertToCsvValue(java.lang.String value, boolean applyQuotestoAll)
Used when reverse parsing an array of strings to a single string.char
getEscape()
boolean
isIgnoreLeadingWhiteSpace()
boolean
isIgnoreQuotations()
protected boolean
isNextCharacterEscapable(java.lang.String nextLine, boolean inQuotes, int i)
Checks to see if the character after the current index in a String is an escapable character.boolean
isStrictQuotes()
protected java.lang.String[]
parseLine(java.lang.String nextLine, boolean multi)
Parses an incomingString
and returns an array of elements.void
setErrorLocale(java.util.Locale errorLocale)
Sets the locale for all error messages.-
Methods inherited from class com.opencsv.AbstractCSVParser
getPendingText, getQuotechar, getSeparator, isPending, isSurroundWithQuotes, nullFieldIndicator, parseLine, parseLineMulti, parseToLine
-
-
-
-
Method Detail
-
getEscape
public char getEscape()
- Returns:
- The default escape character for this parser.
-
isStrictQuotes
public boolean isStrictQuotes()
- Returns:
- The default strictQuotes setting for this parser.
-
isIgnoreLeadingWhiteSpace
public boolean isIgnoreLeadingWhiteSpace()
- Returns:
- The default ignoreLeadingWhiteSpace setting for this parser.
-
isIgnoreQuotations
public boolean isIgnoreQuotations()
- Returns:
- The default ignoreQuotation setting for this parser.
-
convertToCsvValue
protected java.lang.String convertToCsvValue(java.lang.String value, boolean applyQuotestoAll)
Description copied from class:AbstractCSVParser
Used when reverse parsing an array of strings to a single string. Handles the application of quotes around the string and handling any quotes within the string.- Specified by:
convertToCsvValue
in classAbstractCSVParser
- Parameters:
value
- String to be testedapplyQuotestoAll
- All values should be surrounded with quotes- Returns:
- String that will go into the CSV string
-
parseLine
protected java.lang.String[] parseLine(java.lang.String nextLine, boolean multi) throws java.io.IOException
Description copied from class:AbstractCSVParser
Parses an incomingString
and returns an array of elements.- Specified by:
parseLine
in classAbstractCSVParser
- Parameters:
nextLine
- The string to parsemulti
- Whether it takes multiple lines to form a single record- Returns:
- The list of elements, or
null
ifnextLine
isnull
- Throws:
java.io.IOException
- If bad things happen during the read
-
isNextCharacterEscapable
protected boolean isNextCharacterEscapable(java.lang.String nextLine, boolean inQuotes, int i)
Checks to see if the character after the current index in a String is an escapable character. Meaning the next character is either a quotation character or the escape char and you are inside quotes. Precondition: the current character is an escape.- Parameters:
nextLine
- The current lineinQuotes
- True if the current context is quotedi
- Current index in line- Returns:
- True if the following character is a quote
-
setErrorLocale
public void setErrorLocale(java.util.Locale errorLocale)
Description copied from interface:ICSVParser
Sets the locale for all error messages.- Parameters:
errorLocale
- Locale for error messages. If null, the default locale is used.
-
-