Package com.badlogic.gdx.utils
Class UBJsonWriter
- java.lang.Object
-
- com.badlogic.gdx.utils.UBJsonWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class UBJsonWriter extends java.lang.Object implements java.io.Closeable
Builder style API for emitting UBJSON.
-
-
Constructor Summary
Constructors Constructor Description UBJsonWriter(java.io.OutputStream out)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UBJsonWriter
array()
Begins a new array container.UBJsonWriter
array(java.lang.String name)
Begins a new named array container, having the given name.void
close()
Closes the underlying output stream and releases any system resources associated with the stream.void
flush()
Flushes the underlying stream.UBJsonWriter
name(java.lang.String name)
Appends a name for the next object, array, or value.UBJsonWriter
object()
Begins a new object container.UBJsonWriter
object(java.lang.String name)
Begins a new named object container, having the given name.UBJsonWriter
pop()
Ends the current object or array and pops it off of the element stack.protected UBJsonWriter
pop(boolean silent)
UBJsonWriter
set(java.lang.String name)
Appends a namednull
array value to the stream.UBJsonWriter
set(java.lang.String name, boolean value)
Appends a namedboolean
value to the stream.UBJsonWriter
set(java.lang.String name, boolean[] value)
Appends a namedboolean
array value to the stream.UBJsonWriter
set(java.lang.String name, byte value)
Appends a namedbyte
value to the stream.UBJsonWriter
set(java.lang.String name, byte[] value)
Appends a namedbyte
array value to the stream.UBJsonWriter
set(java.lang.String name, char value)
Appends a namedchar
value to the stream.UBJsonWriter
set(java.lang.String name, char[] value)
Appends a namedchar
array value to the stream.UBJsonWriter
set(java.lang.String name, double value)
Appends a nameddouble
value to the stream.UBJsonWriter
set(java.lang.String name, double[] value)
Appends a nameddouble
array value to the stream.UBJsonWriter
set(java.lang.String name, float value)
Appends a namedfloat
value to the stream.UBJsonWriter
set(java.lang.String name, float[] value)
Appends a namedfloat
array value to the stream.UBJsonWriter
set(java.lang.String name, int value)
Appends a namedint
value to the stream.UBJsonWriter
set(java.lang.String name, int[] value)
Appends a namedint
array value to the stream.UBJsonWriter
set(java.lang.String name, long value)
Appends a namedlong
value to the stream.UBJsonWriter
set(java.lang.String name, long[] value)
Appends a namedlong
array value to the stream.UBJsonWriter
set(java.lang.String name, short value)
Appends a namedshort
value to the stream.UBJsonWriter
set(java.lang.String name, short[] value)
Appends a namedshort
array value to the stream.UBJsonWriter
set(java.lang.String name, java.lang.String value)
Appends a namedString
value to the stream.UBJsonWriter
set(java.lang.String name, java.lang.String[] value)
Appends a namedString
array value to the stream.UBJsonWriter
value()
Appends anull
value to the stream.UBJsonWriter
value(boolean value)
Appends aboolean
value to the stream.UBJsonWriter
value(boolean[] values)
Appends aboolean array
value to the stream.UBJsonWriter
value(byte value)
Appends abyte
value to the stream.UBJsonWriter
value(byte[] values)
Appends an optimizedbyte array
value to the stream.UBJsonWriter
value(char value)
Appends achar
value to the stream.UBJsonWriter
value(char[] values)
Appends an optimizedchar array
value to the stream.UBJsonWriter
value(double value)
Appends adouble
value to the stream.UBJsonWriter
value(double[] values)
Appends an optimizeddouble array
value to the stream.UBJsonWriter
value(float value)
Appends afloat
value to the stream.UBJsonWriter
value(float[] values)
Appends an optimizedfloat array
value to the stream.UBJsonWriter
value(int value)
Appends anint
value to the stream.UBJsonWriter
value(int[] values)
Appends an optimizedint array
value to the stream.UBJsonWriter
value(long value)
Appends along
value to the stream.UBJsonWriter
value(long[] values)
Appends an optimizedlong array
value to the stream.UBJsonWriter
value(short value)
Appends ashort
value to the stream.UBJsonWriter
value(short[] values)
Appends an optimizedshort array
value to the stream.UBJsonWriter
value(JsonValue value)
Appends the given JsonValue, including all its fields recursively, to the stream.UBJsonWriter
value(java.lang.Object object)
Appends the object to the stream, if it is a known value type.UBJsonWriter
value(java.lang.String value)
Appends aString
value to the stream.UBJsonWriter
value(java.lang.String[] values)
Appends an optimizedString array
value to the stream.
-
-
-
Method Detail
-
object
public UBJsonWriter object() throws java.io.IOException
Begins a new object container. To finish the object callpop()
.- Returns:
- This writer, for chaining
- Throws:
java.io.IOException
-
object
public UBJsonWriter object(java.lang.String name) throws java.io.IOException
Begins a new named object container, having the given name. To finish the object callpop()
.- Returns:
- This writer, for chaining
- Throws:
java.io.IOException
-
array
public UBJsonWriter array() throws java.io.IOException
Begins a new array container. To finish the array callpop()
.- Returns:
- this writer, for chaining.
- Throws:
java.io.IOException
-
array
public UBJsonWriter array(java.lang.String name) throws java.io.IOException
Begins a new named array container, having the given name. To finish the array callpop()
.- Returns:
- this writer, for chaining.
- Throws:
java.io.IOException
-
name
public UBJsonWriter name(java.lang.String name) throws java.io.IOException
Appends a name for the next object, array, or value.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(byte value) throws java.io.IOException
Appends abyte
value to the stream. This corresponds to theint8
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(short value) throws java.io.IOException
Appends ashort
value to the stream. This corresponds to theint16
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(int value) throws java.io.IOException
Appends anint
value to the stream. This corresponds to theint32
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(long value) throws java.io.IOException
Appends along
value to the stream. This corresponds to theint64
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(float value) throws java.io.IOException
Appends afloat
value to the stream. This corresponds to thefloat32
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(double value) throws java.io.IOException
Appends adouble
value to the stream. This corresponds to thefloat64
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(boolean value) throws java.io.IOException
Appends aboolean
value to the stream. This corresponds to theboolean
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(char value) throws java.io.IOException
Appends achar
value to the stream. Because, in Java, achar
is 16 bytes, this corresponds to theint16
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(java.lang.String value) throws java.io.IOException
Appends aString
value to the stream. This corresponds to thestring
value type in the UBJSON specification.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(byte[] values) throws java.io.IOException
Appends an optimizedbyte array
value to the stream. As an optimized array, theint8
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(short[] values) throws java.io.IOException
Appends an optimizedshort array
value to the stream. As an optimized array, theint16
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(int[] values) throws java.io.IOException
Appends an optimizedint array
value to the stream. As an optimized array, theint32
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(long[] values) throws java.io.IOException
Appends an optimizedlong array
value to the stream. As an optimized array, theint64
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(float[] values) throws java.io.IOException
Appends an optimizedfloat array
value to the stream. As an optimized array, thefloat32
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(double[] values) throws java.io.IOException
Appends an optimizeddouble array
value to the stream. As an optimized array, thefloat64
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element. element count are encoded once at the array marker instead of for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(boolean[] values) throws java.io.IOException
Appends aboolean array
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(char[] values) throws java.io.IOException
Appends an optimizedchar array
value to the stream. As an optimized array, theint16
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(java.lang.String[] values) throws java.io.IOException
Appends an optimizedString array
value to the stream. As an optimized array, theString
value type marker and element count are encoded once at the array marker instead of repeating the type marker for each element.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(JsonValue value) throws java.io.IOException
Appends the given JsonValue, including all its fields recursively, to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value(java.lang.Object object) throws java.io.IOException
Appends the object to the stream, if it is a known value type. This is a convenience method that calls through to the appropriate value method.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
value
public UBJsonWriter value() throws java.io.IOException
Appends anull
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, byte value) throws java.io.IOException
Appends a namedbyte
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, short value) throws java.io.IOException
Appends a namedshort
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, int value) throws java.io.IOException
Appends a namedint
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, long value) throws java.io.IOException
Appends a namedlong
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, float value) throws java.io.IOException
Appends a namedfloat
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, double value) throws java.io.IOException
Appends a nameddouble
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, boolean value) throws java.io.IOException
Appends a namedboolean
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, char value) throws java.io.IOException
Appends a namedchar
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, java.lang.String value) throws java.io.IOException
Appends a namedString
value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, byte[] value) throws java.io.IOException
Appends a namedbyte
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, short[] value) throws java.io.IOException
Appends a namedshort
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, int[] value) throws java.io.IOException
Appends a namedint
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, long[] value) throws java.io.IOException
Appends a namedlong
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, float[] value) throws java.io.IOException
Appends a namedfloat
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, double[] value) throws java.io.IOException
Appends a nameddouble
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, boolean[] value) throws java.io.IOException
Appends a namedboolean
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, char[] value) throws java.io.IOException
Appends a namedchar
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name, java.lang.String[] value) throws java.io.IOException
Appends a namedString
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
set
public UBJsonWriter set(java.lang.String name) throws java.io.IOException
Appends a namednull
array value to the stream.- Returns:
- this writer, for chaining
- Throws:
java.io.IOException
-
pop
public UBJsonWriter pop() throws java.io.IOException
Ends the current object or array and pops it off of the element stack.- Returns:
- This writer, for chaining
- Throws:
java.io.IOException
-
pop
protected UBJsonWriter pop(boolean silent) throws java.io.IOException
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Flushes the underlying stream. This forces any buffered output bytes to be written out to the stream.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Closes the underlying output stream and releases any system resources associated with the stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-