1717
1818package org .apache .commons .csv ;
1919
20- import static org .apache .commons .csv .Constants .BACKSLASH ;
21- import static org .apache .commons .csv .Constants .COMMA ;
22- import static org .apache .commons .csv .Constants .COMMENT ;
23- import static org .apache .commons .csv .Constants .CR ;
24- import static org .apache .commons .csv .Constants .CRLF ;
25- import static org .apache .commons .csv .Constants .DOUBLE_QUOTE_CHAR ;
26- import static org .apache .commons .csv .Constants .EMPTY ;
27- import static org .apache .commons .csv .Constants .LF ;
28- import static org .apache .commons .csv .Constants .PIPE ;
29- import static org .apache .commons .csv .Constants .SP ;
30- import static org .apache .commons .csv .Constants .TAB ;
3120import static org .apache .commons .io .IOUtils .EOF ;
3221
3322import java .io .File ;
@@ -203,7 +192,7 @@ public static class Builder {
203192 * @return a copy of the builder
204193 */
205194 public static Builder create () {
206- return new Builder (CSVFormat . DEFAULT );
195+ return new Builder (DEFAULT );
207196 }
208197
209198 /**
@@ -850,57 +839,57 @@ public enum Predefined {
850839 /**
851840 * @see CSVFormat#DEFAULT
852841 */
853- Default (CSVFormat . DEFAULT ),
842+ Default (DEFAULT ),
854843
855844 /**
856845 * @see CSVFormat#EXCEL
857846 */
858- Excel (CSVFormat . EXCEL ),
847+ Excel (EXCEL ),
859848
860849 /**
861850 * @see CSVFormat#INFORMIX_UNLOAD
862851 * @since 1.3
863852 */
864- InformixUnload (CSVFormat . INFORMIX_UNLOAD ),
853+ InformixUnload (INFORMIX_UNLOAD ),
865854
866855 /**
867856 * @see CSVFormat#INFORMIX_UNLOAD_CSV
868857 * @since 1.3
869858 */
870- InformixUnloadCsv (CSVFormat . INFORMIX_UNLOAD_CSV ),
859+ InformixUnloadCsv (INFORMIX_UNLOAD_CSV ),
871860
872861 /**
873862 * @see CSVFormat#MONGODB_CSV
874863 * @since 1.7
875864 */
876- MongoDBCsv (CSVFormat . MONGODB_CSV ),
865+ MongoDBCsv (MONGODB_CSV ),
877866
878867 /**
879868 * @see CSVFormat#MONGODB_TSV
880869 * @since 1.7
881870 */
882- MongoDBTsv (CSVFormat . MONGODB_TSV ),
871+ MongoDBTsv (MONGODB_TSV ),
883872
884873 /**
885874 * @see CSVFormat#MYSQL
886875 */
887- MySQL (CSVFormat . MYSQL ),
876+ MySQL (MYSQL ),
888877
889878 /**
890879 * @see CSVFormat#ORACLE
891880 */
892- Oracle (CSVFormat . ORACLE ),
881+ Oracle (ORACLE ),
893882
894883 /**
895884 * @see CSVFormat#POSTGRESQL_CSV
896885 * @since 1.5
897886 */
898- PostgreSQLCsv (CSVFormat . POSTGRESQL_CSV ),
887+ PostgreSQLCsv (POSTGRESQL_CSV ),
899888
900889 /**
901890 * @see CSVFormat#POSTGRESQL_CSV
902891 */
903- PostgreSQLText (CSVFormat . POSTGRESQL_TEXT ),
892+ PostgreSQLText (POSTGRESQL_TEXT ),
904893
905894 /**
906895 * @see CSVFormat#RFC4180
@@ -945,8 +934,8 @@ public CSVFormat getFormat() {
945934 *
946935 * @see Predefined#Default
947936 */
948- public static final CSVFormat DEFAULT = new CSVFormat (COMMA , DOUBLE_QUOTE_CHAR , null , null , null , false , true , CRLF , null , null , null , false , false , false ,
949- false , false , false , DuplicateHeaderMode .ALLOW_ALL , false , false );
937+ public static final CSVFormat DEFAULT = new CSVFormat (Constants . COMMA , Constants . DOUBLE_QUOTE_CHAR , null , null , null , false , true , Constants . CRLF , null ,
938+ null , null , false , false , false , false , false , false , DuplicateHeaderMode .ALLOW_ALL , false , false );
950939
951940 /**
952941 * Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is locale-dependent, it might be necessary
@@ -1014,10 +1003,10 @@ public CSVFormat getFormat() {
10141003 */
10151004 // @formatter:off
10161005 public static final CSVFormat INFORMIX_UNLOAD = DEFAULT .builder ()
1017- .setDelimiter (PIPE )
1018- .setEscape (BACKSLASH )
1019- .setQuote (DOUBLE_QUOTE_CHAR )
1020- .setRecordSeparator (LF )
1006+ .setDelimiter (Constants . PIPE )
1007+ .setEscape (Constants . BACKSLASH )
1008+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
1009+ .setRecordSeparator (Constants . LF )
10211010 .build ();
10221011 // @formatter:on
10231012
@@ -1045,9 +1034,9 @@ public CSVFormat getFormat() {
10451034 */
10461035 // @formatter:off
10471036 public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT .builder ()
1048- .setDelimiter (COMMA )
1049- .setQuote (DOUBLE_QUOTE_CHAR )
1050- .setRecordSeparator (LF )
1037+ .setDelimiter (Constants . COMMA )
1038+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
1039+ .setRecordSeparator (Constants . LF )
10511040 .build ();
10521041 // @formatter:on
10531042
@@ -1085,9 +1074,9 @@ public CSVFormat getFormat() {
10851074 */
10861075 // @formatter:off
10871076 public static final CSVFormat MONGODB_CSV = DEFAULT .builder ()
1088- .setDelimiter (COMMA )
1089- .setEscape (DOUBLE_QUOTE_CHAR )
1090- .setQuote (DOUBLE_QUOTE_CHAR )
1077+ .setDelimiter (Constants . COMMA )
1078+ .setEscape (Constants . DOUBLE_QUOTE_CHAR )
1079+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
10911080 .setQuoteMode (QuoteMode .MINIMAL )
10921081 .setSkipHeaderRecord (false )
10931082 .build ();
@@ -1122,9 +1111,9 @@ public CSVFormat getFormat() {
11221111 */
11231112 // @formatter:off
11241113 public static final CSVFormat MONGODB_TSV = DEFAULT .builder ()
1125- .setDelimiter (TAB )
1126- .setEscape (DOUBLE_QUOTE_CHAR )
1127- .setQuote (DOUBLE_QUOTE_CHAR )
1114+ .setDelimiter (Constants . TAB )
1115+ .setEscape (Constants . DOUBLE_QUOTE_CHAR )
1116+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
11281117 .setQuoteMode (QuoteMode .MINIMAL )
11291118 .setSkipHeaderRecord (false )
11301119 .build ();
@@ -1157,11 +1146,11 @@ public CSVFormat getFormat() {
11571146 */
11581147 // @formatter:off
11591148 public static final CSVFormat MYSQL = DEFAULT .builder ()
1160- .setDelimiter (TAB )
1161- .setEscape (BACKSLASH )
1149+ .setDelimiter (Constants . TAB )
1150+ .setEscape (Constants . BACKSLASH )
11621151 .setIgnoreEmptyLines (false )
11631152 .setQuote (null )
1164- .setRecordSeparator (LF )
1153+ .setRecordSeparator (Constants . LF )
11651154 .setNullString (Constants .SQL_NULL_STRING )
11661155 .setQuoteMode (QuoteMode .ALL_NON_NULL )
11671156 .build ();
@@ -1196,10 +1185,10 @@ public CSVFormat getFormat() {
11961185 */
11971186 // @formatter:off
11981187 public static final CSVFormat ORACLE = DEFAULT .builder ()
1199- .setDelimiter (COMMA )
1200- .setEscape (BACKSLASH )
1188+ .setDelimiter (Constants . COMMA )
1189+ .setEscape (Constants . BACKSLASH )
12011190 .setIgnoreEmptyLines (false )
1202- .setQuote (DOUBLE_QUOTE_CHAR )
1191+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
12031192 .setNullString (Constants .SQL_NULL_STRING )
12041193 .setTrim (true )
12051194 .setRecordSeparator (System .lineSeparator ())
@@ -1235,12 +1224,12 @@ public CSVFormat getFormat() {
12351224 */
12361225 // @formatter:off
12371226 public static final CSVFormat POSTGRESQL_CSV = DEFAULT .builder ()
1238- .setDelimiter (COMMA )
1227+ .setDelimiter (Constants . COMMA )
12391228 .setEscape (null )
12401229 .setIgnoreEmptyLines (false )
1241- .setQuote (DOUBLE_QUOTE_CHAR )
1242- .setRecordSeparator (LF )
1243- .setNullString (EMPTY )
1230+ .setQuote (Constants . DOUBLE_QUOTE_CHAR )
1231+ .setRecordSeparator (Constants . LF )
1232+ .setNullString (Constants . EMPTY )
12441233 .setQuoteMode (QuoteMode .ALL_NON_NULL )
12451234 .build ();
12461235 // @formatter:off
@@ -1273,11 +1262,11 @@ public CSVFormat getFormat() {
12731262 */
12741263 // @formatter:off
12751264 public static final CSVFormat POSTGRESQL_TEXT = DEFAULT .builder ()
1276- .setDelimiter (TAB )
1277- .setEscape (BACKSLASH )
1265+ .setDelimiter (Constants . TAB )
1266+ .setEscape (Constants . BACKSLASH )
12781267 .setIgnoreEmptyLines (false )
12791268 .setQuote (null )
1280- .setRecordSeparator (LF )
1269+ .setRecordSeparator (Constants . LF )
12811270 .setNullString (Constants .SQL_NULL_STRING )
12821271 .setQuoteMode (QuoteMode .ALL_NON_NULL )
12831272 .build ();
@@ -1319,7 +1308,7 @@ public CSVFormat getFormat() {
13191308 */
13201309 // @formatter:off
13211310 public static final CSVFormat TDF = DEFAULT .builder ()
1322- .setDelimiter (TAB )
1311+ .setDelimiter (Constants . TAB )
13231312 .setIgnoreSurroundingSpaces (true )
13241313 .build ();
13251314 // @formatter:on
@@ -1356,7 +1345,7 @@ private static boolean contains(final String source, final char searchCh) {
13561345 * @return true if {@code c} contains a line break character.
13571346 */
13581347 private static boolean containsLineBreak (final String source ) {
1359- return contains (source , CR ) || contains (source , LF );
1348+ return contains (source , Constants . CR ) || contains (source , Constants . LF );
13601349 }
13611350
13621351 static boolean isBlank (final String value ) {
@@ -1371,7 +1360,7 @@ static boolean isBlank(final String value) {
13711360 * @return true if {@code c} is a line break character.
13721361 */
13731362 private static boolean isLineBreak (final char c ) {
1374- return c == LF || c == CR ;
1363+ return c == Constants . LF || c == Constants . CR ;
13751364 }
13761365
13771366 /**
@@ -1387,7 +1376,7 @@ private static boolean isLineBreak(final Character c) {
13871376
13881377 /** Same test as in as {@link String#trim()}. */
13891378 private static boolean isTrimChar (final char ch ) {
1390- return ch <= SP ;
1379+ return ch <= Constants . SP ;
13911380 }
13921381
13931382 /** Same test as in as {@link String#trim()}. */
@@ -2121,7 +2110,7 @@ public synchronized void print(final Object value, final Appendable out, final b
21212110 if (value == null ) {
21222111 // https://issues.apache.org/jira/browse/CSV-203
21232112 if (null == nullString ) {
2124- charSequence = EMPTY ;
2113+ charSequence = Constants . EMPTY ;
21252114 } else if (QuoteMode .ALL == quoteMode ) {
21262115 charSequence = quotedNullString ;
21272116 } else {
@@ -2259,8 +2248,8 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
22592248 while (pos < end ) {
22602249 char c = charSeq .charAt (pos );
22612250 final boolean isDelimiterStart = isDelimiter (c , charSeq , pos , delimArray , delimLength );
2262- final boolean isCr = c == CR ;
2263- final boolean isLf = c == LF ;
2251+ final boolean isCr = c == Constants . CR ;
2252+ final boolean isLf = c == Constants . LF ;
22642253 if (isCr || isLf || c == escape || isDelimiterStart ) {
22652254 // write out segment up until this char
22662255 if (pos > start ) {
@@ -2308,8 +2297,8 @@ private void printWithEscapes(final Reader reader, final Appendable appendable)
23082297 Arrays .fill (lookAheadBuffer , (char ) 0 );
23092298 final String test = builder .toString () + new String (bufferedReader .lookAhead (lookAheadBuffer ));
23102299 final boolean isDelimiterStart = isDelimiter ((char ) c , test , pos , delimArray , delimLength );
2311- final boolean isCr = c == CR ;
2312- final boolean isLf = c == LF ;
2300+ final boolean isCr = c == Constants . CR ;
2301+ final boolean isLf = c == Constants . LF ;
23132302 if (isCr || isLf || c == escape || isDelimiterStart ) {
23142303 // write out segment up until this char
23152304 if (pos > start ) {
@@ -2381,15 +2370,15 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
23812370 }
23822371 } else {
23832372 char c = charSeq .charAt (pos );
2384- if (c <= COMMENT ) {
2373+ if (c <= Constants . COMMENT ) {
23852374 // Some other chars at the start of a value caused the parser to fail, so for now
23862375 // encapsulate if we start in anything less than '#'. We are being conservative
23872376 // by including the default comment char too.
23882377 quote = true ;
23892378 } else {
23902379 while (pos < len ) {
23912380 c = charSeq .charAt (pos );
2392- if (c == LF || c == CR || c == quoteChar || c == escapeChar || isDelimiter (c , charSeq , pos , delim , delimLength )) {
2381+ if (c == Constants . LF || c == Constants . CR || c == quoteChar || c == escapeChar || isDelimiter (c , charSeq , pos , delim , delimLength )) {
23932382 quote = true ;
23942383 break ;
23952384 }
0 commit comments