public abstract class AbstractCSVParser extends Object implements ICSVParser
Modifier and Type | Field and Description |
---|---|
protected static StringBuilder |
EMPTY_STRINGBUILDER
Empty StringBuilder
|
protected CSVReaderNullFieldIndicator |
nullFieldIndicator
Determines the handling of null fields.
|
protected String |
pending
Value to be appended to string to process.
|
protected char |
quotechar
This is the character that the CSVParser will treat as the quotation character.
|
protected String |
quotecharAsString
This is the quotechar in String form to reduce the number of calls to toString.
|
protected String |
quoteDoubledAsString
This is quotecharAsString+quotecharAsString - used in replaceAll to reduce the number of strings being created.
|
protected Pattern |
quoteMatcherPattern
pattern created to match quotechars - optimizaion of the String.replaceAll.
|
protected char |
separator
This is the character that the CSVParser will treat as the separator.
|
protected String |
separatorAsString
This is the separator in Stirng form to reduce the number of calls to toString.
|
protected static Pattern |
SPECIAL_REGEX_CHARS
This is needed by the split command in case the separator character is a regex special character.
|
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 and Description |
---|
AbstractCSVParser(char separator,
char quotechar,
CSVReaderNullFieldIndicator nullFieldIndicator)
Common constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract String |
convertToCsvValue(String value,
boolean applyQuotestoAll)
Used when reverse parsing an array of strings to a single string.
|
protected void |
convertToCsvValue(String value,
boolean applyQuotesToAll,
Appendable appendable)
Used when reverse parsing an array of strings to a single string.
|
String |
getPendingText()
If a parser is in the middle of parsing a multiline field, this will
return the text collected so far.
|
char |
getQuotechar() |
String |
getQuotecharAsString() |
char |
getSeparator() |
String |
getSeparatorAsString() |
boolean |
isPending() |
protected boolean |
isSurroundWithQuotes(String value,
boolean forceSurround)
Used by reverse parsing to determine if a value should be surrounded by quote characters.
|
CSVReaderNullFieldIndicator |
nullFieldIndicator() |
String[] |
parseLine(String nextLine)
Parses an incoming String and returns an array of elements.
|
protected abstract String[] |
parseLine(String nextLine,
boolean multi)
Parses an incoming
String and returns an array of elements. |
String[] |
parseLineMulti(String nextLine)
Parses an incoming String and returns an array of elements.
|
String |
parseToLine(String[] values,
boolean applyQuotesToAll)
Essentially a "Reverse parse" where an array of values are concatenating to a
csv delimited string.
|
void |
parseToLine(String[] values,
boolean applyQuotesToAll,
Appendable appendable)
Essentially a "Reverse parse" where an array of values are concatenating to a
csv delimited string.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setErrorLocale
protected static final Pattern SPECIAL_REGEX_CHARS
protected static final StringBuilder EMPTY_STRINGBUILDER
protected final char separator
protected final String separatorAsString
protected final char quotechar
protected final String quotecharAsString
protected final String quoteDoubledAsString
protected final Pattern quoteMatcherPattern
protected final CSVReaderNullFieldIndicator nullFieldIndicator
CSVReaderNullFieldIndicator
protected String pending
public AbstractCSVParser(char separator, char quotechar, CSVReaderNullFieldIndicator nullFieldIndicator)
separator
- The delimiter to use for separating entriesquotechar
- The character to use for quoted elementsnullFieldIndicator
- Indicate what should be considered nullpublic char getSeparator()
getSeparator
in interface ICSVParser
public String getSeparatorAsString()
public char getQuotechar()
getQuotechar
in interface ICSVParser
public String getQuotecharAsString()
public boolean isPending()
isPending
in interface ICSVParser
public String[] parseLineMulti(String nextLine) throws IOException
ICSVParser
parseLineMulti
in interface ICSVParser
nextLine
- Current line to be processedIOException
- If bad things happen during the readpublic String[] parseLine(String nextLine) throws IOException
ICSVParser
parseLine
in interface ICSVParser
nextLine
- Line to be parsed.IOException
- If bad things happen during the readpublic String parseToLine(String[] values, boolean applyQuotesToAll)
ICSVParser
parseToLine
in interface ICSVParser
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).public void parseToLine(String[] values, boolean applyQuotesToAll, Appendable appendable) throws IOException
ICSVParser
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.
parseToLine
in interface ICSVParser
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).appendable
- The Appendable that the parsed values will be appended toIOException
protected abstract String convertToCsvValue(String value, boolean applyQuotestoAll)
value
- String to be convertedapplyQuotestoAll
- All values should be surrounded with quotesprotected void convertToCsvValue(String value, boolean applyQuotesToAll, Appendable appendable) throws IOException
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.
value
- String to be convertedapplyQuotesToAll
- All values should be surrounded with quotesappendable
- Appendable object that the converted values are added to.IOException
protected boolean isSurroundWithQuotes(String value, boolean forceSurround)
value
- String to be testedforceSurround
- If the value is not null
it will be surrounded with quotesprotected abstract String[] parseLine(String nextLine, boolean multi) throws IOException
String
and returns an array of elements.nextLine
- The string to parsemulti
- Whether it takes multiple lines to form a single recordnull
if nextLine
is null
IOException
- If bad things happen during the readpublic CSVReaderNullFieldIndicator nullFieldIndicator()
nullFieldIndicator
in interface ICSVParser
public String getPendingText()
ICSVParser
getPendingText
in interface ICSVParser
Copyright © 2005–2023. All rights reserved.