@@ -150,9 +150,9 @@ public void printComment(final String comment) throws IOException {
150150 println ();
151151 }
152152
153- private void print (final CharSequence value , final int offset , final int len ) throws IOException {
153+ private void print (Object object , final CharSequence value , final int offset , final int len ) throws IOException {
154154 if (format .isQuoting ()) {
155- printAndQuote (value , offset , len );
155+ printAndQuote (object , value , offset , len );
156156 } else if (format .isEscaping ()) {
157157 printAndEscape (value , offset , len );
158158 } else {
@@ -207,7 +207,7 @@ void printAndEscape(final CharSequence value, final int offset, final int len) t
207207 }
208208 }
209209
210- void printAndQuote (final CharSequence value , final int offset , final int len ) throws IOException {
210+ void printAndQuote (Object object , final CharSequence value , final int offset , final int len ) throws IOException {
211211 final boolean first = newLine ; // is this the first value on this line?
212212 boolean quote = false ;
213213 int start = offset ;
@@ -219,9 +219,20 @@ void printAndQuote(final CharSequence value, final int offset, final int len) th
219219 final char delimChar = format .getDelimiter ();
220220 final char quoteChar = format .getQuoteChar ();
221221
222- if (format .getQuotePolicy () == Quote .ALL ) {
222+ Quote quotePolicy = format .getQuotePolicy ();
223+ if (quotePolicy == null ) {
224+ quotePolicy = Quote .MINIMAL ;
225+ }
226+ switch (quotePolicy ) {
227+ case ALL :
223228 quote = true ;
224- } else {
229+ break ;
230+ case NON_NUMERIC :
231+ quote = !(object instanceof Number );
232+ break ;
233+ case NONE :
234+ throw new IllegalArgumentException ("Not implemented yet" );
235+ case MINIMAL :
225236 if (len <= 0 ) {
226237 // always quote an empty token that is the first
227238 // on the line, as it may be the only thing on the
@@ -270,8 +281,15 @@ void printAndQuote(final CharSequence value, final int offset, final int len) th
270281 out .append (value , start , end );
271282 return ;
272283 }
284+ break ;
273285 }
274286
287+ if (!quote ) {
288+ // no encapsulation needed - write out the original value
289+ out .append (value , start , end );
290+ return ;
291+ }
292+
275293 // we hit something that needed encapsulation
276294 out .append (quoteChar );
277295
@@ -313,7 +331,7 @@ public void print(Object object, final boolean checkForEscape) throws IOExceptio
313331 printDelimiter ();
314332 out .append (value );
315333 } else {
316- print (value , 0 , value .length ());
334+ print (object , value , 0 , value .length ());
317335 }
318336 }
319337
@@ -325,8 +343,10 @@ public void print(Object object, final boolean checkForEscape) throws IOExceptio
325343 * @throws IOException
326344 * If an I/O error occurs
327345 */
328- public void print (final Object value ) throws IOException {
329- print (value , true );
346+ public void print (final Object object ) throws IOException {
347+ // null values are considered empty
348+ final String value = object == null ? EMPTY : object .toString ();
349+ print (object , value , 0 , value .length ());
330350 }
331351
332352 /**
0 commit comments