@@ -47,11 +47,12 @@ public class CSVFormat implements Serializable {
4747 private final boolean ignoreEmptyLines ;
4848 private final String lineSeparator ; // for outputs
4949 private final String [] header ;
50+ private final Quote quotePolicy ;
5051
5152 /**
5253 * Starting format; used for creating other formats.
5354 */
54- static final CSVFormat PRISTINE = new CSVFormat (COMMA , null , null , null , false , false , null , null );
55+ static final CSVFormat PRISTINE = new CSVFormat (COMMA , null , null , null , null , false , false , null , null );
5556
5657 /**
5758 * Standard comma separated format, as for {@link #RFC4180} but allowing blank lines.
@@ -130,6 +131,8 @@ public class CSVFormat implements Serializable {
130131 * the char used for value separation
131132 * @param encapsulator
132133 * the char used as value encapsulation marker
134+ * @param quotePolicy
135+ * the quote policy
133136 * @param commentStart
134137 * the char used for comment identification
135138 * @param escape
@@ -143,10 +146,12 @@ public class CSVFormat implements Serializable {
143146 * @param header
144147 * the header
145148 */
146- public CSVFormat (final char delimiter , final Character encapsulator , final Character commentStart , final Character escape , final
147- boolean ignoreSurroundingSpaces , final boolean ignoreEmptyLines , final String lineSeparator , final String [] header ) {
149+ public CSVFormat (final char delimiter , final Character encapsulator , final Quote quotePolicy , final Character commentStart , final Character escape , final
150+ boolean ignoreSurroundingSpaces , final boolean ignoreEmptyLines , final String lineSeparator ,
151+ final String [] header ) {
148152 this .delimiter = delimiter ;
149153 this .encapsulator = encapsulator ;
154+ this .quotePolicy = quotePolicy ;
150155 this .commentStart = commentStart ;
151156 this .escape = escape ;
152157 this .ignoreSurroundingSpaces = ignoreSurroundingSpaces ;
@@ -231,8 +236,8 @@ public CSVFormat withDelimiter(final Character delimiter) {
231236 if (isLineBreak (delimiter )) {
232237 throw new IllegalArgumentException ("The delimiter cannot be a line break" );
233238 }
234- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
235- ignoreEmptyLines , lineSeparator , header );
239+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
240+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
236241 }
237242
238243 /**
@@ -270,8 +275,8 @@ public CSVFormat withEncapsulator(final Character encapsulator) {
270275 if (isLineBreak (encapsulator )) {
271276 throw new IllegalArgumentException ("The encapsulator cannot be a line break" );
272277 }
273- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
274- ignoreEmptyLines , lineSeparator , header );
278+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
279+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
275280 }
276281
277282 /**
@@ -322,8 +327,8 @@ public CSVFormat withCommentStart(final Character commentStart) {
322327 if (isLineBreak (commentStart )) {
323328 throw new IllegalArgumentException ("The comment start character cannot be a line break" );
324329 }
325- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
326- ignoreEmptyLines , lineSeparator , header );
330+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
331+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
327332 }
328333
329334 /**
@@ -372,8 +377,8 @@ public CSVFormat withEscape(final Character escape) {
372377 if (isLineBreak (escape )) {
373378 throw new IllegalArgumentException ("The escape character cannot be a line break" );
374379 }
375- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
376- ignoreEmptyLines , lineSeparator , header );
380+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
381+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
377382 }
378383
379384 /**
@@ -404,8 +409,8 @@ public boolean getIgnoreSurroundingSpaces() {
404409 * @return A copy of this format with the specified trimming behavior.
405410 */
406411 public CSVFormat withIgnoreSurroundingSpaces (final boolean ignoreSurroundingSpaces ) {
407- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
408- ignoreEmptyLines , lineSeparator , header );
412+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
413+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
409414 }
410415
411416 /**
@@ -427,8 +432,8 @@ public boolean getIgnoreEmptyLines() {
427432 * @return A copy of this format with the specified empty line skipping behavior.
428433 */
429434 public CSVFormat withIgnoreEmptyLines (final boolean ignoreEmptyLines ) {
430- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
431- ignoreEmptyLines , lineSeparator , header );
435+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
436+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
432437 }
433438
434439 /**
@@ -449,8 +454,8 @@ public String getLineSeparator() {
449454 * @return A copy of this format using the specified output line separator
450455 */
451456 public CSVFormat withLineSeparator (final char lineSeparator ) {
452- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
453- ignoreEmptyLines , String .valueOf (lineSeparator ), header );
457+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
458+ ignoreSurroundingSpaces , ignoreEmptyLines , String .valueOf (lineSeparator ), header );
454459 }
455460
456461 /**
@@ -462,8 +467,21 @@ public CSVFormat withLineSeparator(final char lineSeparator) {
462467 * @return A copy of this format using the specified output line separator
463468 */
464469 public CSVFormat withLineSeparator (final String lineSeparator ) {
465- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
466- ignoreEmptyLines , lineSeparator , header );
470+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
471+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
472+ }
473+
474+ /**
475+ * Returns a copy of this format using the specified output quote policy.
476+ *
477+ * @param quotePolicy
478+ * the quote policy to be used for output.
479+ *
480+ * @return A copy of this format using the specified output line separator
481+ */
482+ public CSVFormat withQuotePolicy (final Quote quotePolicy ) {
483+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
484+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
467485 }
468486
469487 String [] getHeader () {
@@ -490,8 +508,8 @@ String[] getHeader() {
490508 * @return A copy of this format using the specified header
491509 */
492510 public CSVFormat withHeader (final String ... header ) {
493- return new CSVFormat (delimiter , encapsulator , commentStart , escape , ignoreSurroundingSpaces ,
494- ignoreEmptyLines , lineSeparator , header );
511+ return new CSVFormat (delimiter , encapsulator , quotePolicy , commentStart , escape ,
512+ ignoreSurroundingSpaces , ignoreEmptyLines , lineSeparator , header );
495513 }
496514
497515 /**
@@ -546,4 +564,13 @@ public String toString() {
546564 return sb .toString ();
547565 }
548566
567+ /**
568+ * Returns the quote policy output fields.
569+ *
570+ * @return the quote policy
571+ */
572+ public Quote getQuotePolicy () {
573+ return quotePolicy ;
574+ }
575+
549576}
0 commit comments