public final class CsvPreference extends Object
Please note: the end of line symbols are only used for writing.
The following predefined configurations are available:
Constant | Quote character | Delimiter character | End of line symbols |
---|---|---|---|
STANDARD_PREFERENCE |
" |
, |
\r\n |
EXCEL_PREFERENCE |
" |
, |
\n |
EXCEL_NORTH_EUROPE_PREFERENCE |
" |
; |
\n |
TAB_PREFERENCE |
" |
\t |
\n |
By default, spaces surrounding an unquoted cell are treated as part of the data. In versions of Super CSV prior to 2.0.0 this wasn't the case, and any surrounding spaces that weren't within quotes were ignored when reading (and quotes were automatically added to Strings containing surrounding spaces when writing).
If you wish enable this functionality again, then you can create a CsvPreference with the surroundingSpacesNeedQuotes flag set to true (the default is false). This means that surrounding spaces without quotes will be trimmed when reading, and quotes will automatically be added for Strings containing surrounding spaces when writing.
You can apply the surroundingSpacesNeedQuotes property to an existing preference as follows:
private static final CsvPreference STANDARD_SURROUNDING_SPACES_NEED_QUOTES = new CsvPreference.Builder(CsvPreference.STANDARD_PREFERENCE).surroundingSpacesNeedQuotes(true).build();
You can also create your own preferences. For example if your file was pipe-delimited, you could use the following:
private static final CsvPreference PIPE_DELIMITED = new CsvPreference.Builder('"', '|', "\n").build();
Modifier and Type | Class and Description |
---|---|
static class |
CsvPreference.Builder
Builds immutable CsvPreference instances.
|
Modifier and Type | Field and Description |
---|---|
static CsvPreference |
EXCEL_NORTH_EUROPE_PREFERENCE
Ready to use configuration for north European excel CSV files (columns are separated by ";" instead of ",")
|
static CsvPreference |
EXCEL_PREFERENCE
Ready to use configuration for Windows Excel exported CSV files.
|
static CsvPreference |
STANDARD_PREFERENCE
Ready to use configuration that should cover 99% of all usages.
|
static CsvPreference |
TAB_PREFERENCE
Ready to use configuration for tab-delimited files.
|
Modifier and Type | Method and Description |
---|---|
int |
getDelimiterChar()
Returns the delimiter character
|
String |
getEndOfLineSymbols()
Returns the end of line symbols
|
int |
getQuoteChar()
Returns the quote character
|
boolean |
isSurroundingSpacesNeedQuotes()
Returns the surroundingSpacesNeedQuotes flag.
|
public static final CsvPreference STANDARD_PREFERENCE
public static final CsvPreference EXCEL_PREFERENCE
public static final CsvPreference EXCEL_NORTH_EUROPE_PREFERENCE
public static final CsvPreference TAB_PREFERENCE
public int getDelimiterChar()
public String getEndOfLineSymbols()
public int getQuoteChar()
public boolean isSurroundingSpacesNeedQuotes()
Copyright © 2007-2012 Super CSV. All Rights Reserved.