11package org .json ;
22
33import java .io .IOException ;
4- import java .io .Writer ;
54
65/*
76Copyright (c) 2006 JSON.org
@@ -50,11 +49,11 @@ of this software and associated documentation files (the "Software"), to deal
5049 * <p>
5150 * The first method called must be <code>array</code> or <code>object</code>.
5251 * There are no methods for adding commas or colons. JSONWriter adds them for
53- * you. Objects and arrays can be nested up to 20 levels deep.
52+ * you. Objects and arrays can be nested up to 200 levels deep.
5453 * <p>
5554 * This can sometimes be easier than using a JSONObject to build a string.
5655 * @author JSON.org
57- * @version 2015-12-09
56+ * @version 2016-08-08
5857 */
5958public class JSONWriter {
6059 private static final int maxdepth = 200 ;
@@ -88,12 +87,12 @@ public class JSONWriter {
8887 /**
8988 * The writer that will receive the output.
9089 */
91- protected Writer writer ;
90+ protected Appendable writer ;
9291
9392 /**
9493 * Make a fresh JSONWriter. It can be used to build one JSON text.
9594 */
96- public JSONWriter (Writer w ) {
95+ public JSONWriter (Appendable w ) {
9796 this .comma = false ;
9897 this .mode = 'i' ;
9998 this .stack = new JSONObject [maxdepth ];
@@ -114,9 +113,9 @@ private JSONWriter append(String string) throws JSONException {
114113 if (this .mode == 'o' || this .mode == 'a' ) {
115114 try {
116115 if (this .comma && this .mode == 'a' ) {
117- this .writer .write (',' );
116+ this .writer .append (',' );
118117 }
119- this .writer .write (string );
118+ this .writer .append (string );
120119 } catch (IOException e ) {
121120 throw new JSONException (e );
122121 }
@@ -163,7 +162,7 @@ private JSONWriter end(char mode, char c) throws JSONException {
163162 }
164163 this .pop (mode );
165164 try {
166- this .writer .write (c );
165+ this .writer .append (c );
167166 } catch (IOException e ) {
168167 throw new JSONException (e );
169168 }
@@ -207,10 +206,10 @@ public JSONWriter key(String string) throws JSONException {
207206 try {
208207 this .stack [this .top - 1 ].putOnce (string , Boolean .TRUE );
209208 if (this .comma ) {
210- this .writer .write (',' );
209+ this .writer .append (',' );
211210 }
212- this .writer .write (JSONObject .quote (string ));
213- this .writer .write (':' );
211+ this .writer .append (JSONObject .quote (string ));
212+ this .writer .append (':' );
214213 this .comma = false ;
215214 this .mode = 'o' ;
216215 return this ;
0 commit comments