@@ -2125,11 +2125,9 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
21252125 int start = 0 ;
21262126 int pos = 0 ;
21272127 final int end = charSeq .length ();
2128-
21292128 final char [] delim = getDelimiterString ().toCharArray ();
21302129 final int delimLength = delim .length ;
21312130 final char escape = getEscapeCharacter ().charValue ();
2132-
21332131 while (pos < end ) {
21342132 char c = charSeq .charAt (pos );
21352133 final boolean isDelimiterStart = isDelimiter (c , charSeq , pos , delim , delimLength );
@@ -2143,10 +2141,8 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
21432141 } else if (c == CR ) {
21442142 c = 'r' ;
21452143 }
2146-
21472144 appendable .append (escape );
21482145 appendable .append (c );
2149-
21502146 if (isDelimiterStart ) {
21512147 for (int i = 1 ; i < delimLength ; i ++) {
21522148 pos ++;
@@ -2155,7 +2151,6 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
21552151 appendable .append (c );
21562152 }
21572153 }
2158-
21592154 start = pos + 1 ; // start on the current char after this one
21602155 }
21612156 pos ++;
@@ -2170,14 +2165,12 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
21702165 private void printWithEscapes (final Reader reader , final Appendable appendable ) throws IOException {
21712166 int start = 0 ;
21722167 int pos = 0 ;
2173-
21742168 @ SuppressWarnings ("resource" ) // Temp reader on input reader.
21752169 final ExtendedBufferedReader bufferedReader = new ExtendedBufferedReader (reader );
21762170 final char [] delim = getDelimiterString ().toCharArray ();
21772171 final int delimLength = delim .length ;
21782172 final char escape = getEscapeCharacter ().charValue ();
21792173 final StringBuilder builder = new StringBuilder (IOUtils .DEFAULT_BUFFER_SIZE );
2180-
21812174 int c ;
21822175 while (-1 != (c = bufferedReader .read ())) {
21832176 builder .append ((char ) c );
@@ -2195,23 +2188,19 @@ private void printWithEscapes(final Reader reader, final Appendable appendable)
21952188 } else if (c == CR ) {
21962189 c = 'r' ;
21972190 }
2198-
21992191 append (escape , appendable );
22002192 append ((char ) c , appendable );
2201-
22022193 if (isDelimiterStart ) {
22032194 for (int i = 1 ; i < delimLength ; i ++) {
22042195 c = bufferedReader .read ();
22052196 append (escape , appendable );
22062197 append ((char ) c , appendable );
22072198 }
22082199 }
2209-
22102200 start = pos + 1 ; // start on the current char after this one
22112201 }
22122202 pos ++;
22132203 }
2214-
22152204 // write last segment
22162205 if (pos > start ) {
22172206 append (builder .substring (start , pos ), appendable );
@@ -2227,15 +2216,13 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
22272216 int start = 0 ;
22282217 int pos = 0 ;
22292218 final int len = charSeq .length ();
2230-
22312219 final char [] delim = getDelimiterString ().toCharArray ();
22322220 final int delimLength = delim .length ;
22332221 final char quoteChar = getQuoteCharacter ().charValue ();
22342222 // If escape char not specified, default to the quote char
22352223 // This avoids having to keep checking whether there is an escape character
22362224 // at the cost of checking against quote twice
22372225 final char escapeChar = isEscapeCharacterSet () ? getEscapeCharacter ().charValue () : quoteChar ;
2238-
22392226 QuoteMode quoteModePolicy = getQuoteMode ();
22402227 if (quoteModePolicy == null ) {
22412228 quoteModePolicy = QuoteMode .MINIMAL ;
@@ -2263,7 +2250,6 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
22632250 }
22642251 } else {
22652252 char c = charSeq .charAt (pos );
2266-
22672253 if (c <= COMMENT ) {
22682254 // Some other chars at the start of a value caused the parser to fail, so for now
22692255 // encapsulate if we start in anything less than '#'. We are being conservative
@@ -2290,7 +2276,6 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
22902276 }
22912277 }
22922278 }
2293-
22942279 if (!quote ) {
22952280 // No encapsulation needed - write out the original value
22962281 out .append (charSeq , start , len );
@@ -2300,16 +2285,13 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
23002285 default :
23012286 throw new IllegalStateException ("Unexpected Quote value: " + quoteModePolicy );
23022287 }
2303-
23042288 if (!quote ) {
23052289 // No encapsulation needed - write out the original value
23062290 out .append (charSeq , start , len );
23072291 return ;
23082292 }
2309-
23102293 // We hit something that needed encapsulation
23112294 out .append (quoteChar );
2312-
23132295 // Pick up where we left off: pos should be positioned on the first character that caused
23142296 // the need for encapsulation.
23152297 while (pos < len ) {
@@ -2322,7 +2304,6 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
23222304 }
23232305 pos ++;
23242306 }
2325-
23262307 // Write the last segment
23272308 out .append (charSeq , start , pos );
23282309 out .append (quoteChar );
@@ -2336,19 +2317,14 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
23362317 * @throws IOException If an I/O error occurs
23372318 */
23382319 private void printWithQuotes (final Reader reader , final Appendable appendable ) throws IOException {
2339-
23402320 if (getQuoteMode () == QuoteMode .NONE ) {
23412321 printWithEscapes (reader , appendable );
23422322 return ;
23432323 }
2344-
23452324 int pos = 0 ;
2346-
23472325 final char quote = getQuoteCharacter ().charValue ();
23482326 final StringBuilder builder = new StringBuilder (IOUtils .DEFAULT_BUFFER_SIZE );
2349-
23502327 append (quote , appendable );
2351-
23522328 int c ;
23532329 while (-1 != (c = reader .read ())) {
23542330 builder .append ((char ) c );
@@ -2360,17 +2336,14 @@ private void printWithQuotes(final Reader reader, final Appendable appendable) t
23602336 builder .setLength (0 );
23612337 pos = -1 ;
23622338 }
2363-
23642339 append ((char ) c , appendable );
23652340 }
23662341 pos ++;
23672342 }
2368-
23692343 // write last segment
23702344 if (pos > 0 ) {
23712345 append (builder .substring (0 , pos ), appendable );
23722346 }
2373-
23742347 append (quote , appendable );
23752348 }
23762349
@@ -2440,31 +2413,24 @@ private void validate() throws IllegalArgumentException {
24402413 if (containsLineBreak (delimiter )) {
24412414 throw new IllegalArgumentException ("The delimiter cannot be a line break" );
24422415 }
2443-
24442416 if (quoteCharacter != null && contains (delimiter , quoteCharacter .charValue ())) {
24452417 throw new IllegalArgumentException ("The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')" );
24462418 }
2447-
24482419 if (escapeCharacter != null && contains (delimiter , escapeCharacter .charValue ())) {
24492420 throw new IllegalArgumentException ("The escape character and the delimiter cannot be the same ('" + escapeCharacter + "')" );
24502421 }
2451-
24522422 if (commentMarker != null && contains (delimiter , commentMarker .charValue ())) {
24532423 throw new IllegalArgumentException ("The comment start character and the delimiter cannot be the same ('" + commentMarker + "')" );
24542424 }
2455-
24562425 if (quoteCharacter != null && quoteCharacter .equals (commentMarker )) {
24572426 throw new IllegalArgumentException ("The comment start character and the quoteChar cannot be the same ('" + commentMarker + "')" );
24582427 }
2459-
24602428 if (escapeCharacter != null && escapeCharacter .equals (commentMarker )) {
24612429 throw new IllegalArgumentException ("The comment start and the escape character cannot be the same ('" + commentMarker + "')" );
24622430 }
2463-
24642431 if (escapeCharacter == null && quoteMode == QuoteMode .NONE ) {
24652432 throw new IllegalArgumentException ("Quote mode set to NONE but no escape character is set" );
24662433 }
2467-
24682434 // Validate headers
24692435 if (headers != null && duplicateHeaderMode != DuplicateHeaderMode .ALLOW_ALL ) {
24702436 final Set <String > dupCheckSet = new HashSet <>(headers .length );
0 commit comments