-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use Appendable in place of Writer #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4892329
Adapt JSONWriter to use Appendable instead of Writer.
run2000 c91c37a
Remove executable bit.
run2000 826ceef
Minor tweaks.
run2000 2917cc5
Minor tweaks.
run2000 4a38c80
Merge from upstream.
run2000 0f579e4
Update version string
run2000 5daf2b9
Update version string
run2000 e94e25b
Update version string
run2000 bec3919
Update version string
run2000 0412cf1
Javadoc and copyright notice for JSONString
run2000 288c988
Cygwin fails me again, remove the execute bit.
run2000 c8c95c9
Revert whitespace, direct JSONObject.writeValue() call.
run2000 70f0dd9
Use appendValue, based on append, for writing directly.
run2000 73c5155
Revert whitespace.
run2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,6 @@ of this software and associated documentation files (the "Software"), to deal | |
| */ | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.StringWriter; | ||
| import java.io.Writer; | ||
| import java.lang.reflect.Array; | ||
| import java.math.BigDecimal; | ||
| import java.math.BigInteger; | ||
|
|
@@ -78,7 +76,7 @@ of this software and associated documentation files (the "Software"), to deal | |
| * </ul> | ||
| * | ||
| * @author JSON.org | ||
| * @version 2016-07-19 | ||
| * @version 2016-08-04 | ||
| */ | ||
| public class JSONArray implements Iterable<Object> { | ||
|
|
||
|
|
@@ -447,7 +445,7 @@ public String join(String separator) throws JSONException { | |
| if (i > 0) { | ||
| sb.append(separator); | ||
| } | ||
| sb.append(JSONObject.valueToString(this.myArrayList.get(i))); | ||
| JSONObject.writeValue(sb, this.myArrayList.get(i)); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
|
|
@@ -1017,7 +1015,7 @@ public JSONArray put(int index, Object value) throws JSONException { | |
| } | ||
|
|
||
| /** | ||
| * Creates a JSONPointer using an initialization string and tries to | ||
| * Creates a JSONPointer using an initialization string and tries to | ||
| * match it to an item within this JSONArray. For example, given a | ||
| * JSONArray initialized with this document: | ||
| * <pre> | ||
|
|
@@ -1159,10 +1157,8 @@ public String toString() { | |
| * @throws JSONException | ||
| */ | ||
| public String toString(int indentFactor) throws JSONException { | ||
| StringWriter sw = new StringWriter(); | ||
| synchronized (sw.getBuffer()) { | ||
| return this.write(sw, indentFactor, 0).toString(); | ||
| } | ||
| StringBuilder sw = new StringBuilder(); | ||
| return this.write(sw, indentFactor, 0).toString(); | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reverts a change related to #54 Basically, now that we use StringBuilder, which is not synchronizing on a buffer, instead of StringWriter, which does, the rationale for synchronizing no longer applies. |
||
| /** | ||
|
|
@@ -1174,7 +1170,7 @@ public String toString(int indentFactor) throws JSONException { | |
| * @return The writer. | ||
| * @throws JSONException | ||
| */ | ||
| public Writer write(Writer writer) throws JSONException { | ||
| public <T extends Appendable> T write(T writer) throws JSONException { | ||
| return this.write(writer, 0, 0); | ||
| } | ||
|
|
||
|
|
@@ -1193,12 +1189,12 @@ public Writer write(Writer writer) throws JSONException { | |
| * @return The writer. | ||
| * @throws JSONException | ||
| */ | ||
| public Writer write(Writer writer, int indentFactor, int indent) | ||
| public <T extends Appendable> T write(T writer, int indentFactor, int indent) | ||
| throws JSONException { | ||
| try { | ||
| boolean commanate = false; | ||
| int length = this.length(); | ||
| writer.write('['); | ||
| writer.append('['); | ||
|
|
||
| if (length == 1) { | ||
| JSONObject.writeValue(writer, this.myArrayList.get(0), | ||
|
|
@@ -1208,22 +1204,22 @@ public Writer write(Writer writer, int indentFactor, int indent) | |
|
|
||
| for (int i = 0; i < length; i += 1) { | ||
| if (commanate) { | ||
| writer.write(','); | ||
| writer.append(','); | ||
| } | ||
| if (indentFactor > 0) { | ||
| writer.write('\n'); | ||
| writer.append('\n'); | ||
| } | ||
| JSONObject.indent(writer, newindent); | ||
| JSONObject.writeValue(writer, this.myArrayList.get(i), | ||
| indentFactor, newindent); | ||
| commanate = true; | ||
| } | ||
| if (indentFactor > 0) { | ||
| writer.write('\n'); | ||
| writer.append('\n'); | ||
| } | ||
| JSONObject.indent(writer, indent); | ||
| } | ||
| writer.write(']'); | ||
| writer.append(']'); | ||
| return writer; | ||
| } catch (IOException e) { | ||
| throw new JSONException(e); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write directly to the one StringBuilder, avoiding creation of temporary buffer.