CSVWriter.javawrite() overloads for strings (with double-quote escaping), long integers, dates (ISO 8601 format), and generic objects. Configurable separator character, line ending, and date format. Used for ProjectForge data exports (address lists, timesheet exports, financial reports).java.io.PrintWriter / java.io.Writer — Text outputjava.text.DateFormat / SimpleDateFormat — Date formatting for CSV date columnsjava.util.Date — Date value typejava.util.TimeZone — UTC timezone for date formatting| Setting | Default | Setter |
|---|---|---|
| CSV separator | ';' (semicolon — European convention) | setCsvSeparator(char) |
| Line ending | "\n" (Unix newline) | setCr(String) |
| Date format | "yyyy-MM-dd HH:mm:ss.SSS" | setDateFormat(DateFormat) |
| Date timezone | UTC | Hardcoded in constructor |
All write() methods return this (the CSVWriter instance), enabling method chaining:
csvWriter.write("Name").write("Age").write(42L).writeEndOfLine();
| Method | Formatting | Quoting |
|---|---|---|
write(String s) | Raw string with " escaped to "" (doubling) | Always wrapped in "..." — follows RFC 4180 quoting rules |
write(long value) | Direct numeric output via PrintWriter.print() | None — numbers are unquoted |
write(Date value) | Formatted via dateFormat.format() in UTC | Wrapped in quotes — dates may contain spaces or special chars |
write(Object value) | Fallback: String.valueOf(value) | None — generic objects are unquoted (risky for objects with commas/quotes) |
The write(String) method implements proper CSV escaping per RFC 4180:
writeSeparator() with the firstEntry flag)")"), output it twice ("") — the standard CSV escape sequence")writeLine(Object[] values) — Writes all values in the array, then calls writeEndOfLine()writeEndOfLine() — Outputs the configured line ending (\n by default) and resets firstEntry = trueThe firstEntry boolean flag tracks whether we're at the start of a line:
firstEntry == true: set to false (first cell — no separator needed)firstEntry == false: output the separator character before the cell valueCSVWriter defines DEFAULT_CSV_SEPARATOR_CHAR = ';' as a public constant, which CSVParser references to ensure consistent default separator between reader and writer.
This implementation is intentionally minimal compared to Apache Commons CSV or OpenCSV:
CSVParser.parseHeadCols())write(Object) method does NOT quote the output — it calls String.valueOf(value) and writes directly. If the object's toString() returns a string containing commas, semicolons, or newlines, the resulting CSV will be malformed. This is acceptable because callers are expected to use the type-specific overloads."yyyy-MM-dd HH:mm:ss.SSS" is ISO 8601-like but uses a space separator instead of 'T'.868d6abb7 2025 -> 2026 63081666f Source file headers: 2024-> 2025. a73905c14 Fix typos in projectforge*/ directories Found via codespell b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022 ceb63e8a1 Source code header: (C) 2001-2021. 7c79f1922 Copyright of source header -> 2020.