Package com.dslplatform.json
Class RawJsonWriter
- java.lang.Object
-
- com.dslplatform.json.RawJsonWriter
-
public class RawJsonWriter extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static byteARRAY_ENDHelper for writing JSON array end: ]static byteARRAY_STARTHelper for writing JSON array start: [static byteCOMMAHelper for writing comma separator: ,static byteESCAPEHelper for writing JSON escape: \\static byteOBJECT_ENDHelper for writing JSON object end: }static byteOBJECT_STARTHelper for writing JSON object start: {static byteQUOTEHelper for writing JSON quote: "static byteSEMIHelper for writing semicolon: :
-
Constructor Summary
Constructors Constructor Description RawJsonWriter(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidreset()Resets the writerintsize()Current position in the buffer.byte[]toByteArray()Content of buffer can be copied to another array of appropriate size.voidtoByteBuffer(java.nio.ByteBuffer b)voidwriteAsciiString(java.lang.String value)Write a quoted string consisting of only ascii characters.voidwriteByte(byte value)Write a single byte into the JSON.voidwriteString(java.lang.String value)Write a quoted string into the JSON.
-
-
-
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
-
SEMI
public static final byte SEMI
Helper for writing semicolon: :- See Also:
- Constant Field Values
-
QUOTE
public static final byte QUOTE
Helper for writing JSON quote: "- See Also:
- Constant Field Values
-
ESCAPE
public static final byte ESCAPE
Helper for writing JSON escape: \\- See Also:
- Constant Field Values
-
-
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
-
-