Package org.apache.camel.dataformat.csv
Class CsvDataFormat
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.dataformat.csv.CsvDataFormat
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.DataFormat
,org.apache.camel.spi.DataFormatName
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@Dataformat("csv")
public class CsvDataFormat
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName
CSV Data format.
By default, columns are autogenerated in the resulting CSV. Subsequent messages use the previously created columns
with new fields being added at the end of the line. Thus, field order is the same from message to message.
Autogeneration can be disabled. In this case, only the fields defined in csvConfig are written on the output.
-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doInit()
protected void
doStop()
Indicates whether or not missing column names are allowed.Gets the comment marker.Gets the delimiter.Gets the escape character.org.apache.commons.csv.CSVFormat
Gets the CSV format before applying any changes.Gets the header.Indicates whether or not empty lines must be ignored.Indicates whether or not to ignore case when accessing header names.Indicates whether or not surrounding spaces must be ignored.Returns the usedCsvMarshallerFactory
.Gets the null string replacement.getQuote()
Gets the quote character.org.apache.commons.csv.QuoteMode
Gets the quote mode.Gets the record converter to use.Gets the record separator.Indicates whether or not header record must be skipped.Indicates whether or not to add a trailing delimiter.getTrim()
Indicates whether or not to trim leading and trailing blanks.boolean
Indicates whether or not the unmarshalling should capture the header record.boolean
Indicates whether or not the comment markers are disabled.boolean
Indicates whether or not the escaping is disabled.boolean
Indicates whether or not the headers are disabled.boolean
Indicates whether or not the unmarshalling should lazily load the records.boolean
Indicates whether or not the null string replacement is disabled.boolean
Indicates whether or not quotes are disabled.boolean
Indicates whether or not the record separator is disabled.boolean
Indicates whether or not the unmarshalling should produce maps instead of lists.boolean
Indicates whether or not the unmarshalling should produce ordered maps instead of lists.void
marshal
(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream) setAllowMissingColumnNames
(Boolean allowMissingColumnNames) Sets whether or not missing column names are allowed.setCaptureHeaderRecord
(boolean captureHeaderRecord) Indicates whether or not the unmarshalling should capture the header record.setCommentMarker
(Character commentMarker) Sets the comment marker to use.setCommentMarkerDisabled
(boolean commentMarkerDisabled) Sets whether or not the comment markers are disabled.setDelimiter
(Character delimiter) Sets the delimiter.Sets the escape character.setEscapeDisabled
(boolean escapeDisabled) Sets whether or not the escaping is disabled.setFormat
(org.apache.commons.csv.CSVFormat format) Sets the CSV format before applying any changes.setFormatName
(String name) Sets the CSV format by name before applying any changes.Gets the header.setHeaderDisabled
(boolean headerDisabled) Sets whether or not the headers are disabled.setIgnoreEmptyLines
(Boolean ignoreEmptyLines) Sets whether or not empty lines must be ignored.setIgnoreHeaderCase
(Boolean ignoreHeaderCase) Sets whether or not to ignore case when accessing header names.setIgnoreSurroundingSpaces
(Boolean ignoreSurroundingSpaces) Sets whether or not surrounding spaces must be ignored.setLazyLoad
(boolean lazyLoad) Indicates whether or not the unmarshalling should lazily load the records.setMarshallerFactory
(CsvMarshallerFactory marshallerFactory) Sets theCsvMarshaller
factory.setNullString
(String nullString) Sets the null string replacement.setNullStringDisabled
(boolean nullStringDisabled) Sets whether or not the null string replacement is disabled.Sets the quote character.setQuoteDisabled
(boolean quoteDisabled) Sets whether or not quotes are disabledsetQuoteMode
(org.apache.commons.csv.QuoteMode quoteMode) Sets the quote mode.setRecordConverter
(CsvRecordConverter<?> recordConverter) Sets the record converter to use.setRecordSeparator
(String recordSeparator) Sets the record separator.setRecordSeparatorDisabled
(boolean recordSeparatorDisabled) Sets whether or not the record separator is disabled.setSkipHeaderRecord
(Boolean skipHeaderRecord) Sets whether or not header record must be skipped.setTrailingDelimiter
(Boolean trailingDelimiter) Sets whether or not to add a trailing delimiter.Sets whether or not to trim leading and trailing blanks.setUseMaps
(boolean useMaps) Sets whether or not the unmarshalling should produce maps instead of lists.setUseOrderedMaps
(boolean useOrderedMaps) Sets whether or not the unmarshalling should produce ordered maps instead of lists.unmarshal
(org.apache.camel.Exchange exchange, InputStream inputStream) Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doStart, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
CsvDataFormat
public CsvDataFormat() -
CsvDataFormat
public CsvDataFormat(org.apache.commons.csv.CSVFormat format)
-
-
Method Details
-
getDataFormatName
- Specified by:
getDataFormatName
in interfaceorg.apache.camel.spi.DataFormatName
-
marshal
public void marshal(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream) throws Exception - Specified by:
marshal
in interfaceorg.apache.camel.spi.DataFormat
- Throws:
Exception
-
unmarshal
public Object unmarshal(org.apache.camel.Exchange exchange, InputStream inputStream) throws Exception - Specified by:
unmarshal
in interfaceorg.apache.camel.spi.DataFormat
- Throws:
Exception
-
unmarshal
- Specified by:
unmarshal
in interfaceorg.apache.camel.spi.DataFormat
- Throws:
Exception
-
doInit
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
getFormat
public org.apache.commons.csv.CSVFormat getFormat()Gets the CSV format before applying any changes. It cannot benull
, the default one isCSVFormat.DEFAULT
.- Returns:
- CSV format
-
setFormat
Sets the CSV format before applying any changes. Ifnull
, thenCSVFormat.DEFAULT
is used instead.- Parameters:
format
- CSV format- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
setMarshallerFactory
- Parameters:
marshallerFactory
-- Returns:
- Current
CsvDataFormat
, fluent API
-
getMarshallerFactory
Returns the usedCsvMarshallerFactory
.- Returns:
- never
null
.
-
setFormatName
Sets the CSV format by name before applying any changes.- Parameters:
name
- CSV format name- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isCommentMarkerDisabled
public boolean isCommentMarkerDisabled()Indicates whether or not the comment markers are disabled.- Returns:
true
if the comment markers are disabled,false
otherwise
-
setCommentMarkerDisabled
Sets whether or not the comment markers are disabled.- Parameters:
commentMarkerDisabled
-true
if the comment markers are disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getCommentMarker
Gets the comment marker. Ifnull
then the default one of the format used.- Returns:
- Comment marker
-
setCommentMarker
Sets the comment marker to use. Ifnull
then the default one of the format used.- Parameters:
commentMarker
- Comment marker- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getDelimiter
Gets the delimiter. Ifnull
then the default one of the format used.- Returns:
- Delimiter
-
setDelimiter
Sets the delimiter. Ifnull
then the default one of the format used.- Parameters:
delimiter
- Delimiter- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isEscapeDisabled
public boolean isEscapeDisabled()Indicates whether or not the escaping is disabled.- Returns:
true
if the escaping is disabled,false
otherwise
-
setEscapeDisabled
Sets whether or not the escaping is disabled.- Parameters:
escapeDisabled
-true
if the escaping is disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getEscape
Gets the escape character. Ifnull
then the default one of the format used.- Returns:
- Escape character
-
setEscape
Sets the escape character. Ifnull
then the default one of the format used.- Parameters:
escape
- Escape character- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isHeaderDisabled
public boolean isHeaderDisabled()Indicates whether or not the headers are disabled.- Returns:
true
if the headers are disabled,false
otherwise
-
setHeaderDisabled
Sets whether or not the headers are disabled.- Parameters:
headerDisabled
-true
if the headers are disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getHeader
Gets the header. Multiple values can be separated by comma. Ifnull
then the default one of the format used. If empty then it will be automatically handled.- Returns:
- Header
-
setHeader
Gets the header. Multiple values can be separated by comma. Ifnull
then the default one of the format used. If empty then it will be automatically handled.- Parameters:
header
- Header- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
setHeader
-
getAllowMissingColumnNames
Indicates whether or not missing column names are allowed. Ifnull
then the default value of the format used.- Returns:
- Whether or not missing column names are allowed
-
setAllowMissingColumnNames
Sets whether or not missing column names are allowed. Ifnull
then the default value of the format used.- Parameters:
allowMissingColumnNames
- Whether or not missing column names are allowed- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getIgnoreEmptyLines
Indicates whether or not empty lines must be ignored. Ifnull
then the default value of the format used.- Returns:
- Whether or not empty lines must be ignored
-
setIgnoreEmptyLines
Sets whether or not empty lines must be ignored. Ifnull
then the default value of the format used.- Parameters:
ignoreEmptyLines
- Whether or not empty lines must be ignored- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getIgnoreSurroundingSpaces
Indicates whether or not surrounding spaces must be ignored. Ifnull
then the default value of the format used.- Returns:
- Whether or not surrounding spaces must be ignored
-
setIgnoreSurroundingSpaces
Sets whether or not surrounding spaces must be ignored. Ifnull
then the default value of the format used.- Parameters:
ignoreSurroundingSpaces
- Whether or not surrounding spaces must be ignored- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isNullStringDisabled
public boolean isNullStringDisabled()Indicates whether or not the null string replacement is disabled.- Returns:
true
if the null string replacement is disabled,false
otherwise
-
setNullStringDisabled
Sets whether or not the null string replacement is disabled.- Parameters:
nullStringDisabled
-true
if the null string replacement is disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getNullString
Gets the null string replacement. Ifnull
then the default one of the format used.- Returns:
- Null string replacement
-
setNullString
Sets the null string replacement. Ifnull
then the default one of the format used.- Parameters:
nullString
- Null string replacement- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isQuoteDisabled
public boolean isQuoteDisabled()Indicates whether or not quotes are disabled.- Returns:
true
if quotes are disabled,false
otherwise
-
setQuoteDisabled
Sets whether or not quotes are disabled- Parameters:
quoteDisabled
-true
if quotes are disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getQuote
Gets the quote character. Ifnull
then the default one of the format used.- Returns:
- Quote character
-
setQuote
Sets the quote character. Ifnull
then the default one of the format used.- Parameters:
quote
- Quote character- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getQuoteMode
public org.apache.commons.csv.QuoteMode getQuoteMode()Gets the quote mode. Ifnull
then the default one of the format used.- Returns:
- Quote mode
-
setQuoteMode
Sets the quote mode. Ifnull
then the default one of the format used.- Parameters:
quoteMode
- Quote mode- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isRecordSeparatorDisabled
public boolean isRecordSeparatorDisabled()Indicates whether or not the record separator is disabled.- Returns:
true
if the record separator disabled,false
otherwise
-
setRecordSeparatorDisabled
Sets whether or not the record separator is disabled.- Parameters:
recordSeparatorDisabled
-true
if the record separator disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getRecordSeparator
Gets the record separator. Ifnull
then the default one of the format used.- Returns:
- Record separator
-
setRecordSeparator
Sets the record separator. Ifnull
then the default one of the format used.- Parameters:
recordSeparator
- Record separator- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
getSkipHeaderRecord
Indicates whether or not header record must be skipped. Ifnull
then the default value of the format used.- Returns:
- Whether or not header record must be skipped
-
setSkipHeaderRecord
Sets whether or not header record must be skipped. Ifnull
then the default value of the format used.- Parameters:
skipHeaderRecord
- Whether or not header record must be skipped- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
-
isCaptureHeaderRecord
public boolean isCaptureHeaderRecord()Indicates whether or not the unmarshalling should capture the header record.- Returns:
true
for capture header record,false
otherwise
-
setCaptureHeaderRecord
Indicates whether or not the unmarshalling should capture the header record.- Parameters:
captureHeaderRecord
-true
for capture header record,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API
-
isLazyLoad
public boolean isLazyLoad()Indicates whether or not the unmarshalling should lazily load the records.- Returns:
true
for lazy loading,false
otherwise
-
setLazyLoad
Indicates whether or not the unmarshalling should lazily load the records.- Parameters:
lazyLoad
-true
for lazy loading,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API
-
isUseMaps
public boolean isUseMaps()Indicates whether or not the unmarshalling should produce maps instead of lists.- Returns:
true
for maps,false
for lists
-
setUseMaps
Sets whether or not the unmarshalling should produce maps instead of lists.- Parameters:
useMaps
-true
for maps,false
for lists- Returns:
- Current
CsvDataFormat
, fluent API
-
isUseOrderedMaps
public boolean isUseOrderedMaps()Indicates whether or not the unmarshalling should produce ordered maps instead of lists.- Returns:
true
for maps,false
for lists
-
setUseOrderedMaps
Sets whether or not the unmarshalling should produce ordered maps instead of lists.- Parameters:
useOrderedMaps
-true
for maps,false
for lists- Returns:
- Current
CsvDataFormat
, fluent API
-
getRecordConverter
Gets the record converter to use. Ifnull
then it will useisUseMaps()
for finding the proper converter.- Returns:
- Record converter to use
-
setRecordConverter
Sets the record converter to use. Ifnull
then it will useisUseMaps()
for finding the proper converter.- Parameters:
recordConverter
- Record converter to use- Returns:
- Current
CsvDataFormat
, fluent API
-
setTrim
Sets whether or not to trim leading and trailing blanks.If
null
then the default value of the format used.- Parameters:
trim
- whether or not to trim leading and trailing blanks.null
value allowed.- Returns:
- Current
CsvDataFormat
, fluent API.
-
getTrim
Indicates whether or not to trim leading and trailing blanks.- Returns:
Boolean.TRUE
if leading and trailing blanks should be trimmed.Boolean.FALSE
otherwise. Could returnnull
if value has NOT been set.
-
setIgnoreHeaderCase
Sets whether or not to ignore case when accessing header names.If
null
then the default value of the format used.- Parameters:
ignoreHeaderCase
- whether or not to ignore case when accessing header names.null
value allowed.- Returns:
- Current
CsvDataFormat
, fluent API.
-
getIgnoreHeaderCase
Indicates whether or not to ignore case when accessing header names.- Returns:
Boolean.TRUE
if case should be ignored when accessing header name.Boolean.FALSE
otherwise. Could returnnull
if value has NOT been set.
-
setTrailingDelimiter
Sets whether or not to add a trailing delimiter.If
null
then the default value of the format used.- Parameters:
trailingDelimiter
- whether or not to add a trailing delimiter.- Returns:
- Current
CsvDataFormat
, fluent API.
-
getTrailingDelimiter
Indicates whether or not to add a trailing delimiter.- Returns:
Boolean.TRUE
if a trailing delimiter should be added.Boolean.FALSE
otherwise. Could returnnull
if value has NOT been set.
-