Package org.glassfish.json
Class JsonGeneratorImpl
java.lang.Object
org.glassfish.json.JsonGeneratorImpl
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,JsonGenerator
- Direct Known Subclasses:
JsonPrettyGeneratorImpl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final char[]
private final BufferPool
private JsonGeneratorImpl.Context
private static final char[]
private static final char[]
private static final char[]
All possible chars for representing a number as a Stringprivate static final int[]
private static final char[]
private int
private final Deque<JsonGeneratorImpl.Context>
private static final Charset
private final Writer
Fields inherited from interface javax.json.stream.JsonGenerator
PRETTY_PRINTING
-
Constructor Summary
ConstructorsConstructorDescriptionJsonGeneratorImpl
(OutputStream out, Charset encoding, BufferPool bufferPool) JsonGeneratorImpl
(OutputStream out, BufferPool bufferPool) JsonGeneratorImpl
(Writer writer, BufferPool bufferPool) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this generator and frees any resources associated with it.private static void
fillIntChars
(int i, char[] buf, int index) Places characters representing the integer i into the character array buf.void
flush()
Flushes the underlying output source.(package private) void
private static int
stringSize
(int x) write
(boolean value) Writes a JSON true or false value within the current array context.write
(double value) Writes the specified value as a JSON number value within the current array context.write
(int value) Writes the specified value as a JSON number value within the current array context.write
(long value) Writes the specified value as a JSON number value within the current array context.Writes the specified value as a JSON string value within the current array context.Writes a JSON name/boolean value pair in the current object context.Writes a JSON name/number value pair in the current object context.Writes a JSON name/number value pair in the current object context.Writes a JSON name/number value pair in the current object context.Writes a JSON name/string value pair in the current object context.write
(String name, BigDecimal value) Writes a JSON name/number value pair in the current object context.write
(String name, BigInteger value) Writes a JSON name/number value pair in the current object context.Writes a JSON name/value pair in the current object context.write
(BigDecimal value) Writes the specified value as a JSON number value within the current array context.write
(BigInteger value) Writes the specified value as a JSON number value within the current array context.Writes the specified value as a JSON value within the current array context.(package private) void
writeChar
(char c) protected void
writeEnd()
Writes the end of the current context.(package private) void
writeEscapedString
(String string) (package private) void
writeInt
(int num) private JsonGenerator
Writes a JSON null value within the current array context.Writes a JSON name/null value pair in an current object context.Writes the JSON start array character.writeStartArray
(String name) Writes the JSON name/start array character pair with in the current object context.Writes the JSON start object character.writeStartObject
(String name) Writes the JSON name/start object character pair in the current object context.(package private) void
writeString
(String str) (package private) void
writeString
(String str, int begin, int end) private void
writeValue
(String value) private void
writeValue
(String name, String value)
-
Field Details
-
UTF_8
-
INT_MIN_VALUE_CHARS
private static final char[] INT_MIN_VALUE_CHARS -
INT_CHARS_SIZE_TABLE
private static final int[] INT_CHARS_SIZE_TABLE -
DIGIT_TENS
private static final char[] DIGIT_TENS -
DIGIT_ONES
private static final char[] DIGIT_ONES -
DIGITS
private static final char[] DIGITSAll possible chars for representing a number as a String -
bufferPool
-
writer
-
currentContext
-
stack
-
buf
private final char[] buf -
len
private int len
-
-
Constructor Details
-
JsonGeneratorImpl
JsonGeneratorImpl(Writer writer, BufferPool bufferPool) -
JsonGeneratorImpl
JsonGeneratorImpl(OutputStream out, BufferPool bufferPool) -
JsonGeneratorImpl
JsonGeneratorImpl(OutputStream out, Charset encoding, BufferPool bufferPool)
-
-
Method Details
-
flush
public void flush()Description copied from interface:JsonGenerator
Flushes the underlying output source. If the generator has saved any characters in a buffer, writes them immediately to the underlying output source before flushing it.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceJsonGenerator
-
writeStartObject
Description copied from interface:JsonGenerator
Writes the JSON start object character. It starts a new child object context within which JSON name/value pairs can be written to the object. This method is valid only in an array context or in no context (when a context is not yet started). This method can only be called once in no context.- Specified by:
writeStartObject
in interfaceJsonGenerator
- Returns:
- this generator
-
writeStartObject
Description copied from interface:JsonGenerator
Writes the JSON name/start object character pair in the current object context. It starts a new child object context within which JSON name/value pairs can be written to the object.- Specified by:
writeStartObject
in interfaceJsonGenerator
- Parameters:
name
- a name within the JSON name/object pair to be written- Returns:
- this generator
-
writeName
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/string value pair in the current object context. The specified value is written as JSON string value.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/string pair to be written in current JSON objectfieldValue
- a value in the JSON name/string pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/number pair to be written in current JSON objectvalue
- a value in the JSON name/number pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/number pair to be written in current JSON objectvalue
- a value in the JSON name/number pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The stringBigDecimal.valueOf(double).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/number pair to be written in current JSON objectvalue
- a value in the JSON name/number pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/number pair to be written in current JSON objectvalue
- a value in the JSON name/number pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/number value pair in the current object context. The specified value is written as a JSON number value. The specified value'stoString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/number pair to be written in current JSON objectvalue
- a value in the JSON name/number pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/boolean value pair in the current object context. If value is true, it writes the JSONtrue
value, otherwise it writes the JSONfalse
value.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/boolean pair to be written in current JSON objectvalue
- a value in the JSON name/boolean pair to be written in current JSON object- Returns:
- this generator
-
writeNull
Description copied from interface:JsonGenerator
Writes a JSON name/null value pair in an current object context.- Specified by:
writeNull
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/null pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON value within the current array context.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
-
writeStartArray
Description copied from interface:JsonGenerator
Writes the JSON start array character. It starts a new child array context within which JSON values can be written to the array. This method is valid only in an array context or in no context (when a context is not yet started). This method can only be called once in no context.- Specified by:
writeStartArray
in interfaceJsonGenerator
- Returns:
- this generator
-
writeStartArray
Description copied from interface:JsonGenerator
Writes the JSON name/start array character pair with in the current object context. It starts a new child array context within which JSON values can be written to the array.- Specified by:
writeStartArray
in interfaceJsonGenerator
- Parameters:
name
- a name within the JSON name/array pair to be written- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes a JSON name/value pair in the current object context.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
name
- a name in the JSON name/value pair to be written in current JSON objectvalue
- a value in the JSON name/value pair to be written in current JSON object- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON string value within the current array context.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON number value within the current array context. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON number value within the current array context. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON number value within the current array context. The stringBigDecimal.valueOf(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON number value within the current array context. The stringnew BigDecimal(value).toString()
is used as the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator.
- See Also:
-
write
Description copied from interface:JsonGenerator
Writes the specified value as a JSON number value within the current array context. The specified value'stoString()
is used as the the text value for writing.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- a value to be written in current JSON array- Returns:
- this generator
- See Also:
-
write
Description copied from interface:JsonGenerator
Writes a JSON true or false value within the current array context. If value is true, this method writes the JSONtrue
value, otherwise it writes the JSONfalse
value.- Specified by:
write
in interfaceJsonGenerator
- Parameters:
value
- aboolean
value- Returns:
- this generator
-
writeNull
Description copied from interface:JsonGenerator
Writes a JSON null value within the current array context.- Specified by:
writeNull
in interfaceJsonGenerator
- Returns:
- this generator
-
writeValue
-
writeValue
-
writeEnd
Description copied from interface:JsonGenerator
Writes the end of the current context. If the current context is an array context, this method writes the end-of-array character (']'). If the current context is an object context, this method writes the end-of-object character ('}'). After writing the end of the current context, the parent context becomes the new current context.- Specified by:
writeEnd
in interfaceJsonGenerator
- Returns:
- this generator
-
writeComma
protected void writeComma() -
close
public void close()Description copied from interface:JsonGenerator
Closes this generator and frees any resources associated with it. This method closes the underlying output source.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceJsonGenerator
-
writeEscapedString
-
writeString
-
writeString
-
writeChar
void writeChar(char c) -
writeInt
void writeInt(int num) -
flushBuffer
void flushBuffer() -
stringSize
private static int stringSize(int x) -
fillIntChars
private static void fillIntChars(int i, char[] buf, int index) Places characters representing the integer i into the character array buf. The characters are placed into the buffer backwards starting with the least significant digit at the specified index (exclusive), and working backwards from there. Will fail if i == Integer.MIN_VALUE
-