Class UBJsonWriter

java.lang.Object
arc.util.serialization.UBJsonWriter
All Implemented Interfaces:
BaseJsonWriter, Closeable, AutoCloseable

public class UBJsonWriter extends Object implements Closeable, BaseJsonWriter
Builder style API for emitting UBJSON.
  • Constructor Details

  • Method Details

    • reset

      public void reset()
    • object

      public UBJsonWriter object() throws IOException
      Begins a new object container. To finish the object call pop().
      Specified by:
      object in interface BaseJsonWriter
      Returns:
      This writer, for chaining
      Throws:
      IOException
    • object

      public UBJsonWriter object(String name) throws IOException
      Begins a new named object container, having the given name. To finish the object call pop().
      Specified by:
      object in interface BaseJsonWriter
      Returns:
      This writer, for chaining
      Throws:
      IOException
    • array

      public UBJsonWriter array() throws IOException
      Begins a new array container. To finish the array call pop().
      Specified by:
      array in interface BaseJsonWriter
      Returns:
      this writer, for chaining.
      Throws:
      IOException
    • array

      public UBJsonWriter array(String name) throws IOException
      Begins a new named array container, having the given name. To finish the array call pop().
      Specified by:
      array in interface BaseJsonWriter
      Returns:
      this writer, for chaining.
      Throws:
      IOException
    • name

      public UBJsonWriter name(String name) throws IOException
      Appends a name for the next object, array, or value.
      Specified by:
      name in interface BaseJsonWriter
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(byte value) throws IOException
      Appends a byte value to the stream. This corresponds to the int8 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(short value) throws IOException
      Appends a short value to the stream. This corresponds to the int16 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(int value) throws IOException
      Appends an int value to the stream. This corresponds to the int32 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(long value) throws IOException
      Appends a long value to the stream. This corresponds to the int64 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(float value) throws IOException
      Appends a float value to the stream. This corresponds to the float32 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(double value) throws IOException
      Appends a double value to the stream. This corresponds to the float64 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(boolean value) throws IOException
      Appends a boolean value to the stream. This corresponds to the boolean value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(char value) throws IOException
      Appends a char value to the stream. Because, in Java, a char is 16 bytes, this corresponds to the int16 value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(String value) throws IOException
      Appends a String value to the stream. This corresponds to the string value type in the UBJSON specification.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(byte[] values) throws IOException
      Appends an optimized byte array value to the stream. As an optimized array, the int8 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:
      IOException
    • value

      public UBJsonWriter value(short[] values) throws IOException
      Appends an optimized short array value to the stream. As an optimized array, the int16 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:
      IOException
    • value

      public UBJsonWriter value(int[] values) throws IOException
      Appends an optimized int array value to the stream. As an optimized array, the int32 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:
      IOException
    • value

      public UBJsonWriter value(long[] values) throws IOException
      Appends an optimized long array value to the stream. As an optimized array, the int64 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:
      IOException
    • value

      public UBJsonWriter value(float[] values) throws IOException
      Appends an optimized float array value to the stream. As an optimized array, the float32 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:
      IOException
    • value

      public UBJsonWriter value(double[] values) throws IOException
      Appends an optimized double array value to the stream. As an optimized array, the float64 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:
      IOException
    • value

      public UBJsonWriter value(boolean[] values) throws IOException
      Appends a boolean array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(char[] values) throws IOException
      Appends an optimized char array value to the stream. As an optimized array, the int16 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:
      IOException
    • value

      public UBJsonWriter value(String[] values) throws IOException
      Appends an optimized String array value to the stream. As an optimized array, the String 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:
      IOException
    • value

      public UBJsonWriter value(JsonValue value) throws IOException
      Appends the given JsonValue, including all its fields recursively, to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value(Object object) throws 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.
      Specified by:
      value in interface BaseJsonWriter
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • value

      public UBJsonWriter value() throws IOException
      Appends a null value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • setOutputType

      public void setOutputType(JsonWriter.OutputType outputType)
      Specified by:
      setOutputType in interface BaseJsonWriter
    • setQuoteLongValues

      public void setQuoteLongValues(boolean quoteLongValues)
      Specified by:
      setQuoteLongValues in interface BaseJsonWriter
    • set

      public UBJsonWriter set(String name, Object value) throws IOException
      Appends a named value to the stream.
      Specified by:
      set in interface BaseJsonWriter
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, byte value) throws IOException
      Appends a named byte value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, short value) throws IOException
      Appends a named short value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, int value) throws IOException
      Appends a named int value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, long value) throws IOException
      Appends a named long value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, float value) throws IOException
      Appends a named float value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, double value) throws IOException
      Appends a named double value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, boolean value) throws IOException
      Appends a named boolean value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, char value) throws IOException
      Appends a named char value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, String value) throws IOException
      Appends a named String value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, byte[] value) throws IOException
      Appends a named byte array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, short[] value) throws IOException
      Appends a named short array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, int[] value) throws IOException
      Appends a named int array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, long[] value) throws IOException
      Appends a named long array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, float[] value) throws IOException
      Appends a named float array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, double[] value) throws IOException
      Appends a named double array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, boolean[] value) throws IOException
      Appends a named boolean array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, char[] value) throws IOException
      Appends a named char array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name, String[] value) throws IOException
      Appends a named String array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • set

      public UBJsonWriter set(String name) throws IOException
      Appends a named null array value to the stream.
      Returns:
      this writer, for chaining
      Throws:
      IOException
    • pop

      public UBJsonWriter pop() throws IOException
      Ends the current object or array and pops it off of the element stack.
      Specified by:
      pop in interface BaseJsonWriter
      Returns:
      This writer, for chaining
      Throws:
      IOException
    • pop

      protected UBJsonWriter pop(boolean silent) throws IOException
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flushes the underlying stream. This forces any buffered output bytes to be written out to the stream.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Closes the underlying output stream and releases any system resources associated with the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException