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

public abstract Class CommonSettings<F extends Format>

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.univocity.parsers.common.CommonWriterSettings, com.univocity.parsers.common.CommonParserSettings
Type Parameters
<F>
the format supported by this settings class.
Imports
com.univocity.parsers.annotations.*, com.univocity.parsers.common.fields.*, com.univocity.parsers.common.processor.*, java.util.*, java.util.Map.*

This is the parent class for all configuration classes used by parsers (AbstractParser) and writers (AbstractWriter)

By default, all parsers and writers work with, at least, the following configuration options:

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.common.CommonParserSettings, com.univocity.parsers.common.CommonWriterSettings, com.univocity.parsers.csv.CsvParserSettings, com.univocity.parsers.csv.CsvWriterSettings, com.univocity.parsers.fixed.FixedWidthParserSettings, com.univocity.parsers.fixed.FixedWidthWriterSettings

Field Summary

Modifier and TypeField and Description
private boolean
private int
private ProcessorErrorHandler<? extends Context>
private FieldSelector
private F
private String[]
pack-priv Class<?>
private boolean
private boolean
private int
private int
private String
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
CommonSettings()

Creates a new instance of this settings object using the default format specified by the concrete class that inherits from CommonSettings

Method Summary

Modifier and TypeMethod and Description
protected void
pack-priv final void
protected void
clearInputSpecificSettings()

Clears settings that are likely to be specific to a given input.

protected CommonSettings<F extends Format>

Returns:

a copy of the configurations applied to the current instance.
clone
(boolean
flag indicating whether to clear settings that are likely to be associated with a given input.
clearInputSpecificSettings
)

Clones this configuration object to reuse user-provided settings.

protected CommonSettings<F extends Format>

Returns:

a copy of all configurations applied to the current instance.
clone
()

Overrides java.lang.Object.clone.

Clones this configuration object.
protected abstract F

Returns:

Default format configuration for the given parser/writer settings.
createDefaultFormat
()

Extending classes must implement this method to return the default format settings for their parser/writer

pack-priv boolean

Returns:

true if the headers used for parsing/writing should be derived from the given class; otherwise false
deriveHeadersFrom
(Class<?>
the class to derive headers from
beanClass
)

Indicates whether headers should be derived from a given class.

public FieldSet<String>

Returns:

the (modifiable) set of ignored fields
excludeFields
(String...
The field names to exclude from the parsing/writing process
fieldNames
)

Selects fields which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored.

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

Returns:

the (modifiable) set of ignored fields
excludeFields
(Enum<E extends Enum<E>>...
The columns to exclude from the parsing/writing process
columns
)

Selects columns which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored.

public FieldSet<Integer>

Returns:

the (modifiable) set of ignored fields
excludeIndexes
(Integer...
indexes of columns to exclude from the parsing/writing process
fieldIndexes
)

Selects columns which will not be read/written, by their positions

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored.

public int

Returns:

the maximum length of contents displayed in exception messages in case of errors while parsing/writing.
getErrorContentLength
()

Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs

If set to 0, then no exceptions will include the content being manipulated in their attributes, and the "<omitted>" string will appear in error messages as the parsed/written content.

pack-priv FieldSelector

Returns:

the FieldSelector object, which handles selected fields. Null if no field was selected/excluded
getFieldSelector
()

Returns the FieldSelector object, which handles selected fields.

pack-priv FieldSet<?>

Returns:

the set of selected fields. Null if no field was selected/excluded
getFieldSet
()

Returns the set of selected fields, if any

public F

Returns:

The format of the file to be parsed/written
getFormat
()

The format of the file to be parsed/written (returns the format's defaults).

public String[]

Returns:

the field name sequence associated with each column in the input/output.
getHeaders
()

Returns the field names in the input/output, in the sequence they occur (defaults to null).

public boolean

Returns:

true if leading whitespaces from values being read/written should be skipped, false otherwise
getIgnoreLeadingWhitespaces
()

Returns whether or not leading whitespaces from values being read/written should be skipped (defaults to true)

public boolean

Returns:

true if trailing whitespaces from values being read/written should be skipped, false otherwise
getIgnoreTrailingWhitespaces
()

Returns whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)

public int

Returns:

The maximum number of characters allowed for any given value being written/read
getMaxCharsPerColumn
()

The maximum number of characters allowed for any given value being written/read.

public int

Returns:

The maximum number of columns a record can have.
getMaxColumns
()

Returns the hard limit of how many columns a record can have (defaults to 512).

public String

Returns:

the String representation of a null value
getNullValue
()

Returns the String representation of a null value (defaults to null)

When reading, if the parser does not read any character from the input, the nullValue is used instead of an empty string

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty string

public <
the Context type provided by the parser implementation.
T extends Context
>
ProcessorErrorHandler<T>

Returns:

the callback error handler with custom code to manage occurrences of DataProcessingException.
getProcessorErrorHandler
()

Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a com.univocity.parsers.common.processor.core.Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

public RowProcessorErrorHandler

Returns:

the callback error handler with custom code to manage occurrences of DataProcessingException.
getRowProcessorErrorHandler
()

Deprecated Use the getProcessorErrorHandler() method as it allows format-specific error handlers to be built to work with different implementations of Context.
Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a RowProcessor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).
public final boolean

Returns:

a flag indicating whether bit values (0 or 1) should be considered whitespace.
getSkipBitsAsWhitespace
()

Returns a flag indicating whether the parser/writer should skip bit values as whitespace.

public boolean

Returns:

true if empty lines are configured to be ignored, false otherwise
getSkipEmptyLines
()

Returns whether or not empty lines should be ignored (defaults to true)

when reading, if the parser reads a line that is empty, it will be skipped.

protected final int

Returns:

the starting range after which characters will be considered whitespace
getWhitespaceRangeStart
()

Returns the starting decimal range for characters <= ' ' that should be skipped as whitespace, as determined by getSkipBitsAsWhitespace()

public final boolean

Returns:

true if the automatic configuration feature is enabled, false otherwise
isAutoConfigurationEnabled
()

Indicates whether this settings object can automatically derive configuration options.

public boolean

Returns:

true if the parser/writer is configured to use a ProcessorErrorHandler
isProcessorErrorHandlerDefined
()

Returns a flag indicating whether or not a ProcessorErrorHandler has been defined through the use of method setProcessorErrorHandler(ProcessorErrorHandler)

pack-priv void
public FieldSet<String>

Returns:

the (modifiable) set of selected fields
selectFields
(String...
The field names to read/write
fieldNames
)

Selects a sequence of fields for reading/writing by their names.

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

Returns:

the (modifiable) set of selected fields
selectFields
(Enum<E extends Enum<E>>...
The columns to read/write
columns
)

Selects a sequence of fields for reading/writing by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored.

public FieldSet<Integer>

Returns:

the (modifiable) set of selected fields
selectIndexes
(Integer...
The indexes to read/write
fieldIndexes
)

Selects a sequence of fields for reading/writing by their positions.

public final void
setAutoConfigurationEnabled(boolean
a flag to turn the automatic configuration feature on/off.
autoConfigurationEnabled
)

Indicates whether this settings object can automatically derive configuration options.

public void
setErrorContentLength(int
maximum length of contents displayed in exception messages in case of errors while parsing/writing.
errorContentLength
)

Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs.

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
)

Replaces the current field selection

public void
setFormat(F
The format of the file to be parsed/written
format
)

Defines the format of the file to be parsed/written (returns the format's defaults).

public void
setHeaders(String...
the field name sequence associated with each column in the input/output.
headers
)

Defines the field names in the input/output, in the sequence they occur (defaults to null).

pack-priv void
setHeadersDerivedFromClass(Class<?>
the class from which the headers have been derived.
headerSourceClass
,
String...
the field name sequence associated with each column in the input/output.
headers
)

Defines the field names in the input/output derived from a given class with Parsed annotated attributes/methods.

public void
setIgnoreLeadingWhitespaces(boolean
true if leading whitespaces from values being read/written should be skipped, false otherwise
ignoreLeadingWhitespaces
)

Defines whether or not leading whitespaces from values being read/written should be skipped (defaults to true)

public void
setIgnoreTrailingWhitespaces(boolean
true if trailing whitespaces from values being read/written should be skipped, false otherwise
ignoreTrailingWhitespaces
)

Defines whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)

public void
setMaxCharsPerColumn(int
The maximum number of characters allowed for any given value being written/read
maxCharsPerColumn
)

Defines the maximum number of characters allowed for any given value being written/read.

public void
setMaxColumns(int
The maximum number of columns a record can have.
maxColumns
)

Defines a hard limit of how many columns a record can have (defaults to 512).

public void
setNullValue(String
the String representation of a null value
emptyValue
)

Sets the String representation of a null value (defaults to null)

When reading, if the parser does not read any character from the input, the nullValue is used instead of an empty string

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty string

public void
setProcessorErrorHandler(ProcessorErrorHandler<? extends Context>
the callback error handler with custom code to manage occurrences of DataProcessingException.
processorErrorHandler
)

Defines a custom error handler to capture and handle errors that might happen while processing records with a com.univocity.parsers.common.processor.core.Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

public void
setRowProcessorErrorHandler(RowProcessorErrorHandler
the callback error handler with custom code to manage occurrences of DataProcessingException.
rowProcessorErrorHandler
)

Deprecated Use the setProcessorErrorHandler(ProcessorErrorHandler) method as it allows format-specific error handlers to be built to work with different implementations of Context.
Defines a custom error handler to capture and handle errors that might happen while processing records with a RowProcessor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).
public final void
setSkipBitsAsWhitespace(boolean
a flag indicating whether bit values (0 or 1) should be considered whitespace.
skipBitsAsWhitespace
)

Configures the parser to skip bit values as whitespace.

public void
setSkipEmptyLines(boolean
true if empty lines should be ignored, false otherwise
skipEmptyLines
)

Defines whether or not empty lines should be ignored (defaults to true)

when reading, if the parser reads a line that is empty, it will be skipped.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final void
trimValues(boolean
a flag indicating whether the whitespaces should remove whitespaces around values parsed/written.
trim
)

Configures the parser/writer to trim or keep leading and trailing whitespaces around values This has the same effect as invoking both setIgnoreLeadingWhitespaces(boolean) and setIgnoreTrailingWhitespaces(boolean) with the same value.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

autoConfigurationEnabledback to summary
private boolean autoConfigurationEnabled
errorContentLengthback to summary
private int errorContentLength
errorHandlerback to summary
private ProcessorErrorHandler<? extends Context> errorHandler
fieldSelectorback to summary
private FieldSelector fieldSelector
formatback to summary
private F format
headersback to summary
private String[] headers
headerSourceClassback to summary
pack-priv Class<?> headerSourceClass
ignoreLeadingWhitespacesback to summary
private boolean ignoreLeadingWhitespaces
ignoreTrailingWhitespacesback to summary
private boolean ignoreTrailingWhitespaces
maxCharsPerColumnback to summary
private int maxCharsPerColumn
maxColumnsback to summary
private int maxColumns
nullValueback to summary
private String nullValue
skipBitsAsWhitespaceback to summary
private boolean skipBitsAsWhitespace
skipEmptyLinesback to summary
private boolean skipEmptyLines

Constructor Detail

CommonSettingsback to summary
public CommonSettings()

Creates a new instance of this settings object using the default format specified by the concrete class that inherits from CommonSettings

Method Detail

addConfigurationback to summary
protected void addConfiguration(Map<String, Object> out)
autoConfigureback to summary
pack-priv final void autoConfigure()
clearInputSpecificSettingsback to summary
protected void clearInputSpecificSettings()

Clears settings that are likely to be specific to a given input.

cloneback to summary
protected CommonSettings<F extends Format> clone(boolean clearInputSpecificSettings)

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:CommonSettings<F extends Format>

a copy of the configurations applied to the current instance.

cloneback to summary
protected CommonSettings<F extends Format> clone()

Overrides java.lang.Object.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:CommonSettings<F extends Format>

a copy of all configurations applied to the current instance.

Annotations
@Override
createDefaultFormatback to summary
protected abstract F createDefaultFormat()

Extending classes must implement this method to return the default format settings for their parser/writer

Returns:F

Default format configuration for the given parser/writer settings.

deriveHeadersFromback to summary
pack-priv boolean deriveHeadersFrom(Class<?> beanClass)

Indicates whether headers should be derived from a given class.

Parameters
beanClass:Class<?>

the class to derive headers from

Returns:boolean

true if the headers used for parsing/writing should be derived from the given class; otherwise false

excludeFieldsback to summary
public FieldSet<String> excludeFields(String... fieldNames)

Selects fields which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters
fieldNames:String[]

The field names to exclude from the parsing/writing process

Returns:FieldSet<String>

the (modifiable) set of ignored fields

excludeFieldsback to summary
public FieldSet<Enum<E extends Enum<E>>> excludeFields(Enum<E extends Enum<E>>... columns)

Selects columns which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

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

The columns to exclude from the parsing/writing process

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

the (modifiable) set of ignored fields

Annotations
@SuppressWarnings:rawtypes
excludeIndexesback to summary
public FieldSet<Integer> excludeIndexes(Integer... fieldIndexes)

Selects columns which will not be read/written, by their positions

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields by index, such as "2" and "0" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters
fieldIndexes:Integer[]

indexes of columns to exclude from the parsing/writing process

Returns:FieldSet<Integer>

the (modifiable) set of ignored fields

getErrorContentLengthback to summary
public int getErrorContentLength()

Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs

If set to 0, then no exceptions will include the content being manipulated in their attributes, and the "<omitted>" string will appear in error messages as the parsed/written content.

defaults to -1 (no limit)

.
Returns:int

the maximum length of contents displayed in exception messages in case of errors while parsing/writing.

getFieldSelectorback to summary
pack-priv FieldSelector getFieldSelector()

Returns the FieldSelector object, which handles selected fields.

Returns:FieldSelector

the FieldSelector object, which handles selected fields. Null if no field was selected/excluded

getFieldSetback to summary
pack-priv FieldSet<?> getFieldSet()

Returns the set of selected fields, if any

Returns:FieldSet<?>

the set of selected fields. Null if no field was selected/excluded

getFormatback to summary
public F getFormat()

The format of the file to be parsed/written (returns the format's defaults).

Returns:F

The format of the file to be parsed/written

getHeadersback to summary
public String[] getHeaders()

Returns the field names in the input/output, in the sequence they occur (defaults to null).

when reading, the given header names will be used to refer to each column irrespective of whether or not the input contains a header row

when writing, the given header names will be used to refer to each column and can be used for writing the header row

Returns:String[]

the field name sequence associated with each column in the input/output.

getIgnoreLeadingWhitespacesback to summary
public boolean getIgnoreLeadingWhitespaces()

Returns whether or not leading whitespaces from values being read/written should be skipped (defaults to true)

Returns:boolean

true if leading whitespaces from values being read/written should be skipped, false otherwise

getIgnoreTrailingWhitespacesback to summary
public boolean getIgnoreTrailingWhitespaces()

Returns whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)

Returns:boolean

true if trailing whitespaces from values being read/written should be skipped, false otherwise

getMaxCharsPerColumnback to summary
public int getMaxCharsPerColumn()

The maximum number of characters allowed for any given value being written/read. Used to avoid OutOfMemoryErrors (defaults to 4096).

If set to -1, then the internal internal array will expand automatically, up to the limit allowed by the JVM

Returns:int

The maximum number of characters allowed for any given value being written/read

getMaxColumnsback to summary
public int getMaxColumns()

Returns the hard limit of how many columns a record can have (defaults to 512). You need this to avoid OutOfMemory errors in case of inputs that might be inconsistent with the format you are dealing with .

Returns:int

The maximum number of columns a record can have.

getNullValueback to summary
public String getNullValue()

Returns the String representation of a null value (defaults to null)

When reading, if the parser does not read any character from the input, the nullValue is used instead of an empty string

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty string

Returns:String

the String representation of a null value

getProcessorErrorHandlerback to summary
public <T extends Context> ProcessorErrorHandler<T> getProcessorErrorHandler()

Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a com.univocity.parsers.common.processor.core.Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing/writing process won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Parameters
<T>
the Context type provided by the parser implementation.
Returns:ProcessorErrorHandler<T>

the callback error handler with custom code to manage occurrences of DataProcessingException.

getRowProcessorErrorHandlerback to summary
public RowProcessorErrorHandler getRowProcessorErrorHandler()

Deprecated

Use the getProcessorErrorHandler() method as it allows format-specific error handlers to be built to work with different implementations of Context. Implementations based on RowProcessorErrorHandler allow only parsers who provide a ParsingContext to be used.

Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a RowProcessor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing/writing process won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Returns:RowProcessorErrorHandler

the callback error handler with custom code to manage occurrences of DataProcessingException.

Annotations
@Deprecated
getSkipBitsAsWhitespaceback to summary
public final boolean getSkipBitsAsWhitespace()

Returns a flag indicating whether the parser/writer should skip bit values as whitespace. By default the parser/writer removes control characters and considers a whitespace any character where character <= ' ' evaluates to true. This includes bit values, i.e. 0 (the \0 character) and 1 which might be produced by database dumps. Disabling this flag will prevent the parser/writer from discarding these characters when getIgnoreLeadingWhitespaces() or getIgnoreTrailingWhitespaces() evaluate to true.

defaults to true

Returns:boolean

a flag indicating whether bit values (0 or 1) should be considered whitespace.

getSkipEmptyLinesback to summary
public boolean getSkipEmptyLines()

Returns whether or not empty lines should be ignored (defaults to true)

when reading, if the parser reads a line that is empty, it will be skipped.

when writing, if the writer receives an empty or null row to write to the output, it will be ignored

Returns:boolean

true if empty lines are configured to be ignored, false otherwise

getWhitespaceRangeStartback to summary
protected final int getWhitespaceRangeStart()

Returns the starting decimal range for characters <= ' ' that should be skipped as whitespace, as determined by getSkipBitsAsWhitespace()

Returns:int

the starting range after which characters will be considered whitespace

isAutoConfigurationEnabledback to summary
public final boolean isAutoConfigurationEnabled()

Indicates whether this settings object can automatically derive configuration options. This is used, for example, to define the headers when the user provides a BeanWriterProcessor where the bean class contains a Headers annotation, or to enable header extraction when the bean class of a BeanProcessor has attributes mapping to header names.

Defaults to true

Returns:boolean

true if the automatic configuration feature is enabled, false otherwise

isProcessorErrorHandlerDefinedback to summary
public boolean isProcessorErrorHandlerDefined()

Returns a flag indicating whether or not a ProcessorErrorHandler has been defined through the use of method setProcessorErrorHandler(ProcessorErrorHandler)

Returns:boolean

true if the parser/writer is configured to use a ProcessorErrorHandler

runAutomaticConfigurationback to summary
pack-priv void runAutomaticConfiguration()
selectFieldsback to summary
public FieldSet<String> selectFields(String... fieldNames)

Selects a sequence of fields for reading/writing by their names.

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters
fieldNames:String[]

The field names to read/write

Returns:FieldSet<String>

the (modifiable) set of selected fields

selectFieldsback to summary
public FieldSet<Enum<E extends Enum<E>>> selectFields(Enum<E extends Enum<E>>... columns)

Selects a sequence of fields for reading/writing by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

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

The columns to read/write

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

the (modifiable) set of selected fields

Annotations
@SuppressWarnings:rawtypes
selectIndexesback to summary
public FieldSet<Integer> selectIndexes(Integer... fieldIndexes)

Selects a sequence of fields for reading/writing by their positions.

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set CommonParserSettings#setColumnReorderingEnabled(boolean) with false.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting indexes "2" and "0" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters
fieldIndexes:Integer[]

The indexes to read/write

Returns:FieldSet<Integer>

the (modifiable) set of selected fields

setAutoConfigurationEnabledback to summary
public final void setAutoConfigurationEnabled(boolean autoConfigurationEnabled)

Indicates whether this settings object can automatically derive configuration options. This is used, for example, to define the headers when the user provides a BeanWriterProcessor where the bean class contains a Headers annotation, or to enable header extraction when the bean class of a BeanProcessor has attributes mapping to header names.

Parameters
autoConfigurationEnabled:boolean

a flag to turn the automatic configuration feature on/off.

setErrorContentLengthback to summary
public void setErrorContentLength(int errorContentLength)

Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs.

If set to 0, then no exceptions will include the content being manipulated in their attributes, and the "<omitted>" string will appear in error messages as the parsed/written content.

defaults to -1 (no limit)

.
Parameters
errorContentLength:int

maximum length of contents displayed in exception messages in case of errors while parsing/writing.

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

Replaces the current 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.

setFormatback to summary
public void setFormat(F format)

Defines the format of the file to be parsed/written (returns the format's defaults).

Parameters
format:F

The format of the file to be parsed/written

setHeadersback to summary
public void setHeaders(String... headers)

Defines the field names in the input/output, in the sequence they occur (defaults to null).

when reading, the given header names will be used to refer to each column irrespective of whether or not the input contains a header row

when writing, the given header names will be used to refer to each column and can be used for writing the header row

Parameters
headers:String[]

the field name sequence associated with each column in the input/output.

setHeadersDerivedFromClassback to summary
pack-priv void setHeadersDerivedFromClass(Class<?> headerSourceClass, String... headers)

Defines the field names in the input/output derived from a given class with Parsed annotated attributes/methods.

when reading, the given header names will be used to refer to each column irrespective of whether or not the input contains a header row

when writing, the given header names will be used to refer to each column and can be used for writing the header row

Parameters
headerSourceClass:Class<?>

the class from which the headers have been derived.

headers:String[]

the field name sequence associated with each column in the input/output.

setIgnoreLeadingWhitespacesback to summary
public void setIgnoreLeadingWhitespaces(boolean ignoreLeadingWhitespaces)

Defines whether or not leading whitespaces from values being read/written should be skipped (defaults to true)

Parameters
ignoreLeadingWhitespaces:boolean

true if leading whitespaces from values being read/written should be skipped, false otherwise

setIgnoreTrailingWhitespacesback to summary
public void setIgnoreTrailingWhitespaces(boolean ignoreTrailingWhitespaces)

Defines whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)

Parameters
ignoreTrailingWhitespaces:boolean

true if trailing whitespaces from values being read/written should be skipped, false otherwise

setMaxCharsPerColumnback to summary
public void setMaxCharsPerColumn(int maxCharsPerColumn)

Defines the maximum number of characters allowed for any given value being written/read. Used to avoid OutOfMemoryErrors (defaults to 4096).

To enable auto-expansion of the internal array, set this property to -1

Parameters
maxCharsPerColumn:int

The maximum number of characters allowed for any given value being written/read

setMaxColumnsback to summary
public void setMaxColumns(int maxColumns)

Defines a hard limit of how many columns a record can have (defaults to 512). You need this to avoid OutOfMemory errors in case of inputs that might be inconsistent with the format you are dealing with.

Parameters
maxColumns:int

The maximum number of columns a record can have.

setNullValueback to summary
public void setNullValue(String emptyValue)

Sets the String representation of a null value (defaults to null)

When reading, if the parser does not read any character from the input, the nullValue is used instead of an empty string

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty string

Parameters
emptyValue:String

the String representation of a null value

setProcessorErrorHandlerback to summary
public void setProcessorErrorHandler(ProcessorErrorHandler<? extends Context> processorErrorHandler)

Defines a custom error handler to capture and handle errors that might happen while processing records with a com.univocity.parsers.common.processor.core.Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing parsing/writing won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Parameters
processorErrorHandler:ProcessorErrorHandler<? extends Context>

the callback error handler with custom code to manage occurrences of DataProcessingException.

setRowProcessorErrorHandlerback to summary
public void setRowProcessorErrorHandler(RowProcessorErrorHandler rowProcessorErrorHandler)

Deprecated

Use the setProcessorErrorHandler(ProcessorErrorHandler) method as it allows format-specific error handlers to be built to work with different implementations of Context. Implementations based on RowProcessorErrorHandler allow only parsers who provide a ParsingContext to be used.

Defines a custom error handler to capture and handle errors that might happen while processing records with a RowProcessor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing parsing/writing won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Parameters
rowProcessorErrorHandler:RowProcessorErrorHandler

the callback error handler with custom code to manage occurrences of DataProcessingException.

Annotations
@Deprecated
setSkipBitsAsWhitespaceback to summary
public final void setSkipBitsAsWhitespace(boolean skipBitsAsWhitespace)

Configures the parser to skip bit values as whitespace. By default the parser/writer removes control characters and considers a whitespace any character where character <= ' ' evaluates to true. This includes bit values, i.e. 0 (the \0 character) and 1 which might be produced by database dumps. Disabling this flag will prevent the parser/writer from discarding these characters when getIgnoreLeadingWhitespaces() or getIgnoreTrailingWhitespaces() evaluate to true.

defaults to true

Parameters
skipBitsAsWhitespace:boolean

a flag indicating whether bit values (0 or 1) should be considered whitespace.

setSkipEmptyLinesback to summary
public void setSkipEmptyLines(boolean skipEmptyLines)

Defines whether or not empty lines should be ignored (defaults to true)

when reading, if the parser reads a line that is empty, it will be skipped.

when writing, if the writer receives an empty or null row to write to the output, it will be ignored

Parameters
skipEmptyLines:boolean

true if empty lines should be ignored, false otherwise

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
trimValuesback to summary
public final void trimValues(boolean trim)

Configures the parser/writer to trim or keep leading and trailing whitespaces around values This has the same effect as invoking both setIgnoreLeadingWhitespaces(boolean) and setIgnoreTrailingWhitespaces(boolean) with the same value.

Parameters
trim:boolean

a flag indicating whether the whitespaces should remove whitespaces around values parsed/written.