Class RawJsonWriter


  • public class RawJsonWriter
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ARRAY_END
      Helper for writing JSON array end: ]
      static byte ARRAY_START
      Helper for writing JSON array start: [
      static byte COMMA
      Helper for writing comma separator: ,
      static byte ESCAPE
      Helper for writing JSON escape: \\
      static byte OBJECT_END
      Helper for writing JSON object end: }
      static byte OBJECT_START
      Helper for writing JSON object start: {
      static byte QUOTE
      Helper for writing JSON quote: "
      static byte SEMI
      Helper for writing semicolon: :
    • Constructor Summary

      Constructors 
      Constructor Description
      RawJsonWriter​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void reset()
      Resets the writer
      int size()
      Current position in the buffer.
      byte[] toByteArray()
      Content of buffer can be copied to another array of appropriate size.
      void toByteBuffer​(java.nio.ByteBuffer b)  
      void writeAsciiString​(java.lang.String value)
      Write a quoted string consisting of only ascii characters.
      void writeByte​(byte value)
      Write a single byte into the JSON.
      void writeString​(java.lang.String value)
      Write a quoted string into the JSON.
      • Methods inherited from class java.lang.Object

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

      • OBJECT_START

        public static final byte OBJECT_START
        Helper for writing JSON object start: {
        See Also:
        Constant Field Values
      • OBJECT_END

        public static final byte OBJECT_END
        Helper for writing JSON object end: }
        See Also:
        Constant Field Values
      • ARRAY_START

        public static final byte ARRAY_START
        Helper for writing JSON array start: [
        See Also:
        Constant Field Values
      • ARRAY_END

        public static final byte ARRAY_END
        Helper for writing JSON array end: ]
        See Also:
        Constant Field Values
      • COMMA

        public static final byte COMMA
        Helper for writing comma separator: ,
        See Also:
        Constant Field Values
      • ESCAPE

        public static final byte ESCAPE
        Helper for writing JSON escape: \\
        See Also:
        Constant Field Values
    • Constructor Detail

      • RawJsonWriter

        public RawJsonWriter​(int capacity)
    • Method Detail

      • writeByte

        public final void writeByte​(byte value)
        Write a single byte into the JSON.
        Parameters:
        value - byte to write into the JSON
      • writeString

        public final void writeString​(java.lang.String value)
        Write a quoted string into the JSON. String will be appropriately escaped according to JSON escaping rules.
        Parameters:
        value - string to write
      • writeAsciiString

        public final void writeAsciiString​(java.lang.String value)
        Write a quoted string consisting of only ascii characters. String will not be escaped according to JSON escaping rules.
        Parameters:
        value - ascii string
      • toByteArray

        public final byte[] toByteArray()
        Content of buffer can be copied to another array of appropriate size. This method can't be used when targeting output stream. Ideally it should be avoided if possible, since it will create an array copy. It's better to use getByteBuffer and size instead.
        Returns:
        copy of the buffer up to the current position
      • toByteBuffer

        public void toByteBuffer​(java.nio.ByteBuffer b)
      • size

        public final int size()
        Current position in the buffer. When stream is not used, this is also equivalent to the size of the resulting JSON in bytes
        Returns:
        position in the populated buffer
      • reset

        public final void reset()
        Resets the writer