public interface CsvReadParameters
The default parameters will handle CSVs that follow these guidelines:
LineEnding
."Address, Street"
.\
.2001-02-03
.2001-02-03T04:05:06.007Z
.
If the CSV being read does not follow these guidelines, then these parameters can be modified as needed.
For CSVs with custom Date or DateTime formatting, the values can be read in as a CsvValueType.STRING
and
parsed manually. For example, via LocalDate.parse(CharSequence, java.time.format.DateTimeFormatter)
.
Modifier and Type | Field and Description |
---|---|
static char |
NO_ESCAPE_CHARACTER
Character that can be provided to
setEscape(char) if occurrences of the default escape character
('\' ) should be treated as the literal character, and not as a marker for the start of an escaped
character. |
static char |
NO_QUOTES_CHARACTER
Character that can be provided to
setQuote(char) if occurrences of the default quote character
('"' ) should be treated as the literal character, and not as a marker for the start/end of an individual
value. |
Modifier and Type | Method and Description |
---|---|
CsvReadParameters |
setEscape(char escape)
Sets the character used to escape quote characters and other escape characters in individual values.
|
CsvReadParameters |
setHasHeaders(boolean hasHeaders)
Sets whether or not the CSV being read has headers.
|
CsvReadParameters |
setQuote(char quote)
Sets the character used to surround individual values.
|
CsvReadParameters |
setSeparator(char separator)
Sets the character that separates values.
|
static final char NO_QUOTES_CHARACTER
setQuote(char)
if occurrences of the default quote character
('"'
) should be treated as the literal character, and not as a marker for the start/end of an individual
value.static final char NO_ESCAPE_CHARACTER
setEscape(char)
if occurrences of the default escape character
('\'
) should be treated as the literal character, and not as a marker for the start of an escaped
character.CsvReadParameters setHasHeaders(boolean hasHeaders)
Note that if this is set to true, the CSV being read must not contain multiple headers that have the same name. If it does, reading will throw an exception. If it is necessary to read in a CSV that contains multiple headers with the same name, the CSV can be read in as a CSV without headers. In that case, the header row will be treated as a regular value row, which can have duplicates.
hasHeaders
- true if the CSV being read has headers; false if the CSV being read doesn't have headersCsvReadParameters setSeparator(char separator)
','
.
For example, when reading the value "ABC,DEF"
if the separator character is ','
, then
"ABC"
and "DEF"
would be the individual values. If the separator character is 'D'
, then
"ABC,"
and "EF"
would be the individual values.
The separator, escape, and quote characters must be different.
separator
- the separator charCsvReadParameters setEscape(char escape)
'\'
.
When this character is encountered during a read, it will be assumed that it is escaping the subsequent character. If the escape character is intended to be contained in the content of an individual value, it must be preceded by itself.
For example, when reading the value "foo\\bar"
if the escape character is '\'
, then the value
would be read as "foo\bar"
.
The separator, escape, and quote characters must be different.
escape
- the escape charCsvReadParameters setQuote(char quote)
'"'
.
When this character is encountered during a read, it will be assumed that it is either the start/end
of an individual value. If the quote character is intended to be contained in the content of an individual value,
it must be preceded by the escape character (set by setEscape(char)
).
If there are non-escaped quotes that should be read in as a value, then this can be called with
NO_QUOTES_CHARACTER
.
The separator, escape, and quote characters must be different.
quote
- the quote charCopyright © Veeva Systems 2017–2021. All rights reserved.