Class CSVFormat
java.lang.Object
nl.colorize.util.CSVFormat
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<T> List<T> deserialize(String csv, Function<CSVRecord, T> mapper) Uses this CSV format to deserialize CSV records into objects.<T> List<T> deserialize(List<CSVRecord> records, Function<CSVRecord, T> mapper) Uses this CSV format to deserialize CSV records into objects.Returns aCSVRecordbased on this CSV format and consisting of the specified cells.Returns aCSVRecordbased on this CSV format and consisting of the specified cells.Returns aCSVRecordbased on this CSV format and consisting of the specified cells and column header information.Returns aCSVRecordbased on this CSV format and consisting of the specified cells and column header information.Parses the specified CSV file using thisCSVFormat, and returns the resulting records.<T> StringUses this CSV format to serialize a number of objects to CSV.<T> StringUses this CSV format to serialize a number of objects to CSV.Serializes the specified records using this CSV format.Serializes the specified record using this CSV format.static CSVFormatwithHeaders(char delimiter) Creates aCSVFormatwith the specified delimiter, which includes column header information.withLineSeparator(String lineSeparator) static CSVFormatwithoutHeaders(char delimiter) Creates aCSVFormatwith the specified delimiter, which does not include column header information.
-
Field Details
-
COMMA
-
TAB
-
SEMICOLON
-
-
Method Details
-
withQuotes
-
withLineSeparator
-
of
Returns aCSVRecordbased on this CSV format and consisting of the specified cells and column header information.- Throws:
IllegalArgumentException- if the number of column headers does not match the number of cells, or if there are no cells.
-
of
Returns aCSVRecordbased on this CSV format and consisting of the specified cells and column header information.- Throws:
IllegalArgumentException- if the number of column headers does not match the number of cells, or if there are no cells.
-
of
Returns aCSVRecordbased on this CSV format and consisting of the specified cells. The record will not have any column header information.- Throws:
IllegalArgumentException- if there are no cells.
-
of
Returns aCSVRecordbased on this CSV format and consisting of the specified cells. The record will not have any column header information.- Throws:
IllegalArgumentException- if there are no cells.
-
parseCSV
-
toCSV
Serializes the specified records using this CSV format. If this format includes column header information, the records will be preceded by a record containing the column headers. If the list of records is empty, this returns an empty string.- Throws:
IllegalStateException- if this CSV format includes column header information, but some of the records do not include column headers or include different column headers.
-
toCSV
-
serialize
Uses this CSV format to serialize a number of objects to CSV. The specified callback function is used to map each object to a CSV record.- Throws:
IllegalArgumentException- if the number of column headers does not match the number of cells in the records.
-
serialize
Uses this CSV format to serialize a number of objects to CSV. The specified callback function is used to map each object to a CSV record, with each record receiving the column header information fromcolumns.- Throws:
IllegalArgumentException- if the number of column headers does not match the number of cells in the records.
-
deserialize
-
deserialize
-
withHeaders
-
withoutHeaders
-