Interface CsvReadParameters


public interface CsvReadParameters
Parameters that define the format of the CSV being read.

The default parameters will handle 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 the CSV being read does not follow these guidelines, then these parameters can be modified as needed. For CSVs with custom Date or DateTime formatting, the values can be read in as a CsvValueType.STRING and parsed manually. For example, via LocalDate.parse(CharSequence, java.time.format.DateTimeFormatter).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    Character that can be provided to setEscape(char) if occurrences of the default escape character ('\') should be treated as the literal character, and not as a marker for the start of an escaped character.
    static final char
    Character that can be provided to setQuote(char) if occurrences of the default quote character ('"') should be treated as the literal character, and not as a marker for the start/end of an individual value.
  • Method Summary

    Modifier and Type
    Method
    Description
    setEscape(char escape)
    Sets the character used to escape quote characters and other escape characters in individual values.
    setHasHeaders(boolean hasHeaders)
    Sets whether or not the CSV being read has headers.
    setQuote(char quote)
    Sets the character used to surround individual values.
    setSeparator(char separator)
    Sets the character that separates values.
  • Field Details

    • NO_QUOTES_CHARACTER

      static final char NO_QUOTES_CHARACTER
      Character that can be provided to setQuote(char) if occurrences of the default quote character ('"') should be treated as the literal character, and not as a marker for the start/end of an individual value.
      See Also:
    • NO_ESCAPE_CHARACTER

      static final char NO_ESCAPE_CHARACTER
      Character that can be provided to setEscape(char) if occurrences of the default escape character ('\') should be treated as the literal character, and not as a marker for the start of an escaped character.
      See Also:
  • Method Details

    • setHasHeaders

      CsvReadParameters setHasHeaders(boolean hasHeaders)
      Sets whether or not the CSV being read has headers. If not set, it will be assumed that the CSV being read contains headers.

      Note that if this is set to true, the CSV being read must not contain multiple headers that have the same name. If it does, reading will throw an exception. If it is necessary to read in a CSV that contains multiple headers with the same name, the CSV can be read in as a CSV without headers. In that case, the header row will be treated as a regular value row, which can have duplicates.

      Parameters:
      hasHeaders - true if the CSV being read has headers; false if the CSV being read doesn't have headers
      Returns:
      the current read parameters
    • setSeparator

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

      For example, when reading the value "ABC,DEF" if the separator character is ',', then "ABC" and "DEF" would be the individual values. If the separator character is 'D', then "ABC," and "EF" would be the individual values.

      The separator, escape, and quote characters must be different.

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

      CsvReadParameters setEscape(char escape)
      Sets the character used to escape quote characters and other escape characters in individual values. If not set, the escape character defaults to '\'.

      When this character is encountered during a read, it will be assumed that it is escaping the subsequent character. If the escape character is intended to be contained in the content of an individual value, it must be preceded by itself.

      For example, when reading the value "foo\\bar" if the escape character is '\', then the value would be read as "foo\bar".

      The separator, escape, and quote characters must be different.

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

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

      When this character is encountered during a read, it will be assumed that it is either the start/end of an individual value. If the quote character is intended to be contained in the content of an individual value, it must be preceded by the escape character (set by setEscape(char)).

      If there are non-escaped quotes that should be read in as a value, then this can be called with NO_QUOTES_CHARACTER.

      The separator, escape, and quote characters must be different.

      Parameters:
      quote - the quote char
      Returns:
      the current read parameters