xv.json
Class JSONWriter
java.lang.Object
xv.json.JSONWriter
public class JSONWriter
- extends Object
The JSONWriter writes JSON out to a given stream. This is based on the StAX
XML writer.
- Author:
- xv
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JSONWriter
public JSONWriter(Writer out)
startObject
public void startObject()
throws IOException
- Throws:
IOException
startObject
public void startObject(String label)
throws IOException
- Throws:
IOException
endObject
public void endObject()
throws IOException
- Throws:
IOException
startArray
public void startArray()
throws IOException
- Throws:
IOException
startArray
public void startArray(String label)
throws IOException
- Throws:
IOException
endArray
public void endArray()
throws IOException
- Throws:
IOException
writeString
public void writeString(String string)
throws IOException
- Throws:
IOException
writeString
public void writeString(String label,
String string)
throws IOException
- Throws:
IOException
writeBoolean
public void writeBoolean(boolean value)
throws IOException
- Throws:
IOException
writeBoolean
public void writeBoolean(String label,
boolean value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(byte value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
byte value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(short value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
short value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(int value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
int value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(long value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
long value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(float value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
float value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(double value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
double value)
throws IOException
- Throws:
IOException
writeNumber
public void writeNumber(String label,
Number value)
throws IOException
- Throws:
IOException
writeNull
public void writeNull()
throws IOException
- Throws:
IOException
writeNull
public void writeNull(String label)
throws IOException
- Throws:
IOException
needsEscaping
public boolean needsEscaping(char c)
- Gets whether or not this character needs escaping to be written to the
given writer. Currently this handles meta-characters and assumes that
all control characters and all non-ASCII characters need to be escaped.
Future versions might be a little less extreme.
- Parameters:
c
-
- Returns:
escapeCharacter
public static String escapeCharacter(char c)
getBestQuoteCharacter
public static char getBestQuoteCharacter(String string)
- Gets the best quoting character to use for the given string. This favors
double-quotes over single-quotes.
- Parameters:
string
-
- Returns:
- either
'\''
or '"'
depending on the string's contents
- Throws:
NullPointerException
- if the string is null
Copyright © 2008-2011. All Rights Reserved.