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.DataFormatNameCSV 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 voiddoInit()protected voiddoStop()BooleangetAllowMissingColumnNames()Indicates whether or not missing column names are allowed.CharactergetCommentMarker()Gets the comment marker.StringgetDataFormatName()CharactergetDelimiter()Gets the delimiter.CharactergetEscape()Gets the escape character.org.apache.commons.csv.CSVFormatgetFormat()Gets the CSV format before applying any changes.StringgetHeader()Gets the header.BooleangetIgnoreEmptyLines()Indicates whether or not empty lines must be ignored.BooleangetIgnoreHeaderCase()Indicates whether or not to ignore case when accessing header names.BooleangetIgnoreSurroundingSpaces()Indicates whether or not surrounding spaces must be ignored.CsvMarshallerFactorygetMarshallerFactory()Returns the usedCsvMarshallerFactory.StringgetNullString()Gets the null string replacement.CharactergetQuote()Gets the quote character.org.apache.commons.csv.QuoteModegetQuoteMode()Gets the quote mode.CsvRecordConverter<?>getRecordConverter()Gets the record converter to use.StringgetRecordSeparator()Gets the record separator.BooleangetSkipHeaderRecord()Indicates whether or not header record must be skipped.BooleangetTrailingDelimiter()Indicates whether or not to add a trailing delimiter.BooleangetTrim()Indicates whether or not to trim leading and trailing blanks.booleanisCaptureHeaderRecord()Indicates whether or not the unmarshalling should capture the header record.booleanisCommentMarkerDisabled()Indicates whether or not the comment markers are disabled.booleanisEscapeDisabled()Indicates whether or not the escaping is disabled.booleanisHeaderDisabled()Indicates whether or not the headers are disabled.booleanisLazyLoad()Indicates whether or not the unmarshalling should lazily load the records.booleanisNullStringDisabled()Indicates whether or not the null string replacement is disabled.booleanisQuoteDisabled()Indicates whether or not quotes are disabled.booleanisRecordSeparatorDisabled()Indicates whether or not the record separator is disabled.booleanisUseMaps()Indicates whether or not the unmarshalling should produce maps instead of lists.booleanisUseOrderedMaps()Indicates whether or not the unmarshalling should produce ordered maps instead of lists.voidmarshal(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream)CsvDataFormatsetAllowMissingColumnNames(Boolean allowMissingColumnNames)Sets whether or not missing column names are allowed.CsvDataFormatsetCaptureHeaderRecord(boolean captureHeaderRecord)Indicates whether or not the unmarshalling should capture the header record.CsvDataFormatsetCommentMarker(Character commentMarker)Sets the comment marker to use.CsvDataFormatsetCommentMarkerDisabled(boolean commentMarkerDisabled)Sets whether or not the comment markers are disabled.CsvDataFormatsetDelimiter(Character delimiter)Sets the delimiter.CsvDataFormatsetEscape(Character escape)Sets the escape character.CsvDataFormatsetEscapeDisabled(boolean escapeDisabled)Sets whether or not the escaping is disabled.CsvDataFormatsetFormat(org.apache.commons.csv.CSVFormat format)Sets the CSV format before applying any changes.CsvDataFormatsetFormatName(String name)Sets the CSV format by name before applying any changes.CsvDataFormatsetHeader(String header)Gets the header.CsvDataFormatsetHeader(String[] header)CsvDataFormatsetHeaderDisabled(boolean headerDisabled)Sets whether or not the headers are disabled.CsvDataFormatsetIgnoreEmptyLines(Boolean ignoreEmptyLines)Sets whether or not empty lines must be ignored.CsvDataFormatsetIgnoreHeaderCase(Boolean ignoreHeaderCase)Sets whether or not to ignore case when accessing header names.CsvDataFormatsetIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces)Sets whether or not surrounding spaces must be ignored.CsvDataFormatsetLazyLoad(boolean lazyLoad)Indicates whether or not the unmarshalling should lazily load the records.CsvDataFormatsetMarshallerFactory(CsvMarshallerFactory marshallerFactory)Sets theCsvMarshallerfactory.CsvDataFormatsetNullString(String nullString)Sets the null string replacement.CsvDataFormatsetNullStringDisabled(boolean nullStringDisabled)Sets whether or not the null string replacement is disabled.CsvDataFormatsetQuote(Character quote)Sets the quote character.CsvDataFormatsetQuoteDisabled(boolean quoteDisabled)Sets whether or not quotes are disabledCsvDataFormatsetQuoteMode(org.apache.commons.csv.QuoteMode quoteMode)Sets the quote mode.CsvDataFormatsetRecordConverter(CsvRecordConverter<?> recordConverter)Sets the record converter to use.CsvDataFormatsetRecordSeparator(String recordSeparator)Sets the record separator.CsvDataFormatsetRecordSeparatorDisabled(boolean recordSeparatorDisabled)Sets whether or not the record separator is disabled.CsvDataFormatsetSkipHeaderRecord(Boolean skipHeaderRecord)Sets whether or not header record must be skipped.CsvDataFormatsetTrailingDelimiter(Boolean trailingDelimiter)Sets whether or not to add a trailing delimiter.CsvDataFormatsetTrim(Boolean trim)Sets whether or not to trim leading and trailing blanks.CsvDataFormatsetUseMaps(boolean useMaps)Sets whether or not the unmarshalling should produce maps instead of lists.CsvDataFormatsetUseOrderedMaps(boolean useOrderedMaps)Sets whether or not the unmarshalling should produce ordered maps instead of lists.Objectunmarshal(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:
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
protected void doInit() throws Exception- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
protected void doStop() throws Exception- 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
public CsvDataFormat setFormat(org.apache.commons.csv.CSVFormat format)
Sets the CSV format before applying any changes. Ifnull, thenCSVFormat.DEFAULTis 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:
trueif the comment markers are disabled,falseotherwise
-
setCommentMarkerDisabled
public CsvDataFormat setCommentMarkerDisabled(boolean commentMarkerDisabled)
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
public Character getCommentMarker()
Gets the comment marker. Ifnullthen the default one of the format used.- Returns:
- Comment marker
-
setCommentMarker
public CsvDataFormat setCommentMarker(Character commentMarker)
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
public Character getDelimiter()
Gets the delimiter. Ifnullthen the default one of the format used.- Returns:
- Delimiter
-
setDelimiter
public CsvDataFormat setDelimiter(Character delimiter)
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
public CsvDataFormat setEscapeDisabled(boolean escapeDisabled)
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
public Character getEscape()
Gets the escape character. Ifnullthen the default one of the format used.- Returns:
- Escape character
-
setEscape
public CsvDataFormat setEscape(Character escape)
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
public CsvDataFormat setHeaderDisabled(boolean headerDisabled)
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
public 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
public CsvDataFormat setHeader(String header)
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
public CsvDataFormat setHeader(String[] header)
-
getAllowMissingColumnNames
public Boolean 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
public CsvDataFormat setAllowMissingColumnNames(Boolean allowMissingColumnNames)
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
public 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
public CsvDataFormat setIgnoreEmptyLines(Boolean ignoreEmptyLines)
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
public 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
public CsvDataFormat setIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces)
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
public CsvDataFormat setNullStringDisabled(boolean nullStringDisabled)
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
public String getNullString()
Gets the null string replacement. Ifnullthen the default one of the format used.- Returns:
- Null string replacement
-
setNullString
public CsvDataFormat setNullString(String nullString)
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
public CsvDataFormat setQuoteDisabled(boolean quoteDisabled)
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
public Character getQuote()
Gets the quote character. Ifnullthen the default one of the format used.- Returns:
- Quote character
-
setQuote
public CsvDataFormat setQuote(Character quote)
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
public CsvDataFormat setQuoteMode(org.apache.commons.csv.QuoteMode quoteMode)
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
public CsvDataFormat setRecordSeparatorDisabled(boolean recordSeparatorDisabled)
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
public String getRecordSeparator()
Gets the record separator. Ifnullthen the default one of the format used.- Returns:
- Record separator
-
setRecordSeparator
public CsvDataFormat setRecordSeparator(String recordSeparator)
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
public Boolean 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
public CsvDataFormat setSkipHeaderRecord(Boolean skipHeaderRecord)
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
public CsvDataFormat setCaptureHeaderRecord(boolean captureHeaderRecord)
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
public CsvDataFormat setLazyLoad(boolean lazyLoad)
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
public CsvDataFormat setUseMaps(boolean useMaps)
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
public CsvDataFormat setUseOrderedMaps(boolean useOrderedMaps)
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
public CsvRecordConverter<?> getRecordConverter()
Gets the record converter to use. Ifnullthen 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. Ifnullthen 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
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
public Boolean 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
public CsvDataFormat setIgnoreHeaderCase(Boolean ignoreHeaderCase)
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
public Boolean 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
public CsvDataFormat setTrailingDelimiter(Boolean trailingDelimiter)
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
public Boolean 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.
-
-