Package org.glassfish.json
Class JsonGeneratorImpl
- java.lang.Object
-
- org.glassfish.json.JsonGeneratorImpl
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,JsonGenerator
- Direct Known Subclasses:
JsonPrettyGeneratorImpl
class JsonGeneratorImpl extends java.lang.Object implements JsonGenerator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classJsonGeneratorImpl.Contextprivate static classJsonGeneratorImpl.Scope
-
Field Summary
Fields Modifier and Type Field Description private char[]bufprivate BufferPoolbufferPoolprivate JsonGeneratorImpl.ContextcurrentContextprivate static char[]DIGIT_ONESprivate static char[]DIGIT_TENSprivate static char[]DIGITSAll possible chars for representing a number as a Stringprivate static int[]INT_CHARS_SIZE_TABLEprivate static char[]INT_MIN_VALUE_CHARSprivate intlenprivate java.util.Deque<JsonGeneratorImpl.Context>stackprivate java.io.Writerwriter-
Fields inherited from interface javax.json.stream.JsonGenerator
PRETTY_PRINTING
-
-
Constructor Summary
Constructors Constructor Description JsonGeneratorImpl(java.io.OutputStream out, java.nio.charset.Charset encoding, BufferPool bufferPool)JsonGeneratorImpl(java.io.OutputStream out, BufferPool bufferPool)JsonGeneratorImpl(java.io.Writer writer, BufferPool bufferPool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckContextForValue()voidclose()Closes this generator and frees any resources associated with it.private static voidfillIntChars(int i, char[] buf, int index)Places characters representing the integer i into the character array buf.voidflush()Flushes the underlying output source.(package private) voidflushBuffer()(package private) booleanisCommaAllowed()private voidpopFieldContext()private static intstringSize(int x)JsonGeneratorwrite(boolean value)Writes a JSON true or false value within the current array, field or root context.JsonGeneratorwrite(double value)Writes the specified value as a JSON number value within the current array, field or root context.JsonGeneratorwrite(int value)Writes the specified value as a JSON number value within the current array, field or root context.JsonGeneratorwrite(long value)Writes the specified value as a JSON number value within the current array, field or root context.JsonGeneratorwrite(java.lang.String value)Writes the specified value as a JSON string value within the current array, field or root context.JsonGeneratorwrite(java.lang.String name, boolean value)Writes a JSON name/boolean value pair in the current object context.JsonGeneratorwrite(java.lang.String name, double value)Writes a JSON name/number value pair in the current object context.JsonGeneratorwrite(java.lang.String name, int value)Writes a JSON name/number value pair in the current object context.JsonGeneratorwrite(java.lang.String name, long value)Writes a JSON name/number value pair in the current object context.JsonGeneratorwrite(java.lang.String name, java.lang.String fieldValue)Writes a JSON name/string value pair in the current object context.JsonGeneratorwrite(java.lang.String name, java.math.BigDecimal value)Writes a JSON name/number value pair in the current object context.JsonGeneratorwrite(java.lang.String name, java.math.BigInteger value)Writes a JSON name/number value pair in the current object context.JsonGeneratorwrite(java.lang.String name, JsonValue value)Writes a JSON name/value pair in the current object context.JsonGeneratorwrite(java.math.BigDecimal value)Writes the specified value as a JSON number value within the current array, field or root context.JsonGeneratorwrite(java.math.BigInteger value)Writes the specified value as a JSON number value within the current array, field or root context.JsonGeneratorwrite(JsonValue value)Writes the specified value as a JSON value within the current array, field or root context.(package private) voidwriteChar(char c)protected voidwriteColon()protected voidwriteComma()JsonGeneratorwriteEnd()Writes the end of the current context.(package private) voidwriteEscapedString(java.lang.String string)(package private) voidwriteInt(int num)JsonGeneratorwriteKey(java.lang.String name)Writes the JSON name with a colon.private JsonGeneratorwriteName(java.lang.String name)JsonGeneratorwriteNull()Writes a JSON null value within the current array, field or root context.JsonGeneratorwriteNull(java.lang.String name)Writes a JSON name/null value pair in an current object context.JsonGeneratorwriteStartArray()Writes the JSON start array character.JsonGeneratorwriteStartArray(java.lang.String name)Writes the JSON name/start array character pair with in the current object context.JsonGeneratorwriteStartObject()Writes the JSON start object character.JsonGeneratorwriteStartObject(java.lang.String name)Writes the JSON name/start object character pair in the current object context.(package private) voidwriteString(java.lang.String str)(package private) voidwriteString(java.lang.String str, int begin, int end)private voidwriteValue(java.lang.String value)private voidwriteValue(java.lang.String name, java.lang.String value)
-
-
-
Field Detail
-
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[] DIGITS
All possible chars for representing a number as a String
-
bufferPool
private final BufferPool bufferPool
-
writer
private final java.io.Writer writer
-
currentContext
private JsonGeneratorImpl.Context currentContext
-
stack
private final java.util.Deque<JsonGeneratorImpl.Context> stack
-
buf
private final char[] buf
-
len
private int len
-
-
Constructor Detail
-
JsonGeneratorImpl
JsonGeneratorImpl(java.io.Writer writer, BufferPool bufferPool)
-
JsonGeneratorImpl
JsonGeneratorImpl(java.io.OutputStream out, BufferPool bufferPool)
-
JsonGeneratorImpl
JsonGeneratorImpl(java.io.OutputStream out, java.nio.charset.Charset encoding, BufferPool bufferPool)
-
-
Method Detail
-
flush
public void flush()
Description copied from interface:JsonGeneratorFlushes 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:
flushin interfacejava.io.Flushable- Specified by:
flushin interfaceJsonGenerator
-
writeStartObject
public JsonGenerator writeStartObject()
Description copied from interface:JsonGeneratorWrites 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, field context or in no context (when a context is not yet started). This method can only be called once in no context.- Specified by:
writeStartObjectin interfaceJsonGenerator- Returns:
- this generator
-
writeStartObject
public JsonGenerator writeStartObject(java.lang.String name)
Description copied from interface:JsonGeneratorWrites 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:
writeStartObjectin interfaceJsonGenerator- Parameters:
name- a name within the JSON name/object pair to be written- Returns:
- this generator
-
writeName
private JsonGenerator writeName(java.lang.String name)
-
write
public JsonGenerator write(java.lang.String name, java.lang.String fieldValue)
Description copied from interface:JsonGeneratorWrites a JSON name/string value pair in the current object context. The specified value is written as JSON string value.- Specified by:
writein 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
public JsonGenerator write(java.lang.String name, int value)
Description copied from interface:JsonGeneratorWrites 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:
writein 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
public JsonGenerator write(java.lang.String name, long value)
Description copied from interface:JsonGeneratorWrites 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:
writein 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
public JsonGenerator write(java.lang.String name, double value)
Description copied from interface:JsonGeneratorWrites 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:
writein 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
public JsonGenerator write(java.lang.String name, java.math.BigInteger value)
Description copied from interface:JsonGeneratorWrites 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:
writein 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
public JsonGenerator write(java.lang.String name, java.math.BigDecimal value)
Description copied from interface:JsonGeneratorWrites 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:
writein 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
public JsonGenerator write(java.lang.String name, boolean value)
Description copied from interface:JsonGeneratorWrites a JSON name/boolean value pair in the current object context. If value is true, it writes the JSONtruevalue, otherwise it writes the JSONfalsevalue.- Specified by:
writein 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
public JsonGenerator writeNull(java.lang.String name)
Description copied from interface:JsonGeneratorWrites a JSON name/null value pair in an current object context.- Specified by:
writeNullin interfaceJsonGenerator- Parameters:
name- a name in the JSON name/null pair to be written in current JSON object- Returns:
- this generator
-
write
public JsonGenerator write(JsonValue value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON value within the current array, field or root context.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
-
writeStartArray
public JsonGenerator writeStartArray()
Description copied from interface:JsonGeneratorWrites 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, field context or in no context (when a context is not yet started). This method can only be called once in no context.- Specified by:
writeStartArrayin interfaceJsonGenerator- Returns:
- this generator
-
writeStartArray
public JsonGenerator writeStartArray(java.lang.String name)
Description copied from interface:JsonGeneratorWrites 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:
writeStartArrayin interfaceJsonGenerator- Parameters:
name- a name within the JSON name/array pair to be written- Returns:
- this generator
-
write
public JsonGenerator write(java.lang.String name, JsonValue value)
Description copied from interface:JsonGeneratorWrites a JSON name/value pair in the current object context.- Specified by:
writein 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
public JsonGenerator write(java.lang.String value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON string value within the current array, field or root context.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
-
write
public JsonGenerator write(int value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON number value within the current array, field or root context. The stringnew BigDecimal(value).toString()is used as the text value for writing.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
-
write
public JsonGenerator write(long value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON number value within the current array, field or root context. The stringnew BigDecimal(value).toString()is used as the text value for writing.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
-
write
public JsonGenerator write(double value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON number value within the current array, field or root context. The stringBigDecimal.valueOf(value).toString()is used as the text value for writing.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
-
write
public JsonGenerator write(java.math.BigInteger value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON number value within the current array, field or root context. The stringnew BigDecimal(value).toString()is used as the text value for writing.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator.
- See Also:
JsonNumber
-
checkContextForValue
private void checkContextForValue()
-
write
public JsonGenerator write(java.math.BigDecimal value)
Description copied from interface:JsonGeneratorWrites the specified value as a JSON number value within the current array, field or root context. The specified value'stoString()is used as the the text value for writing.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- a value to be written in current JSON array- Returns:
- this generator
- See Also:
JsonNumber
-
popFieldContext
private void popFieldContext()
-
write
public JsonGenerator write(boolean value)
Description copied from interface:JsonGeneratorWrites a JSON true or false value within the current array, field or root context. If value is true, this method writes the JSONtruevalue, otherwise it writes the JSONfalsevalue.- Specified by:
writein interfaceJsonGenerator- Parameters:
value- abooleanvalue- Returns:
- this generator
-
writeNull
public JsonGenerator writeNull()
Description copied from interface:JsonGeneratorWrites a JSON null value within the current array, field or root context.- Specified by:
writeNullin interfaceJsonGenerator- Returns:
- this generator
-
writeValue
private void writeValue(java.lang.String value)
-
writeValue
private void writeValue(java.lang.String name, java.lang.String value)
-
writeKey
public JsonGenerator writeKey(java.lang.String name)
Description copied from interface:JsonGeneratorWrites the JSON name with a colon. It starts a field context, in which valid options are writing a value, starting an object or an array. Writing value closes field context, if object or array is started after field name, field context will be closed after object/array close.- Specified by:
writeKeyin interfaceJsonGenerator- Parameters:
name- name of json field- Returns:
- this generator
-
writeEnd
public JsonGenerator writeEnd()
Description copied from interface:JsonGeneratorWrites 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. If parent context is field context, it is closed.- Specified by:
writeEndin interfaceJsonGenerator- Returns:
- this generator
-
writeComma
protected void writeComma()
-
isCommaAllowed
boolean isCommaAllowed()
-
writeColon
protected void writeColon()
-
close
public void close()
Description copied from interface:JsonGeneratorCloses this generator and frees any resources associated with it. This method closes the underlying output source.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceJsonGenerator
-
writeEscapedString
void writeEscapedString(java.lang.String string)
-
writeString
void writeString(java.lang.String str, int begin, int end)
-
writeString
void writeString(java.lang.String str)
-
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
-
-