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.
-
-
Constructor Summary
Constructors Constructor Description CsvDataFormat()
CsvDataFormat(org.apache.commons.csv.CSVFormat format)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doInit()
protected void
doStop()
Boolean
getAllowMissingColumnNames()
Indicates whether or not missing column names are allowed.Character
getCommentMarker()
Gets the comment marker.String
getDataFormatName()
Character
getDelimiter()
Gets the delimiter.Character
getEscape()
Gets the escape character.org.apache.commons.csv.CSVFormat
getFormat()
Gets the CSV format before applying any changes.String
getHeader()
Gets the header.Boolean
getIgnoreEmptyLines()
Indicates whether or not empty lines must be ignored.Boolean
getIgnoreHeaderCase()
Indicates whether or not to ignore case when accessing header names.Boolean
getIgnoreSurroundingSpaces()
Indicates whether or not surrounding spaces must be ignored.CsvMarshallerFactory
getMarshallerFactory()
Returns the usedCsvMarshallerFactory
.String
getNullString()
Gets the null string replacement.Character
getQuote()
Gets the quote character.org.apache.commons.csv.QuoteMode
getQuoteMode()
Gets the quote mode.CsvRecordConverter<?>
getRecordConverter()
Gets the record converter to use.String
getRecordSeparator()
Gets the record separator.Boolean
getSkipHeaderRecord()
Indicates whether or not header record must be skipped.Boolean
getTrailingDelimiter()
Indicates whether or not to add a trailing delimiter.Boolean
getTrim()
Indicates whether or not to trim leading and trailing blanks.boolean
isCaptureHeaderRecord()
Indicates whether or not the unmarshalling should capture the header record.boolean
isCommentMarkerDisabled()
Indicates whether or not the comment markers are disabled.boolean
isEscapeDisabled()
Indicates whether or not the escaping is disabled.boolean
isHeaderDisabled()
Indicates whether or not the headers are disabled.boolean
isLazyLoad()
Indicates whether or not the unmarshalling should lazily load the records.boolean
isNullStringDisabled()
Indicates whether or not the null string replacement is disabled.boolean
isQuoteDisabled()
Indicates whether or not quotes are disabled.boolean
isRecordSeparatorDisabled()
Indicates whether or not the record separator is disabled.boolean
isUseMaps()
Indicates whether or not the unmarshalling should produce maps instead of lists.boolean
isUseOrderedMaps()
Indicates whether or not the unmarshalling should produce ordered maps instead of lists.void
marshal(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream)
CsvDataFormat
setAllowMissingColumnNames(Boolean allowMissingColumnNames)
Sets whether or not missing column names are allowed.CsvDataFormat
setCaptureHeaderRecord(boolean captureHeaderRecord)
Indicates whether or not the unmarshalling should capture the header record.CsvDataFormat
setCommentMarker(Character commentMarker)
Sets the comment marker to use.CsvDataFormat
setCommentMarkerDisabled(boolean commentMarkerDisabled)
Sets whether or not the comment markers are disabled.CsvDataFormat
setDelimiter(Character delimiter)
Sets the delimiter.CsvDataFormat
setEscape(Character escape)
Sets the escape character.CsvDataFormat
setEscapeDisabled(boolean escapeDisabled)
Sets whether or not the escaping is disabled.CsvDataFormat
setFormat(org.apache.commons.csv.CSVFormat format)
Sets the CSV format before applying any changes.CsvDataFormat
setFormatName(String name)
Sets the CSV format by name before applying any changes.CsvDataFormat
setHeader(String header)
Gets the header.CsvDataFormat
setHeader(String[] header)
CsvDataFormat
setHeaderDisabled(boolean headerDisabled)
Sets whether or not the headers are disabled.CsvDataFormat
setIgnoreEmptyLines(Boolean ignoreEmptyLines)
Sets whether or not empty lines must be ignored.CsvDataFormat
setIgnoreHeaderCase(Boolean ignoreHeaderCase)
Sets whether or not to ignore case when accessing header names.CsvDataFormat
setIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces)
Sets whether or not surrounding spaces must be ignored.CsvDataFormat
setLazyLoad(boolean lazyLoad)
Indicates whether or not the unmarshalling should lazily load the records.CsvDataFormat
setMarshallerFactory(CsvMarshallerFactory marshallerFactory)
Sets theCsvMarshaller
factory.CsvDataFormat
setNullString(String nullString)
Sets the null string replacement.CsvDataFormat
setNullStringDisabled(boolean nullStringDisabled)
Sets whether or not the null string replacement is disabled.CsvDataFormat
setQuote(Character quote)
Sets the quote character.CsvDataFormat
setQuoteDisabled(boolean quoteDisabled)
Sets whether or not quotes are disabledCsvDataFormat
setQuoteMode(org.apache.commons.csv.QuoteMode quoteMode)
Sets the quote mode.CsvDataFormat
setRecordConverter(CsvRecordConverter<?> recordConverter)
Sets the record converter to use.CsvDataFormat
setRecordSeparator(String recordSeparator)
Sets the record separator.CsvDataFormat
setRecordSeparatorDisabled(boolean recordSeparatorDisabled)
Sets whether or not the record separator is disabled.CsvDataFormat
setSkipHeaderRecord(Boolean skipHeaderRecord)
Sets whether or not header record must be skipped.CsvDataFormat
setTrailingDelimiter(Boolean trailingDelimiter)
Sets whether or not to add a trailing delimiter.CsvDataFormat
setTrim(Boolean trim)
Sets whether or not to trim leading and trailing blanks.CsvDataFormat
setUseMaps(boolean useMaps)
Sets whether or not the unmarshalling should produce maps instead of lists.CsvDataFormat
setUseOrderedMaps(boolean useOrderedMaps)
Sets whether or not the unmarshalling should produce ordered maps instead of lists.Object
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
-
-
-
-
Method Detail
-
getDataFormatName
public String 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
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- 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
public CsvDataFormat setFormat(org.apache.commons.csv.CSVFormat format)
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:
CSVFormat
,CSVFormat.DEFAULT
-
setMarshallerFactory
public CsvDataFormat setMarshallerFactory(CsvMarshallerFactory marshallerFactory)
- Parameters:
marshallerFactory
-- Returns:
- Current
CsvDataFormat
, fluent API
-
getMarshallerFactory
public CsvMarshallerFactory getMarshallerFactory()
Returns the usedCsvMarshallerFactory
.- Returns:
- never
null
.
-
setFormatName
public CsvDataFormat setFormatName(String name)
Sets the CSV format by name before applying any changes.- Parameters:
name
- CSV format name- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
setFormat(org.apache.commons.csv.CSVFormat)
,CSVFormat
-
isCommentMarkerDisabled
public boolean isCommentMarkerDisabled()
Indicates whether or not the comment markers are disabled.- Returns:
true
if the comment markers are disabled,false
otherwise
-
setCommentMarkerDisabled
public CsvDataFormat setCommentMarkerDisabled(boolean commentMarkerDisabled)
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:
CSVFormat.withCommentMarker(java.lang.Character)
-
getCommentMarker
public Character getCommentMarker()
Gets the comment marker. Ifnull
then the default one of the format used.- Returns:
- Comment marker
-
setCommentMarker
public CsvDataFormat setCommentMarker(Character commentMarker)
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:
CSVFormat.withCommentMarker(Character)
-
getDelimiter
public Character getDelimiter()
Gets the delimiter. Ifnull
then the default one of the format used.- Returns:
- Delimiter
-
setDelimiter
public CsvDataFormat setDelimiter(Character delimiter)
Sets the delimiter. Ifnull
then 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:
true
if the escaping is disabled,false
otherwise
-
setEscapeDisabled
public CsvDataFormat setEscapeDisabled(boolean escapeDisabled)
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:
CSVFormat.withEscape(Character)
-
getEscape
public Character getEscape()
Gets the escape character. Ifnull
then the default one of the format used.- Returns:
- Escape character
-
setEscape
public CsvDataFormat setEscape(Character escape)
Sets the escape character. Ifnull
then 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:
true
if the headers are disabled,false
otherwise
-
setHeaderDisabled
public CsvDataFormat setHeaderDisabled(boolean headerDisabled)
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:
CSVFormat.withHeader(String...)
-
getHeader
public String 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
public CsvDataFormat setHeader(String header)
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:
CSVFormat.withHeader(String...)
-
setHeader
public CsvDataFormat setHeader(String[] header)
-
getAllowMissingColumnNames
public Boolean 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
public CsvDataFormat setAllowMissingColumnNames(Boolean allowMissingColumnNames)
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:
CSVFormat.withAllowMissingColumnNames(boolean)
-
getIgnoreEmptyLines
public Boolean 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
public CsvDataFormat setIgnoreEmptyLines(Boolean ignoreEmptyLines)
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:
CSVFormat.withIgnoreEmptyLines(boolean)
-
getIgnoreSurroundingSpaces
public Boolean 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
public CsvDataFormat setIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces)
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:
CSVFormat.withIgnoreSurroundingSpaces(boolean)
-
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
public CsvDataFormat setNullStringDisabled(boolean nullStringDisabled)
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:
CSVFormat.withNullString(String)
-
getNullString
public String getNullString()
Gets the null string replacement. Ifnull
then the default one of the format used.- Returns:
- Null string replacement
-
setNullString
public CsvDataFormat setNullString(String nullString)
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:
CSVFormat.withNullString(String)
-
isQuoteDisabled
public boolean isQuoteDisabled()
Indicates whether or not quotes are disabled.- Returns:
true
if quotes are disabled,false
otherwise
-
setQuoteDisabled
public CsvDataFormat setQuoteDisabled(boolean quoteDisabled)
Sets whether or not quotes are disabled- Parameters:
quoteDisabled
-true
if quotes are disabled,false
otherwise- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
CSVFormat.withQuote(Character)
-
getQuote
public Character getQuote()
Gets the quote character. Ifnull
then the default one of the format used.- Returns:
- Quote character
-
setQuote
public CsvDataFormat setQuote(Character quote)
Sets the quote character. Ifnull
then 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. Ifnull
then the default one of the format used.- Returns:
- Quote mode
-
setQuoteMode
public CsvDataFormat setQuoteMode(org.apache.commons.csv.QuoteMode quoteMode)
Sets the quote mode. Ifnull
then 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:
true
if the record separator disabled,false
otherwise
-
setRecordSeparatorDisabled
public CsvDataFormat setRecordSeparatorDisabled(boolean recordSeparatorDisabled)
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:
CSVFormat.withRecordSeparator(String)
-
getRecordSeparator
public String getRecordSeparator()
Gets the record separator. Ifnull
then the default one of the format used.- Returns:
- Record separator
-
setRecordSeparator
public CsvDataFormat setRecordSeparator(String recordSeparator)
Sets the record separator. Ifnull
then the default one of the format used.- Parameters:
recordSeparator
- Record separator- Returns:
- Current
CsvDataFormat
, fluent API - See Also:
CSVFormat.withRecordSeparator(String)
-
getSkipHeaderRecord
public Boolean 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
public CsvDataFormat setSkipHeaderRecord(Boolean skipHeaderRecord)
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:
CSVFormat.withSkipHeaderRecord(boolean)
-
isCaptureHeaderRecord
public boolean isCaptureHeaderRecord()
Indicates whether or not the unmarshalling should capture the header record.- Returns:
true
for capture header record,false
otherwise
-
setCaptureHeaderRecord
public CsvDataFormat setCaptureHeaderRecord(boolean captureHeaderRecord)
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
public CsvDataFormat setLazyLoad(boolean lazyLoad)
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
public CsvDataFormat setUseMaps(boolean useMaps)
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
public CsvDataFormat setUseOrderedMaps(boolean useOrderedMaps)
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
public CsvRecordConverter<?> getRecordConverter()
Gets the record converter to use. Ifnull
then it will useisUseMaps()
for finding the proper converter.- Returns:
- Record converter to use
-
setRecordConverter
public CsvDataFormat setRecordConverter(CsvRecordConverter<?> recordConverter)
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
public CsvDataFormat setTrim(Boolean trim)
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
public Boolean 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
public CsvDataFormat setIgnoreHeaderCase(Boolean ignoreHeaderCase)
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
public Boolean 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
public CsvDataFormat setTrailingDelimiter(Boolean trailingDelimiter)
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
public Boolean 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.
-
-