@@ -242,7 +242,7 @@ public CSVFormat getFormat() {
242242 * @see Predefined#Default
243243 */
244244 public static final CSVFormat DEFAULT = new CSVFormat (COMMA , DOUBLE_QUOTE_CHAR , null , null , null , false , true , CRLF ,
245- null , null , null , false , false , false , false , false );
245+ null , null , null , false , false , false , false , false , false );
246246
247247 /**
248248 * Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is
@@ -537,7 +537,7 @@ private static boolean isLineBreak(final Character c) {
537537 */
538538 public static CSVFormat newFormat (final char delimiter ) {
539539 return new CSVFormat (delimiter , null , null , null , null , false , false , null , null , null , null , false , false ,
540- false , false , false );
540+ false , false , false , false );
541541 }
542542
543543 /**
@@ -584,6 +584,8 @@ public static CSVFormat valueOf(final String format) {
584584
585585 private final boolean trim ;
586586
587+ private final boolean autoFlush ;
588+
587589 /**
588590 * Creates a customized CSV format.
589591 *
@@ -619,15 +621,16 @@ public static CSVFormat valueOf(final String format) {
619621 * TODO
620622 * @param trailingDelimiter
621623 * TODO
624+ * @param autoFlush
622625 * @throws IllegalArgumentException
623626 * if the delimiter is a line break character
624627 */
625628 private CSVFormat (final char delimiter , final Character quoteChar , final QuoteMode quoteMode ,
626- final Character commentStart , final Character escape , final boolean ignoreSurroundingSpaces ,
627- final boolean ignoreEmptyLines , final String recordSeparator , final String nullString ,
628- final Object [] headerComments , final String [] header , final boolean skipHeaderRecord ,
629- final boolean allowMissingColumnNames , final boolean ignoreHeaderCase , final boolean trim ,
630- final boolean trailingDelimiter ) {
629+ final Character commentStart , final Character escape , final boolean ignoreSurroundingSpaces ,
630+ final boolean ignoreEmptyLines , final String recordSeparator , final String nullString ,
631+ final Object [] headerComments , final String [] header , final boolean skipHeaderRecord ,
632+ final boolean allowMissingColumnNames , final boolean ignoreHeaderCase , final boolean trim ,
633+ final boolean trailingDelimiter , boolean autoFlush ) {
631634 this .delimiter = delimiter ;
632635 this .quoteCharacter = quoteChar ;
633636 this .quoteMode = quoteMode ;
@@ -644,6 +647,7 @@ private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMo
644647 this .ignoreHeaderCase = ignoreHeaderCase ;
645648 this .trailingDelimiter = trailingDelimiter ;
646649 this .trim = trim ;
650+ this .autoFlush = autoFlush ;
647651 validate ();
648652 }
649653
@@ -887,6 +891,16 @@ public boolean getTrim() {
887891 return trim ;
888892 }
889893
894+ /**
895+ * Returns whether to flush on close.
896+ *
897+ * @return whether to flush on close.
898+ * @since 1.6
899+ */
900+ public boolean getAutoFlush () {
901+ return autoFlush ;
902+ }
903+
890904 @ Override
891905 public int hashCode () {
892906 final int prime = 31 ;
@@ -1431,7 +1445,7 @@ public CSVFormat withAllowMissingColumnNames() {
14311445 public CSVFormat withAllowMissingColumnNames (final boolean allowMissingColumnNames ) {
14321446 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
14331447 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1434- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1448+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
14351449 }
14361450
14371451 /**
@@ -1466,7 +1480,7 @@ public CSVFormat withCommentMarker(final Character commentMarker) {
14661480 }
14671481 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
14681482 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1469- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1483+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
14701484 }
14711485
14721486 /**
@@ -1484,7 +1498,7 @@ public CSVFormat withDelimiter(final char delimiter) {
14841498 }
14851499 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
14861500 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1487- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1501+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
14881502 }
14891503
14901504 /**
@@ -1515,7 +1529,7 @@ public CSVFormat withEscape(final Character escape) {
15151529 }
15161530 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escape , ignoreSurroundingSpaces ,
15171531 ignoreEmptyLines , recordSeparator , nullString , headerComments , header , skipHeaderRecord ,
1518- allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1532+ allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
15191533 }
15201534
15211535 /**
@@ -1670,7 +1684,7 @@ public CSVFormat withHeader(final ResultSetMetaData metaData) throws SQLExceptio
16701684 public CSVFormat withHeader (final String ... header ) {
16711685 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
16721686 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1673- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1687+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
16741688 }
16751689
16761690 /**
@@ -1691,7 +1705,7 @@ public CSVFormat withHeader(final String... header) {
16911705 public CSVFormat withHeaderComments (final Object ... headerComments ) {
16921706 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
16931707 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1694- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1708+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
16951709 }
16961710
16971711 /**
@@ -1716,7 +1730,7 @@ public CSVFormat withIgnoreEmptyLines() {
17161730 public CSVFormat withIgnoreEmptyLines (final boolean ignoreEmptyLines ) {
17171731 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
17181732 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1719- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1733+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
17201734 }
17211735
17221736 /**
@@ -1742,7 +1756,7 @@ public CSVFormat withIgnoreHeaderCase() {
17421756 public CSVFormat withIgnoreHeaderCase (final boolean ignoreHeaderCase ) {
17431757 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
17441758 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1745- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1759+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
17461760 }
17471761
17481762 /**
@@ -1767,7 +1781,7 @@ public CSVFormat withIgnoreSurroundingSpaces() {
17671781 public CSVFormat withIgnoreSurroundingSpaces (final boolean ignoreSurroundingSpaces ) {
17681782 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
17691783 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1770- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1784+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
17711785 }
17721786
17731787 /**
@@ -1786,7 +1800,7 @@ public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpac
17861800 public CSVFormat withNullString (final String nullString ) {
17871801 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
17881802 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1789- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1803+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
17901804 }
17911805
17921806 /**
@@ -1817,7 +1831,7 @@ public CSVFormat withQuote(final Character quoteChar) {
18171831 }
18181832 return new CSVFormat (delimiter , quoteChar , quoteMode , commentMarker , escapeCharacter , ignoreSurroundingSpaces ,
18191833 ignoreEmptyLines , recordSeparator , nullString , headerComments , header , skipHeaderRecord ,
1820- allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1834+ allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
18211835 }
18221836
18231837 /**
@@ -1831,7 +1845,7 @@ public CSVFormat withQuote(final Character quoteChar) {
18311845 public CSVFormat withQuoteMode (final QuoteMode quoteModePolicy ) {
18321846 return new CSVFormat (delimiter , quoteCharacter , quoteModePolicy , commentMarker , escapeCharacter ,
18331847 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1834- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1848+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
18351849 }
18361850
18371851 /**
@@ -1869,7 +1883,7 @@ public CSVFormat withRecordSeparator(final char recordSeparator) {
18691883 public CSVFormat withRecordSeparator (final String recordSeparator ) {
18701884 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
18711885 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1872- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1886+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
18731887 }
18741888
18751889 /**
@@ -1896,7 +1910,7 @@ public CSVFormat withSkipHeaderRecord() {
18961910 public CSVFormat withSkipHeaderRecord (final boolean skipHeaderRecord ) {
18971911 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
18981912 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1899- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1913+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
19001914 }
19011915
19021916 /**
@@ -1921,7 +1935,7 @@ public CSVFormat withTrailingDelimiter() {
19211935 public CSVFormat withTrailingDelimiter (final boolean trailingDelimiter ) {
19221936 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
19231937 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1924- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1938+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
19251939 }
19261940
19271941 /**
@@ -1946,6 +1960,21 @@ public CSVFormat withTrim() {
19461960 public CSVFormat withTrim (final boolean trim ) {
19471961 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
19481962 ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1949- skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter );
1963+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
1964+ }
1965+
1966+ /**
1967+ * Returns a new {@code CSVFormat} with whether to flush on close.
1968+ *
1969+ * @param autoFlush
1970+ * whether to flush on close.
1971+ *
1972+ * @return A new CSVFormat that is equal to this but with the specified autoFlush setting.
1973+ * @since 1.6
1974+ */
1975+ public CSVFormat withAutoFlush (final boolean autoFlush ) {
1976+ return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
1977+ ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1978+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush );
19501979 }
19511980}
0 commit comments