Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions JSONWriter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.json;

import java.io.IOException;
import java.io.Writer;

/*
Copyright (c) 2006 JSON.org
Expand Down Expand Up @@ -50,11 +49,11 @@ of this software and associated documentation files (the "Software"), to deal
* <p>
* The first method called must be <code>array</code> or <code>object</code>.
* There are no methods for adding commas or colons. JSONWriter adds them for
* you. Objects and arrays can be nested up to 20 levels deep.
* you. Objects and arrays can be nested up to 200 levels deep.
* <p>
* This can sometimes be easier than using a JSONObject to build a string.
* @author JSON.org
* @version 2015-12-09
* @version 2016-08-08
*/
public class JSONWriter {
private static final int maxdepth = 200;
Expand Down Expand Up @@ -88,12 +87,12 @@ public class JSONWriter {
/**
* The writer that will receive the output.
*/
protected Writer writer;
protected Appendable writer;

/**
* Make a fresh JSONWriter. It can be used to build one JSON text.
*/
public JSONWriter(Writer w) {
public JSONWriter(Appendable w) {
this.comma = false;
this.mode = 'i';
this.stack = new JSONObject[maxdepth];
Expand All @@ -114,9 +113,9 @@ private JSONWriter append(String string) throws JSONException {
if (this.mode == 'o' || this.mode == 'a') {
try {
if (this.comma && this.mode == 'a') {
this.writer.write(',');
this.writer.append(',');
}
this.writer.write(string);
this.writer.append(string);
} catch (IOException e) {
throw new JSONException(e);
}
Expand Down Expand Up @@ -163,7 +162,7 @@ private JSONWriter end(char mode, char c) throws JSONException {
}
this.pop(mode);
try {
this.writer.write(c);
this.writer.append(c);
} catch (IOException e) {
throw new JSONException(e);
}
Expand Down Expand Up @@ -207,10 +206,10 @@ public JSONWriter key(String string) throws JSONException {
try {
this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
if (this.comma) {
this.writer.write(',');
this.writer.append(',');
}
this.writer.write(JSONObject.quote(string));
this.writer.write(':');
this.writer.append(JSONObject.quote(string));
this.writer.append(':');
this.comma = false;
this.mode = 'o';
return this;
Expand Down