public class CSVOptions
extends java.lang.Object
Reader
s and
CSVParser
s based on these options.Modifier and Type | Class and Description |
---|---|
static class |
CSVOptions.ParseResult
Helper class for the result of parseIRI(iri)
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.Character> |
charNames |
private static java.lang.String |
charsetKey |
private java.lang.Boolean |
columnNamesInFirstRow |
private java.lang.Character |
delimiter |
private static java.lang.String |
delimiterKey |
private java.lang.String |
encoding |
private static java.lang.String |
encodingKey |
private java.lang.Character |
escape |
private static java.lang.String |
escapeCharKey |
private static java.lang.String |
headerKey |
private java.lang.Character |
quote |
private static java.lang.String |
quoteCharKey |
Constructor and Description |
---|
CSVOptions()
Creates a new instance with default values.
|
CSVOptions(CSVOptions defaults)
Creates a new instance and initializes it with values
from another instance.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Character |
getDelimiter()
Gets the delimiter between entries.
|
java.lang.String |
getEncoding()
Returns the CSV file's character encoding, or
null
if unknown. |
java.lang.Character |
getEscapeChar()
Gets the escape character used in the file to escape quotes.
|
java.lang.Character |
getQuoteChar()
Gets the quote character used in the file.
|
java.lang.Boolean |
hasColumnNamesInFirstRow()
Set whether the CSV file's first row contains column names.
|
CSVParser |
openParserFor(InputStreamSource source)
Creates a new
CSVParser for a given InputStreamSource
with the options of this instance. |
java.io.Reader |
openReaderFor(InputStreamSource source)
Creates a new
Reader for a given InputStreamSource
with the options of this instance. |
void |
overrideWith(CSVOptions other)
Override values in this object with those from the other.
|
private static java.lang.Character |
parseChar(java.lang.String value)
Interprets argument as a character.
|
static CSVOptions.ParseResult |
parseIRI(java.lang.String iri)
Extracts a CSVOptions object from the fragment part of a
CSV file URL, e.g.,
http://example.com/file.csv#encoding=utf-8;header=absent
The remainder of the URL, with anything interpretable
removed, can also be obtained from the returned
parse result. |
void |
setColumnNamesInFirstRow(java.lang.Boolean value)
Set whether the CSV file's first row contains column names.
|
void |
setDelimiter(java.lang.Character delimiter)
Sets the delimiter between entries.
|
void |
setEncoding(java.lang.String encoding)
Specify the CSV file's character encoding.
|
void |
setEscapeChar(java.lang.Character escape)
Sets the escape character used in the file to escape quotes.
|
void |
setQuoteChar(java.lang.Character quote)
Sets the quote character used in the file.
|
private static final java.lang.String encodingKey
private static final java.lang.String charsetKey
private static final java.lang.String headerKey
private static final java.lang.String delimiterKey
private static final java.lang.String quoteCharKey
private static final java.lang.String escapeCharKey
private static final java.util.Map<java.lang.String,java.lang.Character> charNames
private java.lang.String encoding
private java.lang.Boolean columnNamesInFirstRow
private java.lang.Character delimiter
private java.lang.Character quote
private java.lang.Character escape
public CSVOptions()
public CSVOptions(CSVOptions defaults)
defaults
- Configuration options for the CSV file.public void overrideWith(CSVOptions other)
null
in the other object will be ignored.public static CSVOptions.ParseResult parseIRI(java.lang.String iri)
http://example.com/file.csv#encoding=utf-8;header=absent
The remainder of the URL, with anything interpretable
removed, can also be obtained from the returned
parse result.iri
- IRI to parse.private static java.lang.Character parseChar(java.lang.String value)
value
- String to parse.public void setEncoding(java.lang.String encoding)
null
signifies unknown encoding, that is, auto-detection.
The default is null
.encoding
- New encoding.public java.lang.String getEncoding()
null
if unknown.public void setColumnNamesInFirstRow(java.lang.Boolean value)
null
means unknown.
The default is null
.value
- Determine if first column contains the headers.public java.lang.Boolean hasColumnNamesInFirstRow()
null
means unknown.
The default is null
.public void setDelimiter(java.lang.Character delimiter)
null
means unknown.delimiter
- Delimiter character.public java.lang.Character getDelimiter()
null
means unknown.public void setQuoteChar(java.lang.Character quote)
null
means unknown.quote
- Quote character.public java.lang.Character getQuoteChar()
null
means unknown.public void setEscapeChar(java.lang.Character escape)
null
means no escape character, and quotes inside quoted
values are escaped as two quote characters.escape
- Escape character.public java.lang.Character getEscapeChar()
null
means no escape character, and quotes inside quoted
values are escaped as two quote characters.public CSVParser openParserFor(InputStreamSource source) throws java.io.IOException
CSVParser
for a given InputStreamSource
with the options of this instance.source
- CSV input.java.io.IOException
public java.io.Reader openReaderFor(InputStreamSource source) throws java.io.IOException
Reader
for a given InputStreamSource
with the options of this instance.source
- CSV input.java.io.IOException