Class CommonWriterSettings<F extends Format>
- java.lang.Object
-
- com.univocity.parsers.common.CommonSettings<F>
-
- com.univocity.parsers.common.CommonWriterSettings<F>
-
- Type Parameters:
F- the format supported by this writer.
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
CsvWriterSettings,FixedWidthWriterSettings,TsvWriterSettings
public abstract class CommonWriterSettings<F extends Format> extends CommonSettings<F>
This is the parent class for all configuration classes used by writers (AbstractWriter)By default, all writers work with, at least, the following configuration options in addition to the ones provided by
CommonSettings:- rowWriterProcessor: a implementation of the interface
RowWriterProcessorwhich processes input objects into a manageable format for writing.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancolumnReorderingEnabledprivate java.lang.StringemptyValueprivate booleanexpandIncompleteRowsprivate java.lang.BooleanheaderWritingEnabledprivate RowWriterProcessor<?>rowWriterProcessor-
Fields inherited from class com.univocity.parsers.common.CommonSettings
headerSourceClass
-
-
Constructor Summary
Constructors Constructor Description CommonWriterSettings()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddConfiguration(java.util.Map<java.lang.String,java.lang.Object> out)protected voidclearInputSpecificSettings()Clears settings that are likely to be specific to a given input.protected CommonWriterSettingsclone()Clones this configuration object.protected CommonWriterSettingsclone(boolean clearInputSpecificSettings)Clones this configuration object to reuse user-provided settings.protected voidconfigureFromAnnotations(java.lang.Class<?> beanClass)Configures the writer based on the annotations provided in a given classjava.lang.StringgetEmptyValue()Returns the String representation of an empty value (defaults to null)booleangetExpandIncompleteRows()Indicates whether the writer should expand records with less columns than the number of headers.RowWriterProcessor<?>getRowWriterProcessor()Returns the implementation of the interfaceRowWriterProcessorwhich processes input objects into a manageable format for writing.booleanisColumnReorderingEnabled()Indicates whether fields selected using the field selection methods (defined by the parent classCommonSettings) should be reordered (defaults to false).booleanisHeaderWritingEnabled()Returns a flag indicating whether automatic writing of headers is enabled.(package private) voidrunAutomaticConfiguration()voidsetColumnReorderingEnabled(boolean columnReorderingEnabled)Defines whether fields selected using the field selection methods (defined by the parent classCommonSettings) should be reordered (defaults to false).voidsetEmptyValue(java.lang.String emptyValue)Sets the String representation of an empty value (defaults to null)voidsetExpandIncompleteRows(boolean expandIncompleteRows)Defines whether the writer should expand records with less columns than the number of headers.voidsetHeaderWritingEnabled(boolean headerWritingEnabled)Enables automatic writing of headers when they are available.voidsetRowWriterProcessor(RowWriterProcessor<?> rowWriterProcessor)Defines a processor for input objects that converts them into a manageable format for writing.-
Methods inherited from class com.univocity.parsers.common.CommonSettings
autoConfigure, createDefaultFormat, deriveHeadersFrom, excludeFields, excludeFields, excludeIndexes, getErrorContentLength, getFieldSelector, getFieldSet, getFormat, getHeaders, getIgnoreLeadingWhitespaces, getIgnoreTrailingWhitespaces, getMaxCharsPerColumn, getMaxColumns, getNullValue, getProcessorErrorHandler, getRowProcessorErrorHandler, getSkipBitsAsWhitespace, getSkipEmptyLines, getWhitespaceRangeStart, isAutoConfigurationEnabled, isProcessorErrorHandlerDefined, selectFields, selectFields, selectIndexes, setAutoConfigurationEnabled, setErrorContentLength, setFormat, setHeaders, setHeadersDerivedFromClass, setIgnoreLeadingWhitespaces, setIgnoreTrailingWhitespaces, setMaxCharsPerColumn, setMaxColumns, setNullValue, setProcessorErrorHandler, setRowProcessorErrorHandler, setSkipBitsAsWhitespace, setSkipEmptyLines, toString, trimValues
-
-
-
-
Field Detail
-
rowWriterProcessor
private RowWriterProcessor<?> rowWriterProcessor
-
headerWritingEnabled
private java.lang.Boolean headerWritingEnabled
-
emptyValue
private java.lang.String emptyValue
-
expandIncompleteRows
private boolean expandIncompleteRows
-
columnReorderingEnabled
private boolean columnReorderingEnabled
-
-
Method Detail
-
getEmptyValue
public java.lang.String getEmptyValue()
Returns the String representation of an empty value (defaults to null)When writing, if the writer has an empty String to write to the output, the emptyValue is used instead of an empty string
- Returns:
- the String representation of an empty value
-
setEmptyValue
public void setEmptyValue(java.lang.String emptyValue)
Sets the String representation of an empty value (defaults to null)If the writer has an empty String to write to the output, the emptyValue is used instead of an empty string
- Parameters:
emptyValue- the String representation of an empty value
-
getRowWriterProcessor
public RowWriterProcessor<?> getRowWriterProcessor()
Returns the implementation of the interfaceRowWriterProcessorwhich processes input objects into a manageable format for writing.- Returns:
- the implementation of the interface
RowWriterProcessorwhich processes input objects into a manageable format for writing. - See Also:
ObjectRowWriterProcessor,BeanWriterProcessor
-
setRowWriterProcessor
public void setRowWriterProcessor(RowWriterProcessor<?> rowWriterProcessor)
Defines a processor for input objects that converts them into a manageable format for writing.- Parameters:
rowWriterProcessor- the implementation of the interfaceRowWriterProcessorwhich processes input objects into a manageable format for writing.- See Also:
ObjectRowWriterProcessor,BeanWriterProcessor
-
isHeaderWritingEnabled
public final boolean isHeaderWritingEnabled()
Returns a flag indicating whether automatic writing of headers is enabled. If enabled, and headers are defined (or derived automatically ifCommonSettings.isAutoConfigurationEnabled()evaluates totrue), the writer will invoke theAbstractWriter.writeHeaders()method automatically. In this case, attempting to explicitly write the headers will result in aTextWritingException.Defaults to
false- Returns:
- returns
trueif automatic header writing is enabled, otherwise false.
-
setHeaderWritingEnabled
public final void setHeaderWritingEnabled(boolean headerWritingEnabled)
Enables automatic writing of headers when they are available. If enabled, and headers are defined (or derived automatically ifCommonSettings.isAutoConfigurationEnabled()evaluates totrue), the writer will invoke theAbstractWriter.writeHeaders()method automatically. In this case, attempting to explicitly write the headers will result in aTextWritingException.Defaults to
false- Parameters:
headerWritingEnabled- a flag to enable or disable automatic header writing.
-
getExpandIncompleteRows
public final boolean getExpandIncompleteRows()
Indicates whether the writer should expand records with less columns than the number of headers. For example, if the writer is using "A,B,C" as the headers, and the user provides a row with "V1,V2", thennullwill be introduced in column C, generating the output "V1,V2,null".Defaults to
false- Returns:
- a flag indicating whether records with less columns than the number of headers are to be expanded with nulls.
-
setExpandIncompleteRows
public final void setExpandIncompleteRows(boolean expandIncompleteRows)
Defines whether the writer should expand records with less columns than the number of headers. For example, if the writer is using "A,B,C" as the headers, and the user provides a row with "V1,V2", thennullwill be introduced in column C, generating the output "V1,V2,null".Defaults to
false- Parameters:
expandIncompleteRows- a flag indicating whether records with less columns than the number of headers are to be expanded with nulls.
-
addConfiguration
protected void addConfiguration(java.util.Map<java.lang.String,java.lang.Object> out)
- Overrides:
addConfigurationin classCommonSettings<F extends Format>
-
runAutomaticConfiguration
final void runAutomaticConfiguration()
- Overrides:
runAutomaticConfigurationin classCommonSettings<F extends Format>
-
configureFromAnnotations
protected void configureFromAnnotations(java.lang.Class<?> beanClass)
Configures the writer based on the annotations provided in a given class- Parameters:
beanClass- the classes whose annotations will be processed to derive configurations for writing.
-
clone
protected CommonWriterSettings clone(boolean clearInputSpecificSettings)
Description copied from class:CommonSettingsClones 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 theclearInputSpecificSettingsflag is set totrue- Overrides:
clonein classCommonSettings<F extends Format>- Parameters:
clearInputSpecificSettings- flag indicating whether to clear settings that are likely to be associated with a given input.- Returns:
- a copy of the configurations applied to the current instance.
-
clone
protected CommonWriterSettings clone()
Description copied from class:CommonSettingsClones this configuration object. Use alternativeCommonSettings.clone(boolean)method to reset properties that are specific to a given input, such as header names and selection of fields.- Overrides:
clonein classCommonSettings<F extends Format>- Returns:
- a copy of all configurations applied to the current instance.
-
clearInputSpecificSettings
protected void clearInputSpecificSettings()
Description copied from class:CommonSettingsClears settings that are likely to be specific to a given input.- Overrides:
clearInputSpecificSettingsin classCommonSettings<F extends Format>
-
isColumnReorderingEnabled
public boolean isColumnReorderingEnabled()
Indicates whether fields selected using the field selection methods (defined by the parent classCommonSettings) should be reordered (defaults to false).When disabled, each written record will contain values for all columns, in the order they are sent to the writer. Fields which were not selected will not be written but and the record will contain empty values.
When enabled, each written record will contain values only for the selected columns. The values will be ordered according to the selection.
- Returns:
- true if the selected fields should be reordered when writing with field selection enabled, false otherwise
-
setColumnReorderingEnabled
public void setColumnReorderingEnabled(boolean columnReorderingEnabled)
Defines whether fields selected using the field selection methods (defined by the parent classCommonSettings) should be reordered (defaults to false).When disabled, each written record will contain values for all columns, in the order they are sent to the writer. Fields which were not selected will not be written but and the record will contain empty values.
When enabled, each written record will contain values only for the selected columns. The values will be ordered according to the selection.
- Parameters:
columnReorderingEnabled- the flag indicating whether or not selected fields should be reordered and written by the writer
-
-