AbstractParser) and writers (AbstractWriter)
By default, all parsers and writers work with, at least, the following configuration options:
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
You need this to avoid OutOfMemoryErrors in case a file does not have a valid format. In such cases the parser might just keep reading from the input until its end or the memory is exhausted. This sets a limit which avoids unwanted JVM crashes.
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
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
when reading, the selected fields only will be parsed and the remaining fields will be discarded.
when writing, the selected fields only will be written and the remaining fields will be discarded
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
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private int | |
| private ProcessorErrorHandler | |
| private FieldSelector | |
| private F | |
| private String[] | |
| pack-priv Class | |
| private boolean | |
| private boolean | |
| private int | |
| private int | |
| private String | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | CommonSettings()
Creates a new instance of this settings object using the default format specified by the concrete class that inherits from |
| Modifier and Type | Method and Description |
|---|---|
| protected void | |
| pack-priv final void | |
| protected void | |
| protected CommonSettings | Returns: a copy of the configurations applied to the current instance.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 | Returns: a copy of all configurations applied to the current instance.Overrides java. |
| protected abstract F | Returns: Default format configuration for the given parser/writer settings.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 falsethe class to derive headers from beanClass)Indicates whether headers should be derived from a given class. |
| public FieldSet | Returns: the (modifiable) set of ignored fieldsThe 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 | Returns: the (modifiable) set of ignored fieldsThe 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 | Returns: the (modifiable) set of ignored fieldsindexes 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.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 |
| pack-priv FieldSelector | Returns: the FieldSelector object, which handles selected fields. Null if no field was selected/excludedReturns the FieldSelector object, which handles selected fields. |
| pack-priv FieldSet | Returns: the set of selected fields. Null if no field was selected/excludedReturns the set of selected fields, if any |
| public F | Returns: The format of the file to be parsed/writtenThe 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.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 otherwiseReturns 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 otherwiseReturns 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/readThe maximum number of characters allowed for any given value being written/read. |
| public int | Returns: The maximum number of columns a record can have.Returns the hard limit of how many columns a record can have (defaults to 512). |
| public String | Returns: the String representation of a null valueReturns 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 T extends Context> ProcessorErrorHandlerContext type provided by the parser implementation. | Returns: the callback error handler with custom code to manage occurrences ofDataProcessingException.Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a |
| public RowProcessorErrorHandler | Returns: the callback error handler with custom code to manage occurrences ofDataProcessingException.
Deprecated
Use the
Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a getProcessorErrorHandler() method as it allows format-specific error handlers to be built to work with different implementations of Context.
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.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 otherwiseReturns 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 whitespaceReturns the starting decimal range for |
| public final boolean | Returns: true if the automatic configuration feature is enabled, false otherwiseIndicates whether this settings object can automatically derive configuration options. |
| public boolean | isProcessorErrorHandlerDefined()
Returns a flag indicating whether or not a |
| pack-priv void | |
| public FieldSet | Returns: the (modifiable) set of selected fieldsThe field names to read/write fieldNames)Selects a sequence of fields for reading/writing by their names. |
| public FieldSet | Returns: the (modifiable) set of selected fieldsThe 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 | Returns: the (modifiable) set of selected fieldsThe 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 | Returns: the set of selected fields given in as a parameter.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 |
| 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 processorErrorHandler)DataProcessingException.Defines a custom error handler to capture and handle errors that might happen while processing records with a |
| public void | setRowProcessorErrorHandler(RowProcessorErrorHandler
the callback error handler with custom code to manage occurrences of rowProcessorErrorHandler)DataProcessingException.
Deprecated
Use the
Defines a custom error handler to capture and handle errors that might happen while processing records with a setProcessorErrorHandler(ProcessorErrorHandler) method as it allows format-specific error handlers to be built to work with different implementations of Context.
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 | |
| 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 |
| autoConfigurationEnabled | back to summary |
|---|---|
| private boolean autoConfigurationEnabled | |
| errorContentLength | back to summary |
|---|---|
| private int errorContentLength | |
| errorHandler | back to summary |
|---|---|
| private ProcessorErrorHandler<? extends Context> errorHandler | |
| fieldSelector | back to summary |
|---|---|
| private FieldSelector fieldSelector | |
| format | back to summary |
|---|---|
| private F format | |
| headers | back to summary |
|---|---|
| private String[] headers | |
| headerSourceClass | back to summary |
|---|---|
| pack-priv Class<?> headerSourceClass | |
| ignoreLeadingWhitespaces | back to summary |
|---|---|
| private boolean ignoreLeadingWhitespaces | |
| ignoreTrailingWhitespaces | back to summary |
|---|---|
| private boolean ignoreTrailingWhitespaces | |
| maxCharsPerColumn | back to summary |
|---|---|
| private int maxCharsPerColumn | |
| maxColumns | back to summary |
|---|---|
| private int maxColumns | |
| nullValue | back to summary |
|---|---|
| private String nullValue | |
| skipBitsAsWhitespace | back to summary |
|---|---|
| private boolean skipBitsAsWhitespace | |
| skipEmptyLines | back to summary |
|---|---|
| private boolean skipEmptyLines | |
| CommonSettings | back to summary |
|---|---|
| public CommonSettings() Creates a new instance of this settings object using the default format specified by the concrete class that inherits from | |
| addConfiguration | back to summary |
|---|---|
| protected void addConfiguration(Map<String, Object> out) | |
| autoConfigure | back to summary |
|---|---|
| pack-priv final void autoConfigure() | |
| clearInputSpecificSettings | back to summary |
|---|---|
| protected void clearInputSpecificSettings() Clears settings that are likely to be specific to a given input. | |
| clone | back to summary |
|---|---|
| protected CommonSettings 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
| |
| clone | back to summary |
|---|---|
| protected CommonSettings Overrides java. Clones this configuration object. Use alternative
| |
| createDefaultFormat | back to summary |
|---|---|
| protected abstract F createDefaultFormat() Extending classes must implement this method to return the default format settings for their parser/writer
| |
| deriveHeadersFrom | back to summary |
|---|---|
| pack-priv boolean deriveHeadersFrom(Class<?> beanClass) Indicates whether headers should be derived from a given class.
| |
| excludeFields | back to summary |
|---|---|
| public FieldSet 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 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" | |
| excludeFields | back to summary |
|---|---|
| public FieldSet 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 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" | |
| excludeIndexes | back to summary |
|---|---|
| public FieldSet 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 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" | |
| getErrorContentLength | back 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 defaults to
| |
| getFieldSelector | back to summary |
|---|---|
| pack-priv FieldSelector getFieldSelector() Returns the FieldSelector object, which handles selected fields.
| |
| getFieldSet | back to summary |
|---|---|
| pack-priv FieldSet Returns the set of selected fields, if any
| |
| getFormat | back to summary |
|---|---|
| public F getFormat() The format of the file to be parsed/written (returns the format's defaults).
| |
| getHeaders | back 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
| |
| getIgnoreLeadingWhitespaces | back to summary |
|---|---|
| public boolean getIgnoreLeadingWhitespaces() Returns whether or not leading whitespaces from values being read/written should be skipped (defaults to true)
| |
| getIgnoreTrailingWhitespaces | back to summary |
|---|---|
| public boolean getIgnoreTrailingWhitespaces() Returns whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)
| |
| getMaxCharsPerColumn | back 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
| |
| getMaxColumns | back 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 .
| |
| getNullValue | back 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
| |
| getProcessorErrorHandler | back to summary |
|---|---|
| public <T extends Context> ProcessorErrorHandler Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a The parsing/writing process won't stop (unless the error handler rethrows the
| |
| getRowProcessorErrorHandler | back to summary |
|---|---|
| public RowProcessorErrorHandler getRowProcessorErrorHandler()
Deprecated Use the Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a The parsing/writing process won't stop (unless the error handler rethrows the
| |
| getSkipBitsAsWhitespace | back 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 defaults to
| |
| getSkipEmptyLines | back 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
| |
| getWhitespaceRangeStart | back to summary |
|---|---|
| protected final int getWhitespaceRangeStart() Returns the starting decimal range for
| |
| isAutoConfigurationEnabled | back 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 Defaults to
| |
| isProcessorErrorHandlerDefined | back to summary |
|---|---|
| public boolean isProcessorErrorHandlerDefined() Returns a flag indicating whether or not a
| |
| runAutomaticConfiguration | back to summary |
|---|---|
| pack-priv void runAutomaticConfiguration() | |
| selectFields | back to summary |
|---|---|
| public FieldSet 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 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" | |
| selectFields | back to summary |
|---|---|
| public FieldSet 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 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" | |
| selectIndexes | back to summary |
|---|---|
| public FieldSet 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 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" | |
| setAutoConfigurationEnabled | back 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
| |
| setErrorContentLength | back 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 defaults to
| |
| setFieldSet | back to summary |
|---|---|
| private <T> FieldSet Replaces the current field selection | |
| setFormat | back to summary |
|---|---|
| public void setFormat(F format) Defines the format of the file to be parsed/written (returns the format's defaults).
| |
| setHeaders | back 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
| |
| setHeadersDerivedFromClass | back to summary |
|---|---|
| pack-priv void setHeadersDerivedFromClass(Class<?> headerSourceClass, String... headers) Defines the field names in the input/output derived from a given class with 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 | |
| setIgnoreLeadingWhitespaces | back to summary |
|---|---|
| public void setIgnoreLeadingWhitespaces(boolean ignoreLeadingWhitespaces) Defines whether or not leading whitespaces from values being read/written should be skipped (defaults to true)
| |
| setIgnoreTrailingWhitespaces | back to summary |
|---|---|
| public void setIgnoreTrailingWhitespaces(boolean ignoreTrailingWhitespaces) Defines whether or not trailing whitespaces from values being read/written should be skipped (defaults to true)
| |
| setMaxCharsPerColumn | back 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
| |
| setMaxColumns | back 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.
| |
| setNullValue | back 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
| |
| setProcessorErrorHandler | back 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 The parsing parsing/writing won't stop (unless the error handler rethrows the
| |
| setRowProcessorErrorHandler | back to summary |
|---|---|
| public void setRowProcessorErrorHandler(RowProcessorErrorHandler rowProcessorErrorHandler)
Deprecated Use the Defines a custom error handler to capture and handle errors that might happen while processing records with a The parsing parsing/writing won't stop (unless the error handler rethrows the
| |
| setSkipBitsAsWhitespace | back 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 defaults to
| |
| setSkipEmptyLines | back 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
| |
| toString | back to summary |
|---|---|
| public final String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| trimValues | back 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
| |