Class CSVOutput
java.lang.Object
com.invirgance.convirgance.output.CSVOutput
- All Implemented Interfaces:
Output
Writes data in RFC 4180 compliant CSV format. String data will be quoted with
double quotes, quotes in data will be escaped by two double quotes, and
newlines are allowed in quoted data. Lines are always terminated with CRLF as
recommended by the specification.
This class provides functionality to:
- Write data with optional column headers
- Handles string data with proper quote escaping
- Supports configurable character encoding
- Author:
- tadghh
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns thetext/csvMIME typeReturns the current character encoding used for the output stream.String[]Returns the current headers that will be used when writing CSV data.voidsetEncoding(String encoding) Sets the character encoding for the output stream.voidsetHeaders(String... columns) Set the headers to use when writing out CSV valuesCreates a new writer to output CSV data to the specified target.
-
Constructor Details
-
CSVOutput
public CSVOutput()Creates a new CSVOutput instance without predefined headers. Headers will be automatically generated from the first record's keys if not set explicitly. -
CSVOutput
Creates a new CSVOutput with the provided headers.- Parameters:
headers- The columns to use when writing out CSV data
-
CSVOutput
Creates a new CSVOutput with the provided headers.- Parameters:
headers- The columns to use when writing out CSV dataencoding- The character encoding to use for the output
-
-
Method Details
-
setEncoding
Sets the character encoding for the output stream.- Parameters:
encoding- The character encoding to use (e.g., "UTF-8", "ISO-8859-1"). Must be a valid character encoding supported by the JVM.
-
getEncoding
Returns the current character encoding used for the output stream.- Returns:
- The current character encoding (defaults to "UTF-8")
-
setHeaders
Set the headers to use when writing out CSV values- Parameters:
columns- The column headers.
-
getHeaders
Returns the current headers that will be used when writing CSV data. If headers were not explicitly set, they will be generated from the keys found in the first record when writing begins.- Returns:
- The headers used for CSV output.
-
getContentType
Returns thetext/csvMIME type- Specified by:
getContentTypein interfaceOutput- Returns:
- the MIME type
-
write
Creates a new writer to output CSV data to the specified target.
-