Class CSVFormat

java.lang.Object
nl.colorize.util.stats.CSVFormat

public class CSVFormat extends Object
Describes the format of a CSV file, which is necessary since the CSV file format is not fully standardized. Instances of the format can then be used to parse CSV files into CSVRecords, or to serialize records into CSV files.

Note: This class is intended for basic CSV support. When working with CSV files produced by other applications, prefer using the FastCSV library.

  • Field Details

    • COMMA

      public static final CSVFormat COMMA
    • TAB

      public static final CSVFormat TAB
    • SEMICOLON

      public static final CSVFormat SEMICOLON
  • Method Details

    • withQuotes

      public CSVFormat withQuotes()
    • withLineSeparator

      public CSVFormat withLineSeparator(String lineSeparator)
    • parseCSV

      public List<CSVRecord> parseCSV(String csv)
      Parses the specified CSV file using this CSVFormat, and returns the resulting records. If this CSV format includes header information, the first record in the file is assumed to contain the headers.
    • toCSV

      public String toCSV(List<String> cells)
      Serializes the specified record using this CSV format. The serialized line will end with a trailing line separator. This method can be used for both rows and headers, since CSV files do not differentiate between the two apart from their location within the file.
      Throws:
      IllegalArgumentException - if the record does not contain at least one cell.
    • toCSV

      public String toCSV(String... cells)
      Serializes the specified record using this CSV format. The serialized line will end with a trailing line separator. This method can be used for both rows and headers, since CSV files do not differentiate between the two apart from their location within the file.
      Throws:
      IllegalArgumentException - if the record does not contain at least one cell.
    • toCSV

      public String toCSV(CSVRecord record)
      Serializes the specified record using this CSV format. The serialized line will end with a trailing line separator.
      Throws:
      IllegalArgumentException - if the record does not contain at least one cell.
    • withHeaders

      public static CSVFormat withHeaders(char delimiter)
    • withoutHeaders

      public static CSVFormat withoutHeaders(char delimiter)