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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoInit()protected voiddoStop()Indicates whether or not missing column names are allowed.Gets the comment marker.Gets the delimiter.Gets the escape character.org.apache.commons.csv.CSVFormatGets 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.QuoteModeGets 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.booleanIndicates whether or not the unmarshalling should capture the header record.booleanIndicates whether or not the comment markers are disabled.booleanIndicates whether or not the escaping is disabled.booleanIndicates whether or not the headers are disabled.booleanIndicates whether or not the unmarshalling should lazily load the records.booleanIndicates whether or not the null string replacement is disabled.booleanIndicates whether or not quotes are disabled.booleanIndicates whether or not the record separator is disabled.booleanIndicates whether or not the unmarshalling should produce maps instead of lists.booleanIndicates whether or not the unmarshalling should produce ordered maps instead of lists.voidmarshal(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 theCsvMarshallerfactory.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, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods 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:
getDataFormatNamein interfaceorg.apache.camel.spi.DataFormatName
-
marshal
public void marshal(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream) throws Exception - Specified by:
marshalin interfaceorg.apache.camel.spi.DataFormat- Throws:
Exception
-
unmarshal
public Object unmarshal(org.apache.camel.Exchange exchange, InputStream inputStream) throws Exception - Specified by:
unmarshalin interfaceorg.apache.camel.spi.DataFormat- Throws:
Exception
-
doInit
- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
- Overrides:
doStopin 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.DEFAULTis used instead.- Parameters:
format- CSV format- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormatCSVFormat.DEFAULT
-
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:
trueif the comment markers are disabled,falseotherwise
-
setCommentMarkerDisabled
Sets whether or not the comment markers are disabled.- Parameters:
commentMarkerDisabled-trueif the comment markers are disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withCommentMarker(java.lang.Character)
-
getCommentMarker
Gets the comment marker. Ifnullthen the default one of the format used.- Returns:
- Comment marker
-
setCommentMarker
Sets the comment marker to use. Ifnullthen the default one of the format used.- Parameters:
commentMarker- Comment marker- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withCommentMarker(Character)
-
getDelimiter
Gets the delimiter. Ifnullthen the default one of the format used.- Returns:
- Delimiter
-
setDelimiter
Sets the delimiter. Ifnullthen the default one of the format used.- Parameters:
delimiter- Delimiter- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withDelimiter(char)
-
isEscapeDisabled
public boolean isEscapeDisabled()Indicates whether or not the escaping is disabled.- Returns:
trueif the escaping is disabled,falseotherwise
-
setEscapeDisabled
Sets whether or not the escaping is disabled.- Parameters:
escapeDisabled-trueif the escaping is disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withEscape(Character)
-
getEscape
Gets the escape character. Ifnullthen the default one of the format used.- Returns:
- Escape character
-
setEscape
Sets the escape character. Ifnullthen the default one of the format used.- Parameters:
escape- Escape character- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withEscape(Character)
-
isHeaderDisabled
public boolean isHeaderDisabled()Indicates whether or not the headers are disabled.- Returns:
trueif the headers are disabled,falseotherwise
-
setHeaderDisabled
Sets whether or not the headers are disabled.- Parameters:
headerDisabled-trueif the headers are disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withHeader(String...)
-
getHeader
Gets the header. Multiple values can be separated by comma. Ifnullthen 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. Ifnullthen 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:
-
CSVFormat.withHeader(String...)
-
setHeader
-
getAllowMissingColumnNames
Indicates whether or not missing column names are allowed. Ifnullthen 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. Ifnullthen the default value of the format used.- Parameters:
allowMissingColumnNames- Whether or not missing column names are allowed- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withAllowMissingColumnNames(boolean)
-
getIgnoreEmptyLines
Indicates whether or not empty lines must be ignored. Ifnullthen 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. Ifnullthen the default value of the format used.- Parameters:
ignoreEmptyLines- Whether or not empty lines must be ignored- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withIgnoreEmptyLines(boolean)
-
getIgnoreSurroundingSpaces
Indicates whether or not surrounding spaces must be ignored. Ifnullthen 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. Ifnullthen the default value of the format used.- Parameters:
ignoreSurroundingSpaces- Whether or not surrounding spaces must be ignored- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withIgnoreSurroundingSpaces(boolean)
-
isNullStringDisabled
public boolean isNullStringDisabled()Indicates whether or not the null string replacement is disabled.- Returns:
trueif the null string replacement is disabled,falseotherwise
-
setNullStringDisabled
Sets whether or not the null string replacement is disabled.- Parameters:
nullStringDisabled-trueif the null string replacement is disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withNullString(String)
-
getNullString
Gets the null string replacement. Ifnullthen the default one of the format used.- Returns:
- Null string replacement
-
setNullString
Sets the null string replacement. Ifnullthen the default one of the format used.- Parameters:
nullString- Null string replacement- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withNullString(String)
-
isQuoteDisabled
public boolean isQuoteDisabled()Indicates whether or not quotes are disabled.- Returns:
trueif quotes are disabled,falseotherwise
-
setQuoteDisabled
Sets whether or not quotes are disabled- Parameters:
quoteDisabled-trueif quotes are disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withQuote(Character)
-
getQuote
Gets the quote character. Ifnullthen the default one of the format used.- Returns:
- Quote character
-
setQuote
Sets the quote character. Ifnullthen the default one of the format used.- Parameters:
quote- Quote character- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withQuote(Character)
-
getQuoteMode
public org.apache.commons.csv.QuoteMode getQuoteMode()Gets the quote mode. Ifnullthen the default one of the format used.- Returns:
- Quote mode
-
setQuoteMode
Sets the quote mode. Ifnullthen the default one of the format used.- Parameters:
quoteMode- Quote mode- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withQuoteMode(org.apache.commons.csv.QuoteMode)
-
isRecordSeparatorDisabled
public boolean isRecordSeparatorDisabled()Indicates whether or not the record separator is disabled.- Returns:
trueif the record separator disabled,falseotherwise
-
setRecordSeparatorDisabled
Sets whether or not the record separator is disabled.- Parameters:
recordSeparatorDisabled-trueif the record separator disabled,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withRecordSeparator(String)
-
getRecordSeparator
Gets the record separator. Ifnullthen the default one of the format used.- Returns:
- Record separator
-
setRecordSeparator
Sets the record separator. Ifnullthen the default one of the format used.- Parameters:
recordSeparator- Record separator- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withRecordSeparator(String)
-
getSkipHeaderRecord
Indicates whether or not header record must be skipped. Ifnullthen 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. Ifnullthen the default value of the format used.- Parameters:
skipHeaderRecord- Whether or not header record must be skipped- Returns:
- Current
CsvDataFormat, fluent API - See Also:
-
CSVFormat.withSkipHeaderRecord(boolean)
-
isCaptureHeaderRecord
public boolean isCaptureHeaderRecord()Indicates whether or not the unmarshalling should capture the header record.- Returns:
truefor capture header record,falseotherwise
-
setCaptureHeaderRecord
Indicates whether or not the unmarshalling should capture the header record.- Parameters:
captureHeaderRecord-truefor capture header record,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API
-
isLazyLoad
public boolean isLazyLoad()Indicates whether or not the unmarshalling should lazily load the records.- Returns:
truefor lazy loading,falseotherwise
-
setLazyLoad
Indicates whether or not the unmarshalling should lazily load the records.- Parameters:
lazyLoad-truefor lazy loading,falseotherwise- Returns:
- Current
CsvDataFormat, fluent API
-
isUseMaps
public boolean isUseMaps()Indicates whether or not the unmarshalling should produce maps instead of lists.- Returns:
truefor maps,falsefor lists
-
setUseMaps
Sets whether or not the unmarshalling should produce maps instead of lists.- Parameters:
useMaps-truefor maps,falsefor lists- Returns:
- Current
CsvDataFormat, fluent API
-
isUseOrderedMaps
public boolean isUseOrderedMaps()Indicates whether or not the unmarshalling should produce ordered maps instead of lists.- Returns:
truefor maps,falsefor lists
-
setUseOrderedMaps
Sets whether or not the unmarshalling should produce ordered maps instead of lists.- Parameters:
useOrderedMaps-truefor maps,falsefor lists- Returns:
- Current
CsvDataFormat, fluent API
-
getRecordConverter
Gets the record converter to use. Ifnullthen it will useisUseMaps()for finding the proper converter.- Returns:
- Record converter to use
-
setRecordConverter
Sets the record converter to use. Ifnullthen 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
nullthen the default value of the format used.- Parameters:
trim- whether or not to trim leading and trailing blanks.nullvalue allowed.- Returns:
- Current
CsvDataFormat, fluent API.
-
getTrim
Indicates whether or not to trim leading and trailing blanks.- Returns:
Boolean.TRUEif leading and trailing blanks should be trimmed.Boolean.FALSEotherwise. Could returnnullif value has NOT been set.
-
setIgnoreHeaderCase
Sets whether or not to ignore case when accessing header names.If
nullthen the default value of the format used.- Parameters:
ignoreHeaderCase- whether or not to ignore case when accessing header names.nullvalue allowed.- Returns:
- Current
CsvDataFormat, fluent API.
-
getIgnoreHeaderCase
Indicates whether or not to ignore case when accessing header names.- Returns:
Boolean.TRUEif case should be ignored when accessing header name.Boolean.FALSEotherwise. Could returnnullif value has NOT been set.
-
setTrailingDelimiter
Sets whether or not to add a trailing delimiter.If
nullthen 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.TRUEif a trailing delimiter should be added.Boolean.FALSEotherwise. Could returnnullif value has NOT been set.
-