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 Details

    • CsvDataFormat

      public CsvDataFormat()
    • CsvDataFormat

      public CsvDataFormat(org.apache.commons.csv.CSVFormat format)
  • Method Details

    • getDataFormatName

      public String getDataFormatName()
      Specified by:
      getDataFormatName in interface org.apache.camel.spi.DataFormatName
    • marshal

      public void marshal(org.apache.camel.Exchange exchange, Object object, OutputStream outputStream) throws Exception
      Specified by:
      marshal in interface org.apache.camel.spi.DataFormat
      Throws:
      Exception
    • unmarshal

      public Object unmarshal(org.apache.camel.Exchange exchange, InputStream inputStream) throws Exception
      Specified by:
      unmarshal in interface org.apache.camel.spi.DataFormat
      Throws:
      Exception
    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.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 be null, the default one is CSVFormat.DEFAULT.
      Returns:
      CSV format
    • setFormat

      public CsvDataFormat setFormat(org.apache.commons.csv.CSVFormat format)
      Sets the CSV format before applying any changes. If null, then CSVFormat.DEFAULT is used instead.
      Parameters:
      format - CSV format
      Returns:
      Current CsvDataFormat, fluent API
      See Also:
      • CSVFormat
      • CSVFormat.DEFAULT
    • setMarshallerFactory

      public CsvDataFormat setMarshallerFactory(CsvMarshallerFactory marshallerFactory)
      Sets the CsvMarshaller factory. If null, then CsvMarshallerFactory.DEFAULT is used instead.
      Parameters:
      marshallerFactory -
      Returns:
      Current CsvDataFormat, fluent API
    • getMarshallerFactory

      public CsvMarshallerFactory getMarshallerFactory()
      Returns the used CsvMarshallerFactory.
      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:
    • 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. If null then the default one of the format used.
      Returns:
      Comment marker
    • setCommentMarker

      public CsvDataFormat setCommentMarker(Character commentMarker)
      Sets the comment marker to use. If null 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. If null then the default one of the format used.
      Returns:
      Delimiter
    • setDelimiter

      public CsvDataFormat setDelimiter(Character delimiter)
      Sets the delimiter. If null 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. If null then the default one of the format used.
      Returns:
      Escape character
    • setEscape

      public CsvDataFormat setEscape(Character escape)
      Sets the escape character. If null 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. If null 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. If null 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. If null 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. If null 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. If null 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. If null 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. If null 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. If null 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. If null then the default one of the format used.
      Returns:
      Null string replacement
    • setNullString

      public CsvDataFormat setNullString(String nullString)
      Sets the null string replacement. If null 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. If null then the default one of the format used.
      Returns:
      Quote character
    • setQuote

      public CsvDataFormat setQuote(Character quote)
      Sets the quote character. If null 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. If null 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. If null 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. If null then the default one of the format used.
      Returns:
      Record separator
    • setRecordSeparator

      public CsvDataFormat setRecordSeparator(String recordSeparator)
      Sets the record separator. If null 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. If null 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. If null 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. If null then it will use isUseMaps() for finding the proper converter.
      Returns:
      Record converter to use
    • setRecordConverter

      public CsvDataFormat setRecordConverter(CsvRecordConverter<?> recordConverter)
      Sets the record converter to use. If null then it will use isUseMaps() 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 return null 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 return null 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 return null if value has NOT been set.