uniVocity Fixed Length
Since Camel 2.15
This Data Format uses uniVocity-parsers for reading and writing 3 kinds of tabular data text files:
-
CSV (Comma Separated Values), where the values are separated by a symbol (usually a comma)
-
fixed-width, where the values have known sizes
-
TSV (Tabular Separated Values), where the fields are separated by a tabulation
Thus there are 3 data formats based on uniVocity-parsers.
If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest and greatest release.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-univocity-parsers</artifactId>
<version>x.x.x</version>
</dependency>
Options
Most configuration options of the uniVocity-parsers are available in the data formats. If you want more information about a particular option, please refer to their documentation page.
The 3 data formats share common options and have dedicated ones, this section presents them all.
Options
The uniVocity Fixed Length dataformat supports 17 options, which are listed below.
Name | Default | Java Type | Description |
---|---|---|---|
skipTrailingCharsUntilNewline |
|
|
Whether or not the trailing characters until new line must be ignored. The default value is false |
recordEndsOnNewline |
|
|
Whether or not the record ends on new line. The default value is false |
padding |
|
The padding character. The default value is a space |
|
nullValue |
|
The string representation of a null value. The default value is null |
|
skipEmptyLines |
|
|
Whether or not the empty lines must be ignored. The default value is true |
ignoreTrailingWhitespaces |
|
|
Whether or not the trailing white spaces must ignored. The default value is true |
ignoreLeadingWhitespaces |
|
|
Whether or not the leading white spaces must be ignored. The default value is true |
headersDisabled |
|
|
Whether or not the headers are disabled. When defined, this option explicitly sets the headers as null which indicates that there is no header. The default value is false |
headerExtractionEnabled |
|
|
Whether or not the header must be read in the first line of the test document The default value is false |
numberOfRecordsToRead |
|
The maximum number of record to read. |
|
emptyValue |
|
The String representation of an empty value |
|
lineSeparator |
|
The line separator of the files The default value is to use the JVM platform line separator |
|
normalizedLineSeparator |
|
|
The normalized line separator of the files The default value is a new line character. |
comment |
|
|
The comment symbol. The default value is # |
lazyLoad |
|
|
Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. The default value is false |
asMap |
|
|
Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected). The default value is false |
contentTypeHeader |
|
|
Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc. |
Marshalling usages
The marshalling accepts either:
-
A list of maps (L`ist<Map<String, ?>>`), one for each line
-
A single map (
Map<String, ?>
), for a single line
Any other body will throws an exception.
Usage example: marshalling a Map into CSV format
<route>
<from uri="direct:input"/>
<marshal>
<univocity-csv/>
</marshal>
<to uri="mock:result"/>
</route>
Unmarshalling usages
The unmarshalling uses an InputStream
in order to read the data.
Each row produces either:
-
a list with all the values in it (
asMap
option withfalse
); -
A map with all the values indexed by the headers (
asMap
option withtrue
).
All the rows can either:
-
be collected at once into a list (
lazyLoad
option withfalse
); -
be read on the fly using an iterator (
lazyLoad
option withtrue
).
Spring Boot Auto-Configuration
When using univocity-parsers with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-univocity-parsers-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 53 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.dataformat.univocity-csv.as-map |
Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected). The default value is false |
false |
Boolean |
camel.dataformat.univocity-csv.comment |
The comment symbol. The default value is # |
# |
String |
camel.dataformat.univocity-csv.content-type-header |
Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc. |
false |
Boolean |
camel.dataformat.univocity-csv.delimiter |
The delimiter of values |
, |
String |
camel.dataformat.univocity-csv.empty-value |
The String representation of an empty value |
String |
|
camel.dataformat.univocity-csv.enabled |
Whether to enable auto configuration of the univocity-csv data format. This is enabled by default. |
Boolean |
|
camel.dataformat.univocity-csv.header-extraction-enabled |
Whether or not the header must be read in the first line of the test document The default value is false |
false |
Boolean |
camel.dataformat.univocity-csv.headers-disabled |
Whether or not the headers are disabled. When defined, this option explicitly sets the headers as null which indicates that there is no header. The default value is false |
false |
Boolean |
camel.dataformat.univocity-csv.ignore-leading-whitespaces |
Whether or not the leading white spaces must be ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-csv.ignore-trailing-whitespaces |
Whether or not the trailing white spaces must ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-csv.lazy-load |
Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. The default value is false |
false |
Boolean |
camel.dataformat.univocity-csv.line-separator |
The line separator of the files The default value is to use the JVM platform line separator |
String |
|
camel.dataformat.univocity-csv.normalized-line-separator |
The normalized line separator of the files The default value is a new line character. |
\n |
String |
camel.dataformat.univocity-csv.null-value |
The string representation of a null value. The default value is null |
String |
|
camel.dataformat.univocity-csv.number-of-records-to-read |
The maximum number of record to read. |
Integer |
|
camel.dataformat.univocity-csv.quote |
The quote symbol. |
" |
String |
camel.dataformat.univocity-csv.quote-all-fields |
Whether or not all values must be quoted when writing them. |
false |
Boolean |
camel.dataformat.univocity-csv.quote-escape |
The quote escape symbol |
" |
String |
camel.dataformat.univocity-csv.skip-empty-lines |
Whether or not the empty lines must be ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-fixed.as-map |
Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected). The default value is false |
false |
Boolean |
camel.dataformat.univocity-fixed.comment |
The comment symbol. The default value is # |
# |
String |
camel.dataformat.univocity-fixed.content-type-header |
Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc. |
false |
Boolean |
camel.dataformat.univocity-fixed.empty-value |
The String representation of an empty value |
String |
|
camel.dataformat.univocity-fixed.enabled |
Whether to enable auto configuration of the univocity-fixed data format. This is enabled by default. |
Boolean |
|
camel.dataformat.univocity-fixed.header-extraction-enabled |
Whether or not the header must be read in the first line of the test document The default value is false |
false |
Boolean |
camel.dataformat.univocity-fixed.headers-disabled |
Whether or not the headers are disabled. When defined, this option explicitly sets the headers as null which indicates that there is no header. The default value is false |
false |
Boolean |
camel.dataformat.univocity-fixed.ignore-leading-whitespaces |
Whether or not the leading white spaces must be ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-fixed.ignore-trailing-whitespaces |
Whether or not the trailing white spaces must ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-fixed.lazy-load |
Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. The default value is false |
false |
Boolean |
camel.dataformat.univocity-fixed.line-separator |
The line separator of the files The default value is to use the JVM platform line separator |
String |
|
camel.dataformat.univocity-fixed.normalized-line-separator |
The normalized line separator of the files The default value is a new line character. |
\n |
String |
camel.dataformat.univocity-fixed.null-value |
The string representation of a null value. The default value is null |
String |
|
camel.dataformat.univocity-fixed.number-of-records-to-read |
The maximum number of record to read. |
Integer |
|
camel.dataformat.univocity-fixed.padding |
The padding character. The default value is a space |
String |
|
camel.dataformat.univocity-fixed.record-ends-on-newline |
Whether or not the record ends on new line. The default value is false |
false |
Boolean |
camel.dataformat.univocity-fixed.skip-empty-lines |
Whether or not the empty lines must be ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-fixed.skip-trailing-chars-until-newline |
Whether or not the trailing characters until new line must be ignored. The default value is false |
false |
Boolean |
camel.dataformat.univocity-tsv.as-map |
Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected). The default value is false |
false |
Boolean |
camel.dataformat.univocity-tsv.comment |
The comment symbol. The default value is # |
# |
String |
camel.dataformat.univocity-tsv.content-type-header |
Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc. |
false |
Boolean |
camel.dataformat.univocity-tsv.empty-value |
The String representation of an empty value |
String |
|
camel.dataformat.univocity-tsv.enabled |
Whether to enable auto configuration of the univocity-tsv data format. This is enabled by default. |
Boolean |
|
camel.dataformat.univocity-tsv.escape-char |
The escape character. |
\ |
String |
camel.dataformat.univocity-tsv.header-extraction-enabled |
Whether or not the header must be read in the first line of the test document The default value is false |
false |
Boolean |
camel.dataformat.univocity-tsv.headers-disabled |
Whether or not the headers are disabled. When defined, this option explicitly sets the headers as null which indicates that there is no header. The default value is false |
false |
Boolean |
camel.dataformat.univocity-tsv.ignore-leading-whitespaces |
Whether or not the leading white spaces must be ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-tsv.ignore-trailing-whitespaces |
Whether or not the trailing white spaces must ignored. The default value is true |
true |
Boolean |
camel.dataformat.univocity-tsv.lazy-load |
Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one. The default value is false |
false |
Boolean |
camel.dataformat.univocity-tsv.line-separator |
The line separator of the files The default value is to use the JVM platform line separator |
String |
|
camel.dataformat.univocity-tsv.normalized-line-separator |
The normalized line separator of the files The default value is a new line character. |
\n |
String |
camel.dataformat.univocity-tsv.null-value |
The string representation of a null value. The default value is null |
String |
|
camel.dataformat.univocity-tsv.number-of-records-to-read |
The maximum number of record to read. |
Integer |
|
camel.dataformat.univocity-tsv.skip-empty-lines |
Whether or not the empty lines must be ignored. The default value is true |
true |
Boolean |