Interface CsvWriteParameters


public interface CsvWriteParameters
Parameters that define the format of the CSV being written.

The default parameters will write CSVs that follow these guidelines:

  • Values are separated by commas.
  • Rows are separated by line endings. Supported line endings are defined in LineEnding.
  • Values that contain commas or line endings must be surrounded by double-quotes. For example, "Address, Street".
  • Values that contain double-quotes or escapes must be escaped. For example, pre-pending the character with \.
  • Dates are in the ISO-8601 format. For example, 2001-02-03.
  • DateTimes are in the ISO-8601 format. For example, 2001-02-03T04:05:06.007Z.
If individual Date/DateTime values need to be formatted in a custom way, they can always be converted to a String before being written (e.g. by using LocalDate.format(DateTimeFormatter)).
  • Field Details

    • NO_QUOTES_CHARACTER

      static final char NO_QUOTES_CHARACTER
      Character that can be passed into setQuote(char) if no quotes should be written around individual values.
      See Also:
    • NO_ESCAPE_CHARACTER

      static final char NO_ESCAPE_CHARACTER
      Character that can be provided to setEscape(char) if no escapes should be written before individual values.
      See Also:
  • Method Details

    • setHeaders

      CsvWriteParameters setHeaders(List<String> headers)
      Sets the CSV headers (i.e. column names) for the CSV being written. If not set, the CSV will be written without headers.

      Not setting headers has the implication that certain methods that accept column names (e.g. RowBuilder.setValueByName(String, Object)) will throw exceptions.

      Parameters:
      headers - a list of headers for the CSV. Cannot be null or contain null/duplicate values.
      Returns:
      the current write parameters
    • setSeparator

      CsvWriteParameters setSeparator(char separator)
      Sets the character that separates values. If not set, the separator character defaults to ','.

      For example, if the separator character is ',', then when writing the values "ABC" and "DEF" the output would be "ABC,DEF".

      Parameters:
      separator - the separator char
      Returns:
      the current write parameters
    • setEscape

      CsvWriteParameters setEscape(char escape)
      Sets the character used to escape special characters (e.g. quote characters, escape characters). If not set, the escape character defaults to '\'.

      During writes, this character will be written before any special character that is contained in an individual value.

      Parameters:
      escape - the escape char
      Returns:
      the current write parameters
    • setQuote

      CsvWriteParameters setQuote(char quote)
      Sets the character used to surround individual values. If not set, the quote character defaults to '"'.

      If no quotes should be written, this method can be called with NO_QUOTES_CHARACTER.

      Parameters:
      quote - the quote character
      Returns:
      the current write parameters
    • setLineEnding

      CsvWriteParameters setLineEnding(LineEnding lineEnding)
      Sets the LineEnding that separates individual rows. If not set, the line endings will default to LineEnding.LF.

      During writes, this line ending will be appended to every row.

      Parameters:
      lineEnding - the line ending. Cannot be null.
      Returns:
      the current write parameters