| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | package org.json; | |
| 2 | 2 | ||
| 3 | 3 | import java.io.IOException; | |
| 4 | - import java.io.Writer; | ||
| 5 | 4 | ||
| 6 | 5 | /* | |
| 7 | 6 | Copyright (c) 2006 JSON.org | |
@@ -50,11 +49,11 @@ of this software and associated documentation files (the "Software"), to deal | |||
| 50 | 49 | * <p> | |
| 51 | 50 | * The first method called must be <code>array</code> or <code>object</code>. | |
| 52 | 51 | * 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. | ||
| 54 | 53 | * <p> | |
| 55 | 54 | * This can sometimes be easier than using a JSONObject to build a string. | |
| 56 | 55 | * @author JSON.org | |
| 57 | - * @version 2015-12-09 | ||
| 56 | + * @version 2016-08-08 | ||
| 58 | 57 | */ | |
| 59 | 58 | public class JSONWriter { | |
| 60 | 59 | private static final int maxdepth = 200; | |
@@ -88,12 +87,12 @@ public class JSONWriter { | |||
| 88 | 87 | /** | |
| 89 | 88 | * The writer that will receive the output. | |
| 90 | 89 | */ | |
| 91 | - protected Writer writer; | ||
| 90 | + protected Appendable writer; | ||
| 92 | 91 | ||
| 93 | 92 | /** | |
| 94 | 93 | * Make a fresh JSONWriter. It can be used to build one JSON text. | |
| 95 | 94 | */ | |
| 96 | - public JSONWriter(Writer w) { | ||
| 95 | + public JSONWriter(Appendable w) { | ||
| 97 | 96 | this.comma = false; | |
| 98 | 97 | this.mode = 'i'; | |
| 99 | 98 | this.stack = new JSONObject[maxdepth]; | |
@@ -114,9 +113,9 @@ private JSONWriter append(String string) throws JSONException { | |||
| 114 | 113 | if (this.mode == 'o' || this.mode == 'a') { | |
| 115 | 114 | try { | |
| 116 | 115 | if (this.comma && this.mode == 'a') { | |
| 117 | - this.writer.write(','); | ||
| 116 | + this.writer.append(','); | ||
| 118 | 117 | } | |
| 119 | - this.writer.write(string); | ||
| 118 | + this.writer.append(string); | ||
| 120 | 119 | } catch (IOException e) { | |
| 121 | 120 | throw new JSONException(e); | |
| 122 | 121 | } | |
@@ -163,7 +162,7 @@ private JSONWriter end(char mode, char c) throws JSONException { | |||
| 163 | 162 | } | |
| 164 | 163 | this.pop(mode); | |
| 165 | 164 | try { | |
| 166 | - this.writer.write(c); | ||
| 165 | + this.writer.append(c); | ||
| 167 | 166 | } catch (IOException e) { | |
| 168 | 167 | throw new JSONException(e); | |
| 169 | 168 | } | |
@@ -207,10 +206,10 @@ public JSONWriter key(String string) throws JSONException { | |||
| 207 | 206 | try { | |
| 208 | 207 | this.stack[this.top - 1].putOnce(string, Boolean.TRUE); | |
| 209 | 208 | if (this.comma) { | |
| 210 | - this.writer.write(','); | ||
| 209 | + this.writer.append(','); | ||
| 211 | 210 | } | |
| 212 | - this.writer.write(JSONObject.quote(string)); | ||
| 213 | - this.writer.write(':'); | ||
| 211 | + this.writer.append(JSONObject.quote(string)); | ||
| 212 | + this.writer.append(':'); | ||
| 214 | 213 | this.comma = false; | |
| 215 | 214 | this.mode = 'o'; | |
| 216 | 215 | return this; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments