Class 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 named null array value to the stream.
      UBJsonWriter set​(java.lang.String name, boolean value)
      Appends a named boolean value to the stream.
      UBJsonWriter set​(java.lang.String name, boolean[] value)
      Appends a named boolean array value to the stream.
      UBJsonWriter set​(java.lang.String name, byte value)
      Appends a named byte value to the stream.
      UBJsonWriter set​(java.lang.String name, byte[] value)
      Appends a named byte array value to the stream.
      UBJsonWriter set​(java.lang.String name, char value)
      Appends a named char value to the stream.
      UBJsonWriter set​(java.lang.String name, char[] value)
      Appends a named char array value to the stream.
      UBJsonWriter set​(java.lang.String name, double value)
      Appends a named double value to the stream.
      UBJsonWriter set​(java.lang.String name, double[] value)
      Appends a named double array value to the stream.
      UBJsonWriter set​(java.lang.String name, float value)
      Appends a named float value to the stream.
      UBJsonWriter set​(java.lang.String name, float[] value)
      Appends a named float array value to the stream.
      UBJsonWriter set​(java.lang.String name, int value)
      Appends a named int value to the stream.
      UBJsonWriter set​(java.lang.String name, int[] value)
      Appends a named int array value to the stream.
      UBJsonWriter set​(java.lang.String name, long value)
      Appends a named long value to the stream.
      UBJsonWriter set​(java.lang.String name, long[] value)
      Appends a named long array value to the stream.
      UBJsonWriter set​(java.lang.String name, short value)
      Appends a named short value to the stream.
      UBJsonWriter set​(java.lang.String name, short[] value)
      Appends a named short array value to the stream.
      UBJsonWriter set​(java.lang.String name, java.lang.String value)
      Appends a named String value to the stream.
      UBJsonWriter set​(java.lang.String name, java.lang.String[] value)
      Appends a named String array value to the stream.
      UBJsonWriter value()
      Appends a null value to the stream.
      UBJsonWriter value​(boolean value)
      Appends a boolean value to the stream.
      UBJsonWriter value​(boolean[] values)
      Appends a boolean array value to the stream.
      UBJsonWriter value​(byte value)
      Appends a byte value to the stream.
      UBJsonWriter value​(byte[] values)
      Appends an optimized byte array value to the stream.
      UBJsonWriter value​(char value)
      Appends a char value to the stream.
      UBJsonWriter value​(char[] values)
      Appends an optimized char array value to the stream.
      UBJsonWriter value​(double value)
      Appends a double value to the stream.
      UBJsonWriter value​(double[] values)
      Appends an optimized double array value to the stream.
      UBJsonWriter value​(float value)
      Appends a float value to the stream.
      UBJsonWriter value​(float[] values)
      Appends an optimized float array value to the stream.
      UBJsonWriter value​(int value)
      Appends an int value to the stream.
      UBJsonWriter value​(int[] values)
      Appends an optimized int array value to the stream.
      UBJsonWriter value​(long value)
      Appends a long value to the stream.
      UBJsonWriter value​(long[] values)
      Appends an optimized long array value to the stream.
      UBJsonWriter value​(short value)
      Appends a short value to the stream.
      UBJsonWriter value​(short[] values)
      Appends an optimized short 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 a String value to the stream.
      UBJsonWriter value​(java.lang.String[] values)
      Appends an optimized String array value to the stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UBJsonWriter

        public UBJsonWriter​(java.io.OutputStream out)
    • Method Detail

      • object

        public UBJsonWriter object()
                            throws java.io.IOException
        Begins a new object container. To finish the object call pop().
        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 call pop().
        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 call pop().
        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 call pop().
        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 a byte value to the stream. This corresponds to the int8 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 a short value to the stream. This corresponds to the int16 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 an int value to the stream. This corresponds to the int32 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 a long value to the stream. This corresponds to the int64 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 a float value to the stream. This corresponds to the float32 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 a double value to the stream. This corresponds to the float64 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 a boolean value to the stream. This corresponds to the boolean 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 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:
        java.io.IOException
      • value

        public UBJsonWriter value​(java.lang.String value)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(byte[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(short[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(int[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(long[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(float[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(double[] values)
                           throws java.io.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:
        java.io.IOException
      • value

        public UBJsonWriter value​(boolean[] values)
                           throws java.io.IOException
        Appends a boolean 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 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:
        java.io.IOException
      • value

        public UBJsonWriter value​(java.lang.String[] values)
                           throws java.io.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:
        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 a null 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 named byte 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 named short 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 named int 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 named long 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 named float 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 named double 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 named boolean 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 named char 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 named String 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 named byte 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 named short 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 named int 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 named long 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 named float 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 named double 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 named boolean 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 named char 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 named String 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 named null 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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException