Package de.marhali.json5.stream
Class Json5Writer
- java.lang.Object
-
- de.marhali.json5.stream.Json5Writer
-
public final class Json5Writer extends java.lang.ObjectWrites a tree ofJson5Element's into their string literal representation by using awritestream.
-
-
Constructor Summary
Constructors Constructor Description Json5Writer(Json5Options options, java.io.Writer writer)Creates a new instance that writes a JSON5-encoded stream towriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringformatNumberString(java.lang.String numberString, int numberRadix)java.lang.Stringquote(java.lang.String string)java.lang.StringquoteKey(java.lang.String key)voidwrite(Json5Element element)Encodes and writes the providedJson5Elementinto json5 according to the specification and the configured options.voidwrite(Json5Element element, int depth)Encodes and writes the providedJson5Elementinto json5 according to the specification and the configured options.voidwriteArray(Json5Array array, int depth)Writes the providedJson5Arrayto the stream.voidwriteComment(Json5Element element, int depth)Writes any associated comments for the providedJson5Element.voidwriteNull()Writes the equivalent of aJson5Null(null) value.voidwriteObject(Json5Object object, int depth)Writes the providedJson5Objectto the stream.voidwritePrimitive(Json5Primitive primitive)Writes the provided primitive to the stream and encodes it if necessary.
-
-
-
Constructor Detail
-
Json5Writer
public Json5Writer(Json5Options options, java.io.Writer writer)
Creates a new instance that writes a JSON5-encoded stream towriter.Note: The writer must be closed after operation (
Writer.close())!- Parameters:
options- Parsing and serialization optionswriter- Output stream. For the best performance, use aBufferedWriter.
-
-
Method Detail
-
write
public void write(Json5Element element) throws java.io.IOException
Encodes and writes the providedJson5Elementinto json5 according to the specification and the configured options. The element can be any json5 element. All child trees will be included. This function writes with depth0and expects a root element. For nested elements, see the other write methods.- Parameters:
element- Element to encode- Throws:
java.io.IOException- If an I/O error occurs- See Also:
Configuration options,write(Json5Element, int)
-
write
public void write(Json5Element element, int depth) throws java.io.IOException
Encodes and writes the providedJson5Elementinto json5 according to the specification and the configured options. The element can be any json5 element. All child trees will be included.- Parameters:
element- Element to encodedepth- Depth of the current Json5 tree. Root node is0. Counts+1on every child element.- Throws:
java.io.IOException- If an I/O error occurs- See Also:
Configuration options,write(Json5Element)
-
writeComment
public void writeComment(Json5Element element, int depth) throws java.io.IOException
Writes any associated comments for the providedJson5Element. Checks ifJson5Options.isWriteComments()istrueand if the element has any comment assigned.- Parameters:
element- Element targetdepth- Depth to use for writing- Throws:
java.io.IOException- If an I/O error occurs
-
writeNull
public void writeNull() throws java.io.IOExceptionWrites the equivalent of aJson5Null(null) value.- Throws:
java.io.IOException- If an I/O error occurs.
-
writePrimitive
public void writePrimitive(Json5Primitive primitive) throws java.io.IOException
Writes the provided primitive to the stream and encodes it if necessary.- Parameters:
primitive- Primitive value.- Throws:
java.io.IOException- If an I/O error occurs.
-
writeObject
public void writeObject(Json5Object object, int depth) throws java.io.IOException
Writes the providedJson5Objectto the stream.- Parameters:
object- Object to encodedepth- Depth to use for writing- Throws:
java.io.IOException- If an I/O error occurs.- See Also:
write(Json5Element)
-
writeArray
public void writeArray(Json5Array array, int depth) throws java.io.IOException
Writes the providedJson5Arrayto the stream.- Parameters:
array- Array to encodedepth- Depth to use for writing- Throws:
java.io.IOException- If an I/O error occurs.- See Also:
write(Json5Element)
-
formatNumberString
public java.lang.String formatNumberString(java.lang.String numberString, int numberRadix)
-
quoteKey
public java.lang.String quoteKey(java.lang.String key)
-
quote
public java.lang.String quote(java.lang.String string)
-
-