@@ -126,11 +126,22 @@ public class CSVFormat implements Serializable {
126126 .withEscape (ESCAPE )
127127 .withLineSeparator (LF );
128128
129+ /**
130+ * Creates a basic CSV format.
131+ *
132+ * @param delimiter
133+ * the char used for value separation, must not be a line break character
134+ * @throws IllegalArgumentException if the delimiter is a line break character
135+ */
136+ public CSVFormat (char delimiter ){
137+ this (delimiter , null , null , null , null , false , false , null , null );
138+ }
139+
129140 /**
130141 * Creates a customized CSV format.
131142 *
132143 * @param delimiter
133- * the char used for value separation
144+ * the char used for value separation, must not be a line break character
134145 * @param quoteChar
135146 * the char used as value encapsulation marker
136147 * @param quotePolicy
@@ -147,10 +158,14 @@ public class CSVFormat implements Serializable {
147158 * the line separator to use for output
148159 * @param header
149160 * the header
161+ * @throws IllegalArgumentException if the delimiter is a line break character
150162 */
151163 public CSVFormat (final char delimiter , final Character quoteChar , final Quote quotePolicy , final Character commentStart , final Character escape , final
152164 boolean ignoreSurroundingSpaces , final boolean ignoreEmptyLines , final String lineSeparator ,
153165 final String [] header ) {
166+ if (isLineBreak (delimiter )) {
167+ throw new IllegalArgumentException ("The delimiter cannot be a line break" );
168+ }
154169 this .delimiter = delimiter ;
155170 this .quoteChar = quoteChar ;
156171 this .quotePolicy = quotePolicy ;
@@ -238,9 +253,6 @@ public char getDelimiter() {
238253 * thrown if the specified character is a line break
239254 */
240255 public CSVFormat withDelimiter (final char delimiter ) {
241- if (isLineBreak (delimiter )) {
242- throw new IllegalArgumentException ("The delimiter cannot be a line break" );
243- }
244256 return new CSVFormat (delimiter , quoteChar , quotePolicy , commentStart , escape ,
245257 ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
246258 }
0 commit comments