Top Description Fields Constructors Methods
com.opencsv

public abstract Class AbstractCSVParser

extends Object
implements ICSVParser
Class Inheritance
All Implemented Interfaces
com.opencsv.ICSVParser
Known Direct Subclasses
com.opencsv.CSVParser, com.opencsv.RFC4180Parser
Imports
com.opencsv.enums.CSVReaderNullFieldIndicator, org.apache.commons.lang3.StringUtils, java.io.IOException, java.util.regex.Pattern, java.util.stream.Collectors, .Stream

An abstract class representing the basic functionality required for parsing CSV files. Implements the ICSVParser interface and provides common shared behavior for various CSV parsing implementations.

Field Summary

Modifier and TypeField and Description
protected final CSVReaderNullFieldIndicator
nullFieldIndicator

Determines the handling of null fields.

protected String
pending

Value to be appended to string to process.

protected final char
quotechar

This is the character that the CSVParser will treat as the quotation character.

private final String
quotecharAsString

This is the quotechar in String form to reduce the number of calls to toString.

private final String
quoteDoubledAsString

This is quotecharAsString+quotecharAsString - used in replaceAll to reduce the number of strings being created.

private final Pattern
quoteMatcherPattern

pattern created to match quotechars - optimizaion of the String.replaceAll.

protected final char
separator

This is the character that the CSVParser will treat as the separator.

private final String
separatorAsString

This is the separator in String form to reduce the number of calls to toString.

Constructor Summary

AccessConstructor and Description
public
AbstractCSVParser(char
The delimiter to use for separating entries
separator
,
char
The character to use for quoted elements
quotechar
,
CSVReaderNullFieldIndicator
Indicate what should be considered null
nullFieldIndicator
)

Common constructor.

Method Summary

Modifier and TypeMethod and Description
protected abstract String

Returns:

String that will go into the CSV string
convertToCsvValue
(String
String to be converted
value
,
boolean
All values should be surrounded with quotes
applyQuotestoAll
)

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

protected void
convertToCsvValue(String
String to be converted
value
,
boolean
All values should be surrounded with quotes
applyQuotesToAll
,
Appendable
Appendable object that the converted values are added to.
appendable
)

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

public String
getPendingText()

Implements com.opencsv.ICSVParser.getPendingText.

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

public char
public String
getQuotecharAsString()

Returns: String version of quotechar to reduce the number of calls to toString.

protected final String

Returns:

The string representation of the doubled quote character.
getQuoteDoubledAsString
()

Returns the doubled quote character as a string representation.

protected final Pattern

Returns:

The Pattern used for identifying quoted elements.
getQuoteMatcherPattern
()

Retrieves the compiled Pattern used for matching quoted elements in a CSV input.

public char
public String
getSeparatorAsString()

Returns: String version of separator to reduce number of calls to toString.

public boolean
protected boolean

Returns:

True if the string should be surrounded with quotes, false otherwise
isSurroundWithQuotes
(String
String to be tested
value
,
boolean
If the value is not null it will be surrounded with quotes
forceSurround
)

Used by reverse parsing to determine if a value should be surrounded by quote characters.

public CSVReaderNullFieldIndicator
public String[]
parseLine(String nextLine)

Implements com.opencsv.ICSVParser.parseLine.

Parses an incoming String and returns an array of elements.

protected abstract String[]

Returns:

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

Parses an incoming java.lang.String and returns an array of elements.

public String[]
parseLineMulti(String nextLine)

Implements com.opencsv.ICSVParser.parseLineMulti.

Parses an incoming String and returns an array of elements.

public String
parseToLine(String[] values, boolean applyQuotesToAll)

Implements com.opencsv.ICSVParser.parseToLine.

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

public void
parseToLine(String[] values, boolean applyQuotesToAll, Appendable appendable)

Implements com.opencsv.ICSVParser.parseToLine.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nullFieldIndicatorback to summary
protected final CSVReaderNullFieldIndicator nullFieldIndicator

Determines the handling of null fields.

See Also
CSVReaderNullFieldIndicator
pendingback to summary
protected String pending

Value to be appended to string to process.

quotecharback to summary
protected final char quotechar

This is the character that the CSVParser will treat as the quotation character.

quotecharAsStringback to summary
private final String quotecharAsString

This is the quotechar in String form to reduce the number of calls to toString.

quoteDoubledAsStringback to summary
private final String quoteDoubledAsString

This is quotecharAsString+quotecharAsString - used in replaceAll to reduce the number of strings being created.

quoteMatcherPatternback to summary
private final Pattern quoteMatcherPattern

pattern created to match quotechars - optimizaion of the String.replaceAll.

separatorback to summary
protected final char separator

This is the character that the CSVParser will treat as the separator.

separatorAsStringback to summary
private final String separatorAsString

This is the separator in String form to reduce the number of calls to toString.

Constructor Detail

AbstractCSVParserback to summary
public AbstractCSVParser(char separator, char quotechar, CSVReaderNullFieldIndicator nullFieldIndicator)

Common constructor.

Parameters
separator:char

The delimiter to use for separating entries

quotechar:char

The character to use for quoted elements

nullFieldIndicator:CSVReaderNullFieldIndicator

Indicate what should be considered null

Method Detail

convertToCsvValueback to summary
protected abstract String convertToCsvValue(String value, boolean applyQuotestoAll)

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.

Parameters
value:String

String to be converted

applyQuotestoAll:boolean

All values should be surrounded with quotes

Returns:String

String that will go into the CSV string

convertToCsvValueback to summary
protected void convertToCsvValue(String value, boolean applyQuotesToAll, Appendable appendable) throws IOException

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.

Note

as of 5.7.2 most objects will be inheriting a solution that calls the existing convertToCsvValue and thus will not receive much benefit.

Parameters
value:String

String to be converted

applyQuotesToAll:boolean

All values should be surrounded with quotes

appendable:Appendable

Appendable object that the converted values are added to.

getPendingTextback to summary
public String getPendingText()

Implements com.opencsv.ICSVParser.getPendingText.

Doc from com.opencsv.ICSVParser.getPendingText.

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

Annotations
@Override
getQuotecharback to summary
public char getQuotechar()

Implements com.opencsv.ICSVParser.getQuotechar.

Annotations
@Override
getQuotecharAsStringback to summary
public String getQuotecharAsString()
Returns:String

String version of quotechar to reduce the number of calls to toString.

getQuoteDoubledAsStringback to summary
protected final String getQuoteDoubledAsString()

Returns the doubled quote character as a string representation.

Returns:String

The string representation of the doubled quote character.

getQuoteMatcherPatternback to summary
protected final Pattern getQuoteMatcherPattern()

Retrieves the compiled Pattern used for matching quoted elements in a CSV input.

Returns:Pattern

The Pattern used for identifying quoted elements.

getSeparatorback to summary
public char getSeparator()

Implements com.opencsv.ICSVParser.getSeparator.

Annotations
@Override
getSeparatorAsStringback to summary
public String getSeparatorAsString()
Returns:String

String version of separator to reduce number of calls to toString.

isPendingback to summary
public boolean isPending()

Implements com.opencsv.ICSVParser.isPending.

Annotations
@Override
isSurroundWithQuotesback to summary
protected boolean isSurroundWithQuotes(String value, boolean forceSurround)

Used by reverse parsing to determine if a value should be surrounded by quote characters.

Parameters
value:String

String to be tested

forceSurround:boolean

If the value is not null it will be surrounded with quotes

Returns:boolean

True if the string should be surrounded with quotes, false otherwise

nullFieldIndicatorback to summary
public CSVReaderNullFieldIndicator nullFieldIndicator()

Implements com.opencsv.ICSVParser.nullFieldIndicator.

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

Implements com.opencsv.ICSVParser.parseLine.

Doc from com.opencsv.ICSVParser.parseLine.

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

Annotations
@Override
Exceptions
IOException:
If bad things happen during the read
parseLineback to summary
protected abstract String[] parseLine(String nextLine, boolean multi) throws IOException

Parses an incoming java.lang.String and returns an array of elements.

Parameters
nextLine:String

The string to parse

multi:boolean

Whether it takes multiple lines to form a single record

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

Implements com.opencsv.ICSVParser.parseLineMulti.

Doc from com.opencsv.ICSVParser.parseLineMulti.

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

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

Implements com.opencsv.ICSVParser.parseToLine.

Doc from com.opencsv.ICSVParser.parseToLine.

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

Annotations
@Override
parseToLineback to summary
public void parseToLine(String[] values, boolean applyQuotesToAll, Appendable appendable) throws IOException

Implements com.opencsv.ICSVParser.parseToLine.

Doc from com.opencsv.ICSVParser.parseToLine.

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.

Annotations
@Override