diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index ff41b37d..e07f14f9 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -51,8 +51,23 @@ public class CSVFormat implements Serializable { */ static final char DISABLED = '\ufffe'; + /** + * Starting format with no settings defined; used for creating other formats from scratch. + */ + private static CSVFormat PRISTINE = + new CSVFormat(DISABLED, DISABLED, DISABLED, DISABLED, false, false, false, null, null); + /** Standard comma separated format as defined by RFC 4180. */ - public static final CSVFormat DEFAULT = new CSVFormat(',', '"', DISABLED, DISABLED, true, true, true, CRLF, null); + public static final CSVFormat DEFAULT = + PRISTINE. + withDelimiter(',') + .withEncapsulator('"') + .withLeadingSpacesIgnored(true) + .withTrailingSpacesIgnored(true) + .withEmptyLinesIgnored(true) + .withLineSeparator(CRLF) + ; + /** * Excel file format (using a comma as the value delimiter). @@ -65,10 +80,23 @@ public class CSVFormat implements Serializable { * *
CSVFormat fmt = CSVFormat.EXCEL.withDelimiter(';');*/ - public static final CSVFormat EXCEL = new CSVFormat(',', '"', DISABLED, DISABLED, false, false, false, CRLF, null); + public static final CSVFormat EXCEL = + PRISTINE + .withDelimiter(',') + .withEncapsulator('"') + .withLineSeparator(CRLF) + ; /** Tab-delimited format, with quote; leading and trailing spaces ignored. */ - public static final CSVFormat TDF = new CSVFormat('\t', '"', DISABLED, DISABLED, true, true, true, CRLF, null); + public static final CSVFormat TDF = + PRISTINE + .withDelimiter('\t') + .withEncapsulator('"') + .withLeadingSpacesIgnored(true) + .withTrailingSpacesIgnored(true) + .withEmptyLinesIgnored(true) + .withLineSeparator(CRLF) + ; /** * Default MySQL format used by the SELECT INTO OUTFILE and @@ -78,7 +106,12 @@ public class CSVFormat implements Serializable { * * @see http://dev.mysql.com/doc/refman/5.1/en/load-data.html */ - public static final CSVFormat MYSQL = new CSVFormat('\t', DISABLED, DISABLED, '\\', false, false, false, "\n", null); + public static final CSVFormat MYSQL = + PRISTINE + .withDelimiter('\t') + .withEscape('\\') + .withLineSeparator("\n") + ; /**