@@ -163,35 +163,28 @@ public void printComment(final String comment) throws IOException {
163163
164164 private void print (final Object object , final CharSequence value ,
165165 final int offset , final int len ) throws IOException {
166+ if (!newRecord ) {
167+ out .append (format .getDelimiter ());
168+ }
166169 if (format .isQuoting ()) {
167170 // the original object is needed so can check for Number
168171 printAndQuote (object , value , offset , len );
169172 } else if (format .isEscaping ()) {
170173 printAndEscape (value , offset , len );
171174 } else {
172- printDelimiter ();
173175 out .append (value , offset , offset + len );
174176 }
175- }
176-
177- void printDelimiter () throws IOException {
178- if (newRecord ) {
179- newRecord = false ;
180- } else {
181- out .append (format .getDelimiter ());
182- }
177+ newRecord = false ;
183178 }
184179
185180 /*
186181 * Note: must only be called if escaping is enabled, otherwise will generate NPE
187182 */
188- void printAndEscape (final CharSequence value , final int offset , final int len ) throws IOException {
183+ private void printAndEscape (final CharSequence value , final int offset , final int len ) throws IOException {
189184 int start = offset ;
190185 int pos = offset ;
191186 final int end = offset + len ;
192187
193- printDelimiter ();
194-
195188 final char delim = format .getDelimiter ();
196189 final char escape = format .getEscape ().charValue ();
197190
@@ -227,16 +220,13 @@ void printAndEscape(final CharSequence value, final int offset, final int len) t
227220 * Note: must only be called if quoting is enabled, otherwise will generate NPE
228221 */
229222 // the original object is needed so can check for Number
230- void printAndQuote (final Object object , final CharSequence value ,
223+ private void printAndQuote (final Object object , final CharSequence value ,
231224 final int offset , final int len ) throws IOException {
232- final boolean first = newRecord ; // is this the first value on this line?
233225 boolean quote = false ;
234226 int start = offset ;
235227 int pos = offset ;
236228 final int end = offset + len ;
237229
238- printDelimiter ();
239-
240230 final char delimChar = format .getDelimiter ();
241231 final char quoteChar = format .getQuoteChar ().charValue ();
242232
@@ -259,14 +249,14 @@ void printAndQuote(final Object object, final CharSequence value,
259249 // on the line, as it may be the only thing on the
260250 // line. If it were not quoted in that case,
261251 // an empty line has no tokens.
262- if (first ) {
252+ if (newRecord ) {
263253 quote = true ;
264254 }
265255 } else {
266256 char c = value .charAt (pos );
267257
268258 // Hmmm, where did this rule come from?
269- if (first && (c < '0' || (c > '9' && c < 'A' ) || (c > 'Z' && c < 'a' ) || (c > 'z' ))) {
259+ if (newRecord && (c < '0' || (c > '9' && c < 'A' ) || (c > 'Z' && c < 'a' ) || (c > 'z' ))) {
270260 quote = true ;
271261 // } else if (c == ' ' || c == '\f' || c == '\t') {
272262 } else if (c <= COMMENT ) {
0 commit comments