Top Description Fields Constructors Methods
com.opencsv

public Class RFC4180Parser

extends AbstractCSVParser
Class Inheritance
Imports
com.opencsv.enums.CSVReaderNullFieldIndicator, org.apache.commons.lang3.ArrayUtils, .StringUtils, java.util.ArrayList, .List, .Locale

This Parser is meant to parse csv data 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 a 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 are 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()
Author
Scott Conway
Since
3.9

Field Summary

Inherited from com.opencsv.AbstractCSVParser:
nullFieldIndicatorpendingquotecharseparator

Constructor Summary

AccessConstructor and Description
public
RFC4180Parser()

Default constructor for the RFC4180Parser.

protected
RFC4180Parser(char
The character to use for quoted elements
quoteChar
,
char
The delimiter to use for separating entries
separator
,
CSVReaderNullFieldIndicator
Indicate what should be considered null
nullFieldIndicator
)

Constructor used by the CSVParserBuilder.

Method Summary

Modifier and TypeMethod and Description
protected String
convertToCsvValue(String value, boolean applyQuotesToAll)

Implements abstract com.opencsv.AbstractCSVParser.convertToCsvValue.

Used when reverse parsing an array of strings to a single string.

private int
findEndOfFieldFromPosition(String nextLine, int currentPosition)

private String[]
private String
private boolean
hasOddQuotes(String lastElement)

private boolean
hasOnlyOneQuote(String lastElement)

private boolean
haveNotFoundLastQuote(String nextLine, int nextQuote)

private boolean
protected String[]

Returns:

The list of elements, or null if nextLine is null
parseLine
(String
The string to parse
nextLine
,
boolean
Does it take multiple lines to form a single record?
multi
)

Implements abstract com.opencsv.AbstractCSVParser.parseLine.

Parses an incoming String and returns an array of elements.

public void
setErrorLocale(Locale errorLocale)

Implements com.opencsv.ICSVParser.setErrorLocale.

Sets the locale for all error messages.

private String[]
splitWhileNotInQuotes(String nextLine, boolean multi)

private boolean
private String[]
Inherited from com.opencsv.AbstractCSVParser:
convertToCsvValuegetPendingTextgetQuotechargetQuotecharAsStringgetQuoteDoubledAsStringgetQuoteMatcherPatterngetSeparatorgetSeparatorAsStringisPendingisSurroundWithQuotesnullFieldIndicatorparseLineparseLineMultiparseToLineparseToLine

Constructor Detail

RFC4180Parserback to summary
public RFC4180Parser()

Default constructor for the RFC4180Parser. Uses values from the ICSVParser.

RFC4180Parserback to summary
protected RFC4180Parser(char quoteChar, char separator, CSVReaderNullFieldIndicator nullFieldIndicator)

Constructor used by the CSVParserBuilder.

Parameters
quoteChar:char

The character to use for quoted elements

separator:char

The delimiter to use for separating entries

nullFieldIndicator:CSVReaderNullFieldIndicator

Indicate what should be considered null

Method Detail

convertToCsvValueback to summary
protected String convertToCsvValue(String value, boolean applyQuotesToAll)

Implements abstract com.opencsv.AbstractCSVParser.convertToCsvValue.

Doc from com.opencsv.AbstractCSVParser.convertToCsvValue.

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.

Annotations
@Override
findEndOfFieldFromPositionback to summary
private int findEndOfFieldFromPosition(String nextLine, int currentPosition)
handleEmptySeparatorsback to summary
private String[] handleEmptySeparators(String[] strings)
handleQuotesback to summary
private String handleQuotes(String element)
hasOddQuotesback to summary
private boolean hasOddQuotes(String lastElement)
hasOnlyOneQuoteback to summary
private boolean hasOnlyOneQuote(String lastElement)
haveNotFoundLastQuoteback to summary
private boolean haveNotFoundLastQuote(String nextLine, int nextQuote)
lastElementStartedWithQuoteButDidNotEndInOneback to summary
private boolean lastElementStartedWithQuoteButDidNotEndInOne(List<String> elements)
parseLineback to summary
protected String[] parseLine(String nextLine, boolean multi)

Implements abstract com.opencsv.AbstractCSVParser.parseLine.

Parses an incoming String and returns an array of elements.

Parameters
nextLine:String

The string to parse

multi:boolean

Does it take multiple lines to form a single record?

Returns:String[]

The list of elements, or null if nextLine is null

setErrorLocaleback to summary
public void setErrorLocale(Locale errorLocale)

Implements com.opencsv.ICSVParser.setErrorLocale.

Doc from com.opencsv.ICSVParser.setErrorLocale.

Sets the locale for all error messages.

Annotations
@Override
splitWhileNotInQuotesback to summary
private String[] splitWhileNotInQuotes(String nextLine, boolean multi)
startsButDoesNotEndWithQuoteback to summary
private boolean startsButDoesNotEndWithQuote(String lastElement)
tokenizeStringIntoArrayback to summary
private String[] tokenizeStringIntoArray(String nextLine)