public abstract class AbstractCSVParser extends Object implements ICSVParser
| Modifier and Type | Field and Description |
|---|---|
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 char |
separator
This is the character that the CSVParser will treat as the separator.
|
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() |
protected String |
getQuoteDoubledAsString()
Returns the doubled quote character as a string representation.
|
protected Pattern |
getQuoteMatcherPattern()
Retrieves the compiled
Pattern used for matching quoted elements in a CSV input. |
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, waitsetErrorLocaleprotected final char separator
protected final char quotechar
protected final CSVReaderNullFieldIndicator nullFieldIndicator
CSVReaderNullFieldIndicatorprotected 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 nullprotected final String getQuoteDoubledAsString()
protected final Pattern getQuoteMatcherPattern()
Pattern used for matching quoted elements in a CSV input.Pattern used for identifying quoted elements.public char getSeparator()
getSeparator in interface ICSVParserpublic String getSeparatorAsString()
public char getQuotechar()
getQuotechar in interface ICSVParserpublic String getQuotecharAsString()
public boolean isPending()
isPending in interface ICSVParserpublic String[] parseLineMulti(String nextLine) throws IOException
ICSVParserparseLineMulti in interface ICSVParsernextLine - Current line to be processedIOException - If bad things happen during the readpublic String[] parseLine(String nextLine) throws IOException
ICSVParserparseLine in interface ICSVParsernextLine - Line to be parsed.IOException - If bad things happen during the readpublic String parseToLine(String[] values, boolean applyQuotesToAll)
ICSVParserparseToLine in interface ICSVParservalues - 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
ICSVParserNOTE: 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 ICSVParservalues - 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 toIOExceptionprotected 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.IOExceptionprotected 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 nullIOException - If bad things happen during the readpublic CSVReaderNullFieldIndicator nullFieldIndicator()
nullFieldIndicator in interface ICSVParserpublic String getPendingText()
ICSVParsergetPendingText in interface ICSVParserCopyright © 2005–2025. All rights reserved.