public class TokenBuffer extends JsonGenerator
JsonToken
sequences, needed for temporary buffering.
Space efficient for different sequence lengths (especially so for smaller
ones; but not significantly less efficient for larger), highly efficient
for linear iteration and appending. Implemented as segmented/chunked
linked list of tokens; only modifications are via appends.
Note that before version 2.0, this class was located in the "core" bundle, not data-binding; but since it was only used by data binding, was moved here to reduce size of core package
| Modifier and Type | Class and Description |
|---|---|
protected static class |
TokenBuffer.Parser |
protected static class |
TokenBuffer.Segment
Individual segment of TokenBuffer that can store up to 16 tokens
(limited by 4 bits per token type marker requirement).
|
JsonGenerator.Feature| Modifier and Type | Field and Description |
|---|---|
protected int |
_appendAt
Offset within last segment,
|
protected boolean |
_closed |
protected TokenBuffer.Segment |
_first
First segment, for contents this buffer has
|
protected boolean |
_forceBigDecimal
Flag set during construction, if use of
BigDecimal is to be forced
on all floating-point values. |
protected int |
_generatorFeatures
Bit flag composed of bits that indicate which
JsonGenerator.Features
are enabled. |
protected boolean |
_hasNativeId
Do we currently have a native type or object id buffered?
|
protected boolean |
_hasNativeObjectIds |
protected boolean |
_hasNativeTypeIds |
protected TokenBuffer.Segment |
_last
Last segment of this buffer, one that is used
for appending more tokens
|
protected boolean |
_mayHaveNativeIds |
protected ObjectCodec |
_objectCodec
Object codec to use for stream-based object
conversion through parser/generator interfaces.
|
protected Object |
_objectId
If native object ids supported, this is the id for following
value (or first token of one) to be written.
|
protected JsonStreamContext |
_parentContext
Parse context from "parent" parser (one from which content to buffer is read,
if specified).
|
protected Object |
_typeId
If native type ids supported, this is the id for following
value (or first token of one) to be written.
|
protected JsonWriteContext |
_writeContext |
protected static int |
DEFAULT_GENERATOR_FEATURES |
_cfgPrettyPrinter| Constructor and Description |
|---|
TokenBuffer(JsonParser p) |
TokenBuffer(JsonParser p,
DeserializationContext ctxt) |
TokenBuffer(ObjectCodec codec,
boolean hasNativeIds) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_appendEndMarker(JsonToken type)
Specialized method used for appending a structural end Object/Array marker
|
protected void |
_appendFieldName(Object value)
Specialized method used for appending a field name, appending either
String or SerializableString. |
protected void |
_appendStartMarker(JsonToken type)
Specialized method used for appending a structural start Object/Array marker
|
protected void |
_appendValue(JsonToken type)
Method used for appending token known to represent a "simple" scalar
value where token is the only information
|
protected void |
_appendValue(JsonToken type,
Object value)
Method used for appending token known to represent a scalar value
where there is additional content (text, number) beyond type token
|
protected void |
_copyBufferContents(JsonParser p) |
protected void |
_reportUnsupportedOperation() |
TokenBuffer |
append(TokenBuffer other)
Helper method that will append contents of given buffer into this
buffer.
|
static TokenBuffer |
asCopyOfValue(JsonParser p)
Convenience method, equivalent to:
|
JsonParser |
asParser()
Method used to create a
JsonParser that can read contents
stored in this buffer. |
JsonParser |
asParser(JsonParser src) |
JsonParser |
asParser(ObjectCodec codec)
Method used to create a
JsonParser that can read contents
stored in this buffer. |
JsonParser |
asParserOnFirstToken()
Same as:
|
boolean |
canWriteBinaryNatively()
Since we can efficiently store
byte[], yes. |
boolean |
canWriteObjectId() |
boolean |
canWriteTypeId() |
void |
close() |
void |
copyCurrentEvent(JsonParser p) |
void |
copyCurrentStructure(JsonParser p) |
TokenBuffer |
deserialize(JsonParser p,
DeserializationContext ctxt)
Helper method used by standard deserializer.
|
JsonGenerator |
disable(JsonGenerator.Feature f) |
JsonGenerator |
enable(JsonGenerator.Feature f) |
JsonToken |
firstToken() |
void |
flush() |
TokenBuffer |
forceUseOfBigDecimal(boolean b) |
ObjectCodec |
getCodec() |
int |
getFeatureMask() |
JsonWriteContext |
getOutputContext() |
boolean |
isClosed() |
boolean |
isEnabled(JsonGenerator.Feature f) |
TokenBuffer |
overrideParentContext(JsonStreamContext ctxt)
Method that allows explicitly specifying parent parse context to associate
with contents of this buffer.
|
JsonGenerator |
overrideStdFeatures(int values,
int mask) |
void |
serialize(JsonGenerator gen)
Helper method that will write all contents of this buffer
using given
JsonGenerator. |
JsonGenerator |
setCodec(ObjectCodec oc) |
JsonGenerator |
setFeatureMask(int mask)
Deprecated.
|
String |
toString() |
JsonGenerator |
useDefaultPrettyPrinter() |
Version |
version() |
void |
writeBinary(Base64Variant b64variant,
byte[] data,
int offset,
int len) |
int |
writeBinary(Base64Variant b64variant,
InputStream data,
int dataLength)
Although we could support this method, it does not necessarily make
sense: we cannot make good use of streaming because buffer must
hold all the data.
|
void |
writeBoolean(boolean state) |
void |
writeEmbeddedObject(Object object) |
void |
writeEndArray() |
void |
writeEndObject() |
void |
writeFieldName(SerializableString name) |
void |
writeFieldName(String name) |
void |
writeNull() |
void |
writeNumber(BigDecimal dec) |
void |
writeNumber(BigInteger v) |
void |
writeNumber(double d) |
void |
writeNumber(float f) |
void |
writeNumber(int i) |
void |
writeNumber(long l) |
void |
writeNumber(short i) |
void |
writeNumber(String encodedValue) |
void |
writeObject(Object value) |
void |
writeObjectId(Object id) |
void |
writeRaw(char c) |
void |
writeRaw(char[] text,
int offset,
int len) |
void |
writeRaw(SerializableString text) |
void |
writeRaw(String text) |
void |
writeRaw(String text,
int offset,
int len) |
void |
writeRawUTF8String(byte[] text,
int offset,
int length) |
void |
writeRawValue(char[] text,
int offset,
int len) |
void |
writeRawValue(String text) |
void |
writeRawValue(String text,
int offset,
int len) |
void |
writeStartArray() |
void |
writeStartArray(int size) |
void |
writeStartArray(Object forValue) |
void |
writeStartArray(Object forValue,
int size) |
void |
writeStartObject() |
void |
writeStartObject(Object forValue) |
void |
writeStartObject(Object forValue,
int size) |
void |
writeString(char[] text,
int offset,
int len) |
void |
writeString(SerializableString text) |
void |
writeString(String text) |
void |
writeTree(TreeNode node) |
void |
writeTypeId(Object id) |
void |
writeUTF8String(byte[] text,
int offset,
int length) |
_copyCurrentContents, _reportError, _throwInternal, _verifyOffsets, _writeSimpleObject, canOmitFields, canUseSchema, canWriteFormattedNumbers, configure, getCharacterEscapes, getCurrentValue, getFormatFeatures, getHighestEscapedChar, getOutputBuffered, getOutputTarget, getPrettyPrinter, getSchema, isEnabled, overrideFormatFeatures, setCharacterEscapes, setCurrentValue, setHighestNonEscapedChar, setPrettyPrinter, setRootValueSeparator, setSchema, writeArray, writeArray, writeArray, writeArray, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeFieldId, writeNullField, writeNumber, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeObjectRef, writeOmittedField, writeRawValue, writeString, writeStringField, writeTypePrefix, writeTypeSuffixprotected static final int DEFAULT_GENERATOR_FEATURES
protected ObjectCodec _objectCodec
protected JsonStreamContext _parentContext
protected int _generatorFeatures
JsonGenerator.Features
are enabled.
NOTE: most features have no effect on this class
protected boolean _closed
protected boolean _hasNativeTypeIds
protected boolean _hasNativeObjectIds
protected boolean _mayHaveNativeIds
protected boolean _forceBigDecimal
BigDecimal is to be forced
on all floating-point values.protected TokenBuffer.Segment _first
protected TokenBuffer.Segment _last
protected int _appendAt
protected Object _typeId
protected Object _objectId
protected boolean _hasNativeId
protected JsonWriteContext _writeContext
public TokenBuffer(ObjectCodec codec, boolean hasNativeIds)
codec - Object codec to use for stream-based object
conversion through parser/generator interfaces. If null,
such methods cannot be used.hasNativeIds - Whether resulting JsonParser (if created)
is considered to support native type and object idspublic TokenBuffer(JsonParser p)
public TokenBuffer(JsonParser p, DeserializationContext ctxt)
public static TokenBuffer asCopyOfValue(JsonParser p) throws IOException
TokenBuffer b = new TokenBuffer(p); b.copyCurrentStructure(p); return b;
IOExceptionpublic TokenBuffer overrideParentContext(JsonStreamContext ctxt)
public TokenBuffer forceUseOfBigDecimal(boolean b)
public Version version()
version in interface Versionedversion in class JsonGeneratorpublic JsonParser asParser()
JsonParser that can read contents
stored in this buffer. Will use default _objectCodec for
object conversions.
Note: instances are not synchronized, that is, they are not thread-safe if there are concurrent appends to the underlying buffer.
public JsonParser asParserOnFirstToken() throws IOException
JsonParser p = asParser(); p.nextToken(); return p;
IOExceptionpublic JsonParser asParser(ObjectCodec codec)
JsonParser that can read contents
stored in this buffer.
Note: instances are not synchronized, that is, they are not thread-safe if there are concurrent appends to the underlying buffer.
codec - Object codec to use for stream-based object
conversion through parser/generator interfaces. If null,
such methods cannot be used.public JsonParser asParser(JsonParser src)
src - Parser to use for accessing source information
like location, configured codecpublic JsonToken firstToken()
public TokenBuffer append(TokenBuffer other) throws IOException
IOExceptionpublic void serialize(JsonGenerator gen) throws IOException
JsonGenerator.
Note: this method would be enough to implement
JsonSerializer for TokenBuffer type;
but we cannot have upwards
references (from core to mapper package); and as such we also
cannot take second argument.
IOExceptionpublic TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
IOExceptionpublic JsonGenerator enable(JsonGenerator.Feature f)
enable in class JsonGeneratorpublic JsonGenerator disable(JsonGenerator.Feature f)
disable in class JsonGeneratorpublic boolean isEnabled(JsonGenerator.Feature f)
isEnabled in class JsonGeneratorpublic int getFeatureMask()
getFeatureMask in class JsonGenerator@Deprecated public JsonGenerator setFeatureMask(int mask)
setFeatureMask in class JsonGeneratorpublic JsonGenerator overrideStdFeatures(int values, int mask)
overrideStdFeatures in class JsonGeneratorpublic JsonGenerator useDefaultPrettyPrinter()
useDefaultPrettyPrinter in class JsonGeneratorpublic JsonGenerator setCodec(ObjectCodec oc)
setCodec in class JsonGeneratorpublic ObjectCodec getCodec()
getCodec in class JsonGeneratorpublic final JsonWriteContext getOutputContext()
getOutputContext in class JsonGeneratorpublic boolean canWriteBinaryNatively()
byte[], yes.canWriteBinaryNatively in class JsonGeneratorpublic void flush()
throws IOException
flush in interface Flushableflush in class JsonGeneratorIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class JsonGeneratorIOExceptionpublic boolean isClosed()
isClosed in class JsonGeneratorpublic final void writeStartArray()
throws IOException
writeStartArray in class JsonGeneratorIOExceptionpublic final void writeStartArray(int size)
throws IOException
writeStartArray in class JsonGeneratorIOExceptionpublic void writeStartArray(Object forValue) throws IOException
writeStartArray in class JsonGeneratorIOExceptionpublic void writeStartArray(Object forValue, int size) throws IOException
writeStartArray in class JsonGeneratorIOExceptionpublic final void writeEndArray()
throws IOException
writeEndArray in class JsonGeneratorIOExceptionpublic final void writeStartObject()
throws IOException
writeStartObject in class JsonGeneratorIOExceptionpublic void writeStartObject(Object forValue) throws IOException
writeStartObject in class JsonGeneratorIOExceptionpublic void writeStartObject(Object forValue, int size) throws IOException
writeStartObject in class JsonGeneratorIOExceptionpublic final void writeEndObject()
throws IOException
writeEndObject in class JsonGeneratorIOExceptionpublic final void writeFieldName(String name) throws IOException
writeFieldName in class JsonGeneratorIOExceptionpublic void writeFieldName(SerializableString name) throws IOException
writeFieldName in class JsonGeneratorIOExceptionpublic void writeString(String text) throws IOException
writeString in class JsonGeneratorIOExceptionpublic void writeString(char[] text,
int offset,
int len)
throws IOException
writeString in class JsonGeneratorIOExceptionpublic void writeString(SerializableString text) throws IOException
writeString in class JsonGeneratorIOExceptionpublic void writeRawUTF8String(byte[] text,
int offset,
int length)
throws IOException
writeRawUTF8String in class JsonGeneratorIOExceptionpublic void writeUTF8String(byte[] text,
int offset,
int length)
throws IOException
writeUTF8String in class JsonGeneratorIOExceptionpublic void writeRaw(String text) throws IOException
writeRaw in class JsonGeneratorIOExceptionpublic void writeRaw(String text, int offset, int len) throws IOException
writeRaw in class JsonGeneratorIOExceptionpublic void writeRaw(SerializableString text) throws IOException
writeRaw in class JsonGeneratorIOExceptionpublic void writeRaw(char[] text,
int offset,
int len)
throws IOException
writeRaw in class JsonGeneratorIOExceptionpublic void writeRaw(char c)
throws IOException
writeRaw in class JsonGeneratorIOExceptionpublic void writeRawValue(String text) throws IOException
writeRawValue in class JsonGeneratorIOExceptionpublic void writeRawValue(String text, int offset, int len) throws IOException
writeRawValue in class JsonGeneratorIOExceptionpublic void writeRawValue(char[] text,
int offset,
int len)
throws IOException
writeRawValue in class JsonGeneratorIOExceptionpublic void writeNumber(short i)
throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(int i)
throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(long l)
throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(double d)
throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(float f)
throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(BigDecimal dec) throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(BigInteger v) throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeNumber(String encodedValue) throws IOException
writeNumber in class JsonGeneratorIOExceptionpublic void writeBoolean(boolean state)
throws IOException
writeBoolean in class JsonGeneratorIOExceptionpublic void writeNull()
throws IOException
writeNull in class JsonGeneratorIOExceptionpublic void writeObject(Object value) throws IOException
writeObject in class JsonGeneratorIOExceptionpublic void writeTree(TreeNode node) throws IOException
writeTree in class JsonGeneratorIOExceptionpublic void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
writeBinary in class JsonGeneratorIOExceptionpublic int writeBinary(Base64Variant b64variant, InputStream data, int dataLength)
UnsupportedOperationExceptionwriteBinary in class JsonGeneratorpublic boolean canWriteTypeId()
canWriteTypeId in class JsonGeneratorpublic boolean canWriteObjectId()
canWriteObjectId in class JsonGeneratorpublic void writeTypeId(Object id)
writeTypeId in class JsonGeneratorpublic void writeObjectId(Object id)
writeObjectId in class JsonGeneratorpublic void writeEmbeddedObject(Object object) throws IOException
writeEmbeddedObject in class JsonGeneratorIOExceptionpublic void copyCurrentEvent(JsonParser p) throws IOException
copyCurrentEvent in class JsonGeneratorIOExceptionpublic void copyCurrentStructure(JsonParser p) throws IOException
copyCurrentStructure in class JsonGeneratorIOExceptionprotected void _copyBufferContents(JsonParser p) throws IOException
IOExceptionprotected final void _appendValue(JsonToken type)
protected final void _appendValue(JsonToken type, Object value)
protected final void _appendFieldName(Object value)
String or SerializableString.protected final void _appendStartMarker(JsonToken type)
protected final void _appendEndMarker(JsonToken type)
protected void _reportUnsupportedOperation()
_reportUnsupportedOperation in class JsonGeneratorCopyright © 2008–2020 FasterXML. All rights reserved.