Top Description Fields Constructors Methods
com.univocity.parsers.csv

public Class CsvWriterSettings

extends CommonWriterSettings<CsvFormat>
Class Inheritance
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.fields.*, java.util.*

This is the configuration class used by the CSV writer (CsvWriter)

In addition to the configuration options provided by CommonWriterSettings, the CsvWriterSettings include:

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.csv.CsvWriter, com.univocity.parsers.csv.CsvFormat, com.univocity.parsers.common.CommonWriterSettings

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private char[]
private boolean
private FieldSelector
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
public final CsvWriterSettings
clone()

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Clones this configuration object.
public final CsvWriterSettings
clone(boolean
flag indicating whether to clear settings that are likely to be associated with a given input.
clearInputSpecificSettings
)

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Clones this configuration object to reuse user-provided settings.
protected CsvFormat

Returns:

and instance of CsvFormat configured to produce CSV outputs compliant to the RFC4180 standard.
createDefaultFormat
()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default CsvFormat configured to produce CSV outputs compliant to the RFC4180 standard.
public char[]

Returns:

the characters that will trigger values to be quoted when present in a value to be written.
getQuotationTriggers
()

Returns the list of characters that when present in a value to be written, will force the output value to be enclosed in quotes.

public boolean

Returns:

true if all written values should be enclosed within quotes, false otherwise
getQuoteAllFields
()

Indicates that all written values should be enclosed within quotes (as defined in CsvFormat)

(Defaults to false)

pack-priv final FieldSelector

Returns:

the current selection of quoted fields
getQuotedFieldSelector
()

Returns the current selection of quoted fields (if any)

public boolean

Returns:

a flag indicating whether null values should be quoted.
getQuoteNulls
()

Flag whether to quote null values sent to the CsvWriter when the corresponding column is configured to be quoted via quoteFields(String...), or getQuoteAllFields() evaluates to true.

public boolean

Returns:

true if escape sequences should be processed in unquoted values, otherwise false
isEscapeUnquotedValues
()

Indicates whether escape sequences should be written in unquoted values.

public final boolean

Returns:

a flag indicating whether the escape sequences should not be introduced by the writer.
isInputEscaped
()

Indicates that the user will provide escaped input, and the writer will not try to introduce escape sequences.

public boolean

Returns:

true if line separator characters in quoted values should be considered 'normalized' and replaced by the sequence specified in Format#getLineSeparator(), false otherwise
isNormalizeLineEndingsWithinQuotes
()

Flag indicating whether the writer should replace the the normalized line separator character specified in Format#getNormalizedNewline() by the sequence specified in Format#getLineSeparator(), when the value is enclosed within quotes.

public boolean

Returns:

true if the given character is a quotation trigger, false otherwise.
isQuotationTrigger
(char
the character to be tested
ch
)

Queries if a given character is a quotation trigger, i.e. a character that if present in a value to be written, will make the CSV writer enclose the entire value within quotes.

public boolean

Returns:

a flag indicating whether values containing quotes should be enclosed in quotes.
isQuoteEscapingEnabled
()

Indicates whether the CSV writer should escape values that contain the quote character, by enclosing the entire value in quotes.

public final FieldSet<Enum<E extends Enum<E>>>

Returns:

the (modifiable) set of selected fields to be quoted.
quoteFields
(Enum<E extends Enum<E>>...
a selection of columns that will always be quoted
columns
)

Selects fields whose values should always be written within quotes

public final FieldSet<String>

Returns:

the (modifiable) set of selected fields to be quoted.
quoteFields
(String...
a selection of columns that will always be quoted
columns
)

Selects fields whose values should always be written within quotes

public final FieldSet<Integer>

Returns:

the (modifiable) set of column positions to be quoted.
quoteIndexes
(Integer...
a selection of column indexes that will always be quoted
columns
)

Selects field positions whose values should always be written within quotes

public void
setEscapeUnquotedValues(boolean
a flag indicating whether escape sequences should be processed in unquoted values
escapeUnquotedValues
)

Configures the writer to process escape sequences in unquoted values.

private <T> FieldSet<T>

Returns:

the set of selected fields given in as a parameter.
setFieldSet
(FieldSet<T>
the new set of selected fields
fieldSet
,
T...
the values to include to the selection
values
)

Hides com.univocity.parsers.common.CommonSettings.setFieldSet.

Replaces the current quoted field selection
public final void
setInputEscaped(boolean
a flag indicating whether the input that will be written is already properly escaped.
isInputEscaped
)

Configures the writer to prevent it to introduce escape sequences.

public void
setNormalizeLineEndingsWithinQuotes(boolean
flag indicating that line separator characters in quoted values should be considered 'normalized' and occurrences of Format#getNormalizedNewline() should be replaced by the sequence specified in Format#getLineSeparator()
normalizeLineEndingsWithinQuotes
)

Flag indicating whether the writer should replace the the normalized line separator character specified in Format#getNormalizedNewline() by the sequence specified in Format#getLineSeparator(), when the value is enclosed within quotes.

public void
setQuotationTriggers(char...
a list of characters that when present in a value to be written, will force the output value to be enclosed in quotes.
quotationTriggers
)

Defines one or more "triggers" for enclosing a value within quotes.

public void
setQuoteAllFields(boolean
a flag indicating whether to enclose all fields within quotes
quoteAllFields
)

Indicates indicates whether or not all written values should be enclosed within quotes (as defined in CsvFormat)

(Defaults to false)

By default, only values that contain a field separator are enclosed within quotes.

public void
setQuoteEscapingEnabled(boolean
a flag indicating whether values containing quotes should be enclosed in quotes.
quoteEscapingEnabled
)

Configures the CSV writer to escape values that contain the quote character, by enclosing the entire value in quotes.

public void
setQuoteNulls(boolean
flag indicating whether null values should be quoted.
quoteNulls
)

Configures whether to quote null values sent to the CsvWriter when the corresponding column is configured to be quoted via quoteFields(String...), or getQuoteAllFields() evaluates to true.

Inherited from com.univocity.parsers.common.CommonWriterSettings:
clearInputSpecificSettingsconfigureFromAnnotationsgetEmptyValuegetExpandIncompleteRowsgetRowWriterProcessorisColumnReorderingEnabledisHeaderWritingEnabledsetColumnReorderingEnabledsetEmptyValuesetExpandIncompleteRowssetHeaderWritingEnabledsetRowWriterProcessor

Field Detail

escapeUnquotedValuesback to summary
private boolean escapeUnquotedValues
isInputEscapedback to summary
private boolean isInputEscaped
normalizeLineEndingsWithinQuotesback to summary
private boolean normalizeLineEndingsWithinQuotes
quotationTriggersback to summary
private char[] quotationTriggers
quoteAllFieldsback to summary
private boolean quoteAllFields
quotedFieldSelectorback to summary
private FieldSelector quotedFieldSelector
quoteEscapingEnabledback to summary
private boolean quoteEscapingEnabled
quoteNullsback to summary
private boolean quoteNulls

Constructor Detail

CsvWriterSettingsback to summary
public CsvWriterSettings()

Method Detail

addConfigurationback to summary
protected void addConfiguration(Map<String, Object> out)

Overrides com.univocity.parsers.common.CommonWriterSettings.addConfiguration.

Annotations
@Override
cloneback to summary
public final CsvWriterSettings clone()

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Doc from com.univocity.parsers.common.CommonSettings.clone.

Clones this configuration object. Use alternative clone(boolean) method to reset properties that are specific to a given input, such as header names and selection of fields.

Returns:CsvWriterSettings

a copy of all configurations applied to the current instance.

Annotations
@Override
cloneback to summary
public final CsvWriterSettings clone(boolean clearInputSpecificSettings)

Overrides com.univocity.parsers.common.CommonWriterSettings.clone.

Doc from com.univocity.parsers.common.CommonSettings.clone.

Clones this configuration object to reuse user-provided settings. Properties that are specific to a given input (such as header names and selection of fields) can be reset to their defaults if the clearInputSpecificSettings flag is set to true

Parameters
clearInputSpecificSettings:boolean

flag indicating whether to clear settings that are likely to be associated with a given input.

Returns:CsvWriterSettings

a copy of the configurations applied to the current instance.

Annotations
@Override
createDefaultFormatback to summary
protected CsvFormat createDefaultFormat()

Implements abstract com.univocity.parsers.common.CommonSettings.createDefaultFormat.

Returns the default CsvFormat configured to produce CSV outputs compliant to the RFC4180 standard.

Returns:CsvFormat

and instance of CsvFormat configured to produce CSV outputs compliant to the RFC4180 standard.

Annotations
@Override
getQuotationTriggersback to summary
public char[] getQuotationTriggers()

Returns the list of characters that when present in a value to be written, will force the output value to be enclosed in quotes.

Returns:char[]

the characters that will trigger values to be quoted when present in a value to be written.

getQuoteAllFieldsback to summary
public boolean getQuoteAllFields()

Indicates that all written values should be enclosed within quotes (as defined in CsvFormat)

(Defaults to false)

Returns:boolean

true if all written values should be enclosed within quotes, false otherwise

getQuotedFieldSelectorback to summary
pack-priv final FieldSelector getQuotedFieldSelector()

Returns the current selection of quoted fields (if any)

Returns:FieldSelector

the current selection of quoted fields

getQuoteNullsback to summary
public boolean getQuoteNulls()

Flag whether to quote null values sent to the CsvWriter when the corresponding column is configured to be quoted via quoteFields(String...), or getQuoteAllFields() evaluates to true.

Returns:boolean

a flag indicating whether null values should be quoted.

isEscapeUnquotedValuesback to summary
public boolean isEscapeUnquotedValues()

Indicates whether escape sequences should be written in unquoted values. Defaults to false.

By default, this is disabled and if the input is A""B,C, the resulting value will be [A""B] and [C] (i.e. the content is written as-is). However, if the writer is configured to process escape sequences in unquoted values, the values will be written as [A""""B] and [C]

Returns:boolean

true if escape sequences should be processed in unquoted values, otherwise false

isInputEscapedback to summary
public final boolean isInputEscaped()

Indicates that the user will provide escaped input, and the writer will not try to introduce escape sequences. The input will be written as-is.

Warning

ensure your data is properly escaped, otherwise the writer will produce invalid CSV.

This is disabled by default

Returns:boolean

a flag indicating whether the escape sequences should not be introduced by the writer.

isNormalizeLineEndingsWithinQuotesback to summary
public boolean isNormalizeLineEndingsWithinQuotes()

Flag indicating whether the writer should replace the the normalized line separator character specified in Format#getNormalizedNewline() by the sequence specified in Format#getLineSeparator(), when the value is enclosed within quotes. This is enabled by default and is used to ensure data be read on any platform without introducing unwanted blank lines. For example, consider the quoted value "Line1 \n Line2". If this is written using "\r\n" as the line separator sequence, and the normalized new line is set to '\n' (the default), the output will be: [Line1 \r\n Line2] However, if the value is meant to be kept untouched, and the original line separator should be maintained, set the normalizeLineEndingsWithinQuotes to false. This will make the writer output the value as-is, producing: [Line1 \n Line2]

Returns:boolean

true if line separator characters in quoted values should be considered 'normalized' and replaced by the sequence specified in Format#getLineSeparator(), false otherwise

isQuotationTriggerback to summary
public boolean isQuotationTrigger(char ch)

Queries if a given character is a quotation trigger, i.e. a character that if present in a value to be written, will make the CSV writer enclose the entire value within quotes.

Parameters
ch:char

the character to be tested

Returns:boolean

true if the given character is a quotation trigger, false otherwise.

isQuoteEscapingEnabledback to summary
public boolean isQuoteEscapingEnabled()

Indicates whether the CSV writer should escape values that contain the quote character, by enclosing the entire value in quotes. For example, consider a value such as [My "precious" value]. When quote escaping is enabled, the output will be: ["My ""precious"" value"] If disabled (the default), the value will be written as-is. Note that the CSV output will not conform to the RFC 4180 standard, but it will still be valid as the value does not contain line separators nor the delimiter character.

Returns:boolean

a flag indicating whether values containing quotes should be enclosed in quotes.

quoteFieldsback to summary
public final FieldSet<Enum<E extends Enum<E>>> quoteFields(Enum<E extends Enum<E>>... columns)

Selects fields whose values should always be written within quotes

Parameters
columns:Enum<E extends Enum<E>>[]

a selection of columns that will always be quoted

Returns:FieldSet<Enum<E extends Enum<E>>>

the (modifiable) set of selected fields to be quoted.

quoteFieldsback to summary
public final FieldSet<String> quoteFields(String... columns)

Selects fields whose values should always be written within quotes

Parameters
columns:String[]

a selection of columns that will always be quoted

Returns:FieldSet<String>

the (modifiable) set of selected fields to be quoted.

quoteIndexesback to summary
public final FieldSet<Integer> quoteIndexes(Integer... columns)

Selects field positions whose values should always be written within quotes

Parameters
columns:Integer[]

a selection of column indexes that will always be quoted

Returns:FieldSet<Integer>

the (modifiable) set of column positions to be quoted.

setEscapeUnquotedValuesback to summary
public void setEscapeUnquotedValues(boolean escapeUnquotedValues)

Configures the writer to process escape sequences in unquoted values. Defaults to false.

By default, this is disabled and if the input is A""B,C, the result will be written as [A""B] and [C] (i.e. the quotes written as-is). However, if the writer is configured to process escape sequences in unquoted values, the values will written as [A""""B] and [C]

Parameters
escapeUnquotedValues:boolean

a flag indicating whether escape sequences should be processed in unquoted values

setFieldSetback to summary
private <T> FieldSet<T> setFieldSet(FieldSet<T> fieldSet, T... values)

Hides com.univocity.parsers.common.CommonSettings.setFieldSet.

Replaces the current quoted field selection

Parameters
fieldSet:FieldSet<T>

the new set of selected fields

values:T[]

the values to include to the selection

Returns:FieldSet<T>

the set of selected fields given in as a parameter.

setInputEscapedback to summary
public final void setInputEscaped(boolean isInputEscaped)

Configures the writer to prevent it to introduce escape sequences. The writer will assume the user is providing escaped input, and it will be written as-is.

Warning

ensure your data is properly escaped, otherwise the writer will produce invalid CSV.

This is disabled by default

Parameters
isInputEscaped:boolean

a flag indicating whether the input that will be written is already properly escaped.

setNormalizeLineEndingsWithinQuotesback to summary
public void setNormalizeLineEndingsWithinQuotes(boolean normalizeLineEndingsWithinQuotes)

Flag indicating whether the writer should replace the the normalized line separator character specified in Format#getNormalizedNewline() by the sequence specified in Format#getLineSeparator(), when the value is enclosed within quotes. This is enabled by default and is used to ensure data can be used on any platform without producing unrecognized line endings. For example, consider the quoted value "Line1 \n Line2". If this is written using "\r\n" as the line separator sequence, and the normalized new line is set to '\n' (the default), the output will be: [Line1 \r\n Line2] However, if the value is meant to be kept untouched, and the original line separator should be maintained, set the normalizeLineEndingsWithinQuotes to false. This will make the writer output the value as-is, producing: [Line1 \n Line2]

Parameters
normalizeLineEndingsWithinQuotes:boolean

flag indicating that line separator characters in quoted values should be considered 'normalized' and occurrences of Format#getNormalizedNewline() should be replaced by the sequence specified in Format#getLineSeparator()

setQuotationTriggersback to summary
public void setQuotationTriggers(char... quotationTriggers)

Defines one or more "triggers" for enclosing a value within quotes. If one of the characters in the quotation trigger list is found in a value to be written, the entire value will be enclosed in quotes.

Parameters
quotationTriggers:char[]

a list of characters that when present in a value to be written, will force the output value to be enclosed in quotes.

setQuoteAllFieldsback to summary
public void setQuoteAllFields(boolean quoteAllFields)

Indicates indicates whether or not all written values should be enclosed within quotes (as defined in CsvFormat)

(Defaults to false)

By default, only values that contain a field separator are enclosed within quotes.

Parameters
quoteAllFields:boolean

a flag indicating whether to enclose all fields within quotes

setQuoteEscapingEnabledback to summary
public void setQuoteEscapingEnabled(boolean quoteEscapingEnabled)

Configures the CSV writer to escape values that contain the quote character, by enclosing the entire value in quotes. For example, consider a value such as [My "precious" value]. When quote escaping is enabled, the output will be: ["My ""precious"" value"] If disabled (the default), the value will be written as-is. Note that the CSV output will not conform to the RFC 4180 standard, but it will still be valid as the value does not contain line separators nor the delimiter character.

Parameters
quoteEscapingEnabled:boolean

a flag indicating whether values containing quotes should be enclosed in quotes.

setQuoteNullsback to summary
public void setQuoteNulls(boolean quoteNulls)

Configures whether to quote null values sent to the CsvWriter when the corresponding column is configured to be quoted via quoteFields(String...), or getQuoteAllFields() evaluates to true.

Parameters
quoteNulls:boolean

flag indicating whether null values should be quoted.