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.
|
String |
getPendingText()
If a parser is in the middle of parsing a multiline field, this will
return the text collected so far.
|
char |
getQuotechar() |
char |
getSeparator() |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setErrorLocale
protected final char separator
protected final char quotechar
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 char getQuotechar()
getQuotechar
in interface ICSVParser
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).protected abstract String convertToCsvValue(String value, boolean applyQuotestoAll)
value
- String to be testedapplyQuotestoAll
- All values should be surrounded with quotesprotected 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 © 2021. All rights reserved.