java.lang.Object
tools.jackson.core.JsonGenerator
tools.jackson.databind.util.TokenBuffer
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Versioned
Utility class used for efficient storage of
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final class
protected static final class
Individual segment of TokenBuffer that can store up to 16 tokens (limited by 4 bits per token type marker requirement). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Offset within last segment,protected boolean
protected TokenBuffer.Segment
First segment, for contents this buffer hasprotected boolean
Flag set during construction, if use ofBigDecimal
is to be forced on all floating-point values.protected boolean
Do we currently have a native type or object id buffered?protected boolean
protected boolean
protected TokenBuffer.Segment
Last segment of this buffer, one that is used for appending more tokensprotected boolean
protected Object
If native object ids supported, this is the id for following value (or first token of one) to be written.protected ObjectWriteContext
protected TokenStreamContext
Parse context from "parent" parser (one from which content to buffer is read, if specified).protected final StreamReadConstraints
protected int
Bit flag composed of bits that indicate whichStreamWriteFeature
s are enabled.protected SimpleStreamWriteContext
protected Object
If native type ids supported, this is the id for following value (or first token of one) to be written.protected static final JacksonFeatureSet<StreamWriteCapability>
protected static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionTokenBuffer
(boolean hasNativeIds) Deprecated.protected
TokenBuffer
(JsonParser p, ObjectReadContext ctxt) TokenBuffer
(ObjectWriteContext writeContext, boolean hasNativeIds) -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
_appendEndMarker
(JsonToken type) Specialized method used for appending a structural end Object/Array markerprotected final void
_appendName
(Object value) protected final void
_appendStartMarker
(JsonToken type) Specialized method used for appending a structural start Object/Array markerprotected final void
_appendValue
(JsonToken type) Method used for appending token known to represent a "simple" scalar value where token is the only informationprotected final 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 tokenprotected void
protected <T> T
append
(TokenBuffer other) Helper method that will append contents of given buffer into this buffer.asParser()
Method used to create aJsonParser
that can read contents stored in this buffer.asParser
(ObjectReadContext readCtxt) Method used to create aJsonParser
that can read contents stored in this buffer.asParser
(ObjectReadContext readCtxt, JsonParser p0) asParserOnFirstToken
(ObjectReadContext readCtxt) Same as:asParserOnFirstToken
(ObjectReadContext readCtxt, JsonParser src) void
boolean
boolean
void
close()
configure
(StreamWriteFeature f, boolean state) void
void
deserialize
(JsonParser p, DeserializationContext ctxt) Helper method used by standard deserializer.void
flush()
static TokenBuffer
forBuffering
(JsonParser p, ObjectReadContext ctxt) Specialized factory method used when we are specifically buffering contents of a token stream for further processing.forceUseOfBigDecimal
(boolean b) static TokenBuffer
Specialized factory method used when we are generating token stream for further processing without tokens coming from specific input token stream.boolean
isClosed()
boolean
isEmpty()
Accessor for checking whether this buffer has one or more tokens or not.boolean
Method that allows explicitly specifying parent parse context to associate with contents of this buffer.void
serialize
(JsonGenerator gen) Helper method that will write all contents of this buffer using givenJsonGenerator
.int
int
toString()
version()
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.writeBoolean
(boolean state) writeEmbeddedObject
(Object object) final JsonGenerator
final JsonGenerator
final JsonGenerator
writeName
(SerializableString name) writeNumber
(double d) writeNumber
(float f) writeNumber
(int i) writeNumber
(long l) writeNumber
(short i) writeNumber
(String encodedValue) void
writeNumber
(String encodedValue, boolean isInteger) Write method that can be used for custom numeric types that can not be (easily?)writeNumber
(BigDecimal dec) writeObjectId
(Object id) writePropertyId
(long id) writeRaw
(char c) writeRaw
(char[] text, int offset, int len) writeRaw
(SerializableString text) writeRawUTF8String
(byte[] text, int offset, int length) writeRawValue
(char[] text, int offset, int len) writeRawValue
(String text) writeRawValue
(String text, int offset, int len) final JsonGenerator
final JsonGenerator
writeStartArray
(Object forValue) final JsonGenerator
writeStartArray
(Object forValue, int len) final JsonGenerator
writeStartObject
(Object forValue) writeStartObject
(Object forValue, int size) writeString
(char[] text, int offset, int len) writeString
(Reader reader, int len) writeString
(String text) writeTypeId
(Object id) writeUTF8String
(byte[] text, int offset, int length) Methods inherited from class tools.jackson.core.JsonGenerator
_constructWriteException, _constructWriteException, _constructWriteException, _constructWriteException, _copyCurrentContents, _copyCurrentFloatValue, _copyCurrentFloatValueExact, _copyCurrentIntValue, _copyCurrentStringValue, _reportArgumentError, _reportError, _reportUnsupportedOperation, _verifyOffsets, _wrapIOFailure, _writeTypePrefixUsingNative, _writeTypePrefixUsingWrapper, canOmitProperties, copyCurrentEventExact, getCharacterEscapes, getHighestNonEscapedChar, getSchema, setCharacterEscapes, streamWriteConstraints, writeArray, writeArray, writeArray, writeArray, writeArrayPropertyStart, writeBinary, writeBinary, writeBinary, writeBinaryProperty, writeBooleanProperty, writeNullProperty, writeNumber, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeNumberProperty, writeObjectPropertyStart, writeObjectRef, writeOmittedProperty, writePOJOProperty, writeRawValue, writeStringProperty, writeTypePrefix, writeTypeSuffix
-
Field Details
-
DEFAULT_STREAM_WRITE_FEATURES
protected static final int DEFAULT_STREAM_WRITE_FEATURES -
BOGUS_WRITE_CAPABILITIES
-
_parentContext
Parse context from "parent" parser (one from which content to buffer is read, if specified). Used, if available, when reading content, to present full context as if content was read from the original parser: this is useful in error reporting and sometimes processing as well. -
_streamWriteFeatures
protected int _streamWriteFeaturesBit flag composed of bits that indicate whichStreamWriteFeature
s are enabled.NOTE: most features have no effect on this class
-
_streamReadConstraints
-
_closed
protected boolean _closed -
_hasNativeTypeIds
protected boolean _hasNativeTypeIds -
_hasNativeObjectIds
protected boolean _hasNativeObjectIds -
_mayHaveNativeIds
protected boolean _mayHaveNativeIds -
_forceBigDecimal
protected boolean _forceBigDecimalFlag set during construction, if use ofBigDecimal
is to be forced on all floating-point values. -
_first
First segment, for contents this buffer has -
_last
Last segment of this buffer, one that is used for appending more tokens -
_appendAt
protected int _appendAtOffset within last segment, -
_typeId
If native type ids supported, this is the id for following value (or first token of one) to be written. -
_objectId
If native object ids supported, this is the id for following value (or first token of one) to be written. -
_hasNativeId
protected boolean _hasNativeIdDo we currently have a native type or object id buffered? -
_tokenWriteContext
-
_objectWriteContext
- Since:
- 3.0
-
-
Constructor Details
-
TokenBuffer
Deprecated.- Parameters:
hasNativeIds
- Whether resultingJsonParser
(if created) is considered to support native type and object ids
-
TokenBuffer
- Since:
- 3.0
-
TokenBuffer
-
-
Method Details
-
forGeneration
Specialized factory method used when we are generating token stream for further processing without tokens coming from specific input token stream.- Since:
- 3.0
-
forBuffering
Specialized factory method used when we are specifically buffering contents of a token stream for further processing.- Since:
- 3.0
-
overrideParentContext
Method that allows explicitly specifying parent parse context to associate with contents of this buffer. Usually context is assigned at construction, based on given parser; but it is not always available, and may not contain intended context. -
forceUseOfBigDecimal
-
asParser
Method used to create aJsonParser
that can read contents stored in this buffer. Will create an "empty" read context (seeObjectReadContext.empty()
which often is not what you want.Note: instances are not synchronized, that is, they are not thread-safe if there are concurrent appends to the underlying buffer.
- Returns:
- Parser that can be used for reading contents stored in this buffer
-
asParser
Method used to create aJsonParser
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.
- Parameters:
readCtxt
- Active read context to use.- Returns:
- Parser that can be used for reading contents stored in this buffer
-
asParser
- Parameters:
p0
- Parser to use for accessing source information like location, streamReadConstraints
-
asParserOnFirstToken
Same as:JsonParser p = asParser(readCtxt); p.nextToken(); return p;
- Throws:
JacksonException
-
asParserOnFirstToken
public JsonParser asParserOnFirstToken(ObjectReadContext readCtxt, JsonParser src) throws JacksonException - Throws:
JacksonException
-
version
- Specified by:
version
in interfaceVersioned
- Specified by:
version
in classJsonGenerator
-
firstToken
-
isEmpty
public boolean isEmpty()Accessor for checking whether this buffer has one or more tokens or not.- Returns:
- True if this buffer instance has no tokens
- Since:
- 2.13
-
append
Helper method that will append contents of given buffer into this buffer. Not particularly optimized; can be made faster if there is need.- Returns:
- This buffer
-
serialize
Helper method that will write all contents of this buffer using givenJsonGenerator
.Note: this method would be enough to implement
ValueSerializer
forTokenBuffer
type; but we cannot have upwards references (from core to mapper package); and as such we also cannot take second argument.- Throws:
JacksonException
-
deserialize
Helper method used by standard deserializer.- Throws:
JacksonException
-
toString
-
streamWriteContext
- Specified by:
streamWriteContext
in classJsonGenerator
-
currentValue
- Specified by:
currentValue
in classJsonGenerator
-
assignCurrentValue
- Specified by:
assignCurrentValue
in classJsonGenerator
-
objectWriteContext
- Specified by:
objectWriteContext
in classJsonGenerator
-
configure
- Specified by:
configure
in classJsonGenerator
-
isEnabled
- Specified by:
isEnabled
in classJsonGenerator
-
streamWriteFeatures
public int streamWriteFeatures()- Specified by:
streamWriteFeatures
in classJsonGenerator
-
streamWriteCapabilities
- Specified by:
streamWriteCapabilities
in classJsonGenerator
-
flush
public void flush()- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classJsonGenerator
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classJsonGenerator
-
isClosed
public boolean isClosed()- Specified by:
isClosed
in classJsonGenerator
-
streamWriteOutputTarget
- Specified by:
streamWriteOutputTarget
in classJsonGenerator
-
streamWriteOutputBuffered
public int streamWriteOutputBuffered()- Specified by:
streamWriteOutputBuffered
in classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArray
in classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArray
in classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArray
in classJsonGenerator
-
writeEndArray
- Specified by:
writeEndArray
in classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObject
in classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObject
in classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObject
in classJsonGenerator
-
writeEndObject
- Specified by:
writeEndObject
in classJsonGenerator
-
writeName
- Specified by:
writeName
in classJsonGenerator
-
writeName
- Specified by:
writeName
in classJsonGenerator
-
writePropertyId
- Specified by:
writePropertyId
in classJsonGenerator
-
writeString
- Specified by:
writeString
in classJsonGenerator
-
writeString
- Specified by:
writeString
in classJsonGenerator
-
writeString
- Specified by:
writeString
in classJsonGenerator
-
writeString
- Specified by:
writeString
in classJsonGenerator
-
writeRawUTF8String
- Specified by:
writeRawUTF8String
in classJsonGenerator
-
writeUTF8String
- Specified by:
writeUTF8String
in classJsonGenerator
-
writeRaw
- Specified by:
writeRaw
in classJsonGenerator
-
writeRaw
- Specified by:
writeRaw
in classJsonGenerator
-
writeRaw
- Overrides:
writeRaw
in classJsonGenerator
-
writeRaw
- Specified by:
writeRaw
in classJsonGenerator
-
writeRaw
- Specified by:
writeRaw
in classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValue
in classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValue
in classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValue
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
- Specified by:
writeNumber
in classJsonGenerator
-
writeNumber
Write method that can be used for custom numeric types that can not be (easily?) converted to "standard" Java number types. Because numbers are not surrounded by double quotes, regularwriteString(java.lang.String)
method can not be used; norwriteRaw(java.lang.String)
because that does not properly handle value separators needed in Array or Object contexts.- Parameters:
encodedValue
- Textual (possibly formatted) number representation to writeisInteger
- Whether value should be considered an integer- Throws:
IOException
- if there is either an underlying I/O problem or encoding issue at format layer- Since:
- 2.18
-
writeBoolean
- Specified by:
writeBoolean
in classJsonGenerator
-
writeNull
- Specified by:
writeNull
in classJsonGenerator
-
writePOJO
- Specified by:
writePOJO
in classJsonGenerator
-
writeTree
- Specified by:
writeTree
in classJsonGenerator
-
writeBinary
- Specified by:
writeBinary
in classJsonGenerator
-
writeBinary
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. Because of this, currently this will simply throwUnsupportedOperationException
- Specified by:
writeBinary
in classJsonGenerator
-
canWriteTypeId
public boolean canWriteTypeId()- Overrides:
canWriteTypeId
in classJsonGenerator
-
canWriteObjectId
public boolean canWriteObjectId()- Overrides:
canWriteObjectId
in classJsonGenerator
-
writeTypeId
- Overrides:
writeTypeId
in classJsonGenerator
-
writeObjectId
- Overrides:
writeObjectId
in classJsonGenerator
-
writeEmbeddedObject
- Overrides:
writeEmbeddedObject
in classJsonGenerator
-
copyCurrentEvent
- Overrides:
copyCurrentEvent
in classJsonGenerator
-
copyCurrentStructure
- Overrides:
copyCurrentStructure
in classJsonGenerator
-
_copyBufferContents
-
_appendValue
Method used for appending token known to represent a "simple" scalar value where token is the only information -
_appendValue
Method used for appending token known to represent a scalar value where there is additional content (text, number) beyond type token -
_appendName
-
_appendStartMarker
Specialized method used for appending a structural start Object/Array marker -
_appendEndMarker
Specialized method used for appending a structural end Object/Array marker -
_reportUnsupportedOperation
protected <T> T _reportUnsupportedOperation()- Overrides:
_reportUnsupportedOperation
in classJsonGenerator
-