Class RFC4180Parser
java.lang.Object
com.opencsv.AbstractCSVParser
com.opencsv.RFC4180Parser
- All Implemented Interfaces:
ICSVParser
This Parser is meant to parse according to the RFC4180 specification.
Since it shares the same interface with the CSVParser there are methods here that will do nothing. For example the RFC4180 specification does not have an concept of an escape character so the getEscape method will return char 0. The methods that are not supported are noted in the Javadocs.
Another departure from the CSVParser is that there is only two constructors and only one is available publicly. The intent is that if you want to create anything other than a default RFC4180Parser you should use the CSVParserBuilder. This way the code will not become cluttered with constructors as the CSVParser did.
You can view the RFC4180 specification at the Internet Engineering Task Force (IETF) website.
Examples:
ICSVParser parser = new RFC4180Parser();
or
CSVParserBuilder builder = new CSVParserBuilder()
ICSVParser parser = builder.withParserType(ParserType.RFC4180Parser).build()
- Since:
- 3.9
-
Field Summary
Fields inherited from class AbstractCSVParser
EMPTY_STRINGBUILDER, nullFieldIndicator, pending, quotechar, quotecharAsString, quoteDoubledAsString, quoteMatcherPattern, separator, separatorAsString, SPECIAL_REGEX_CHARSFields inherited from interface 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
ConstructorsConstructorDescriptionDefault constructor for the RFC4180Parser.RFC4180Parser(char quoteChar, char separator, CSVReaderNullFieldIndicator nullFieldIndicator) Constructor used by the CSVParserBuilder. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertToCsvValue(String value, boolean applyQuotesToAll) Used when reverse parsing an array of strings to a single string.private intfindEndOfFieldFromPosition(String nextLine, int currentPosition) private String[]handleEmptySeparators(String[] strings) private StringhandleQuotes(String element) private booleanhasOddQuotes(String lastElement) private booleanhasOnlyOneQuote(String lastElement) private booleanhaveNotFoundLastQuote(String nextLine, int nextQuote) private booleanprotected String[]Parses an incoming String and returns an array of elements.voidsetErrorLocale(Locale errorLocale) Sets the locale for all error messages.private String[]splitWhileNotInQuotes(String nextLine, boolean multi) private booleanstartsButDoesNotEndWithQuote(String lastElement) private String[]tokenizeStringIntoArray(String nextLine) Methods inherited from class AbstractCSVParser
convertToCsvValue, getPendingText, getQuotechar, getQuotecharAsString, getSeparator, getSeparatorAsString, isPending, isSurroundWithQuotes, nullFieldIndicator, parseLine, parseLineMulti, parseToLine, parseToLine
-
Constructor Details
-
RFC4180Parser
public RFC4180Parser()Default constructor for the RFC4180Parser. Uses values from the ICSVParser. -
RFC4180Parser
RFC4180Parser(char quoteChar, char separator, CSVReaderNullFieldIndicator nullFieldIndicator) Constructor used by the CSVParserBuilder.- Parameters:
quoteChar- The character to use for quoted elementsseparator- The delimiter to use for separating entriesnullFieldIndicator- Indicate what should be considered null
-
-
Method Details
-
convertToCsvValue
Description copied from class:AbstractCSVParserUsed 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:
convertToCsvValuein classAbstractCSVParser- Parameters:
value- String to be convertedapplyQuotesToAll- All values should be surrounded with quotes- Returns:
- String that will go into the CSV string
-
parseLine
Parses an incoming String and returns an array of elements.- Specified by:
parseLinein classAbstractCSVParser- Parameters:
nextLine- The string to parsemulti- Does it take multiple lines to form a single record?- Returns:
- The list of elements, or null if nextLine is null
-
tokenizeStringIntoArray
-
handleEmptySeparators
-
splitWhileNotInQuotes
-
lastElementStartedWithQuoteButDidNotEndInOne
-
hasOddQuotes
-
hasOnlyOneQuote
-
startsButDoesNotEndWithQuote
-
findEndOfFieldFromPosition
-
haveNotFoundLastQuote
-
handleQuotes
-
setErrorLocale
Description copied from interface:ICSVParserSets the locale for all error messages.- Parameters:
errorLocale- Locale for error messages. If null, the default locale is used.
-