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 classprotected static final classIndividual segment of TokenBuffer that can store up to 16 tokens (limited by 4 bits per token type marker requirement). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intOffset within last segment,protected booleanprotected TokenBuffer.SegmentFirst segment, for contents this buffer hasprotected booleanFlag set during construction, if use ofBigDecimalis to be forced on all floating-point values.protected booleanDo we currently have a native type or object id buffered?protected booleanprotected booleanprotected TokenBuffer.SegmentLast segment of this buffer, one that is used for appending more tokensprotected booleanprotected ObjectIf native object ids supported, this is the id for following value (or first token of one) to be written.protected ObjectWriteContextprotected TokenStreamContextParse context from "parent" parser (one from which content to buffer is read, if specified).protected final StreamReadConstraintsprotected intBit flag composed of bits that indicate whichStreamWriteFeatures are enabled.protected SimpleStreamWriteContextprotected ObjectIf 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.protectedTokenBuffer(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 voidprotected <T> Tappend(TokenBuffer other) Helper method that will append contents of given buffer into this buffer.asParser()Method used to create aJsonParserthat can read contents stored in this buffer.asParser(ObjectReadContext readCtxt) Method used to create aJsonParserthat can read contents stored in this buffer.asParser(ObjectReadContext readCtxt, JsonParser p0) asParserOnFirstToken(ObjectReadContext readCtxt) Same as:asParserOnFirstToken(ObjectReadContext readCtxt, JsonParser src) voidbooleanbooleanvoidclose()configure(StreamWriteFeature f, boolean state) voidvoiddeserialize(JsonParser p, DeserializationContext ctxt) Helper method used by standard deserializer.voidflush()static TokenBufferforBuffering(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 TokenBufferSpecialized factory method used when we are generating token stream for further processing without tokens coming from specific input token stream.intbooleanhas(StreamWriteCapability capability) booleanisClosed()booleanisEmpty()Accessor for checking whether this buffer has one or more tokens or not.booleanMethod that allows explicitly specifying parent parse context to associate with contents of this buffer.voidserialize(JsonGenerator gen) Helper method that will write all contents of this buffer using givenJsonGenerator.intinttoString()version()writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) intwriteBinary(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 JsonGeneratorfinal JsonGeneratorfinal JsonGeneratorwriteName(SerializableString name) writeNumber(double d) writeNumber(float f) writeNumber(int i) writeNumber(long l) writeNumber(short i) writeNumber(String encodedValue) voidwriteNumber(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 JsonGeneratorfinal JsonGeneratorwriteStartArray(Object forValue) final JsonGeneratorwriteStartArray(Object forValue, int len) final JsonGeneratorwriteStartObject(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, _copyCurrentContentsExact, _copyCurrentFloatValue, _copyCurrentFloatValueExact, _copyCurrentIntValue, _copyCurrentStringValue, _reportArgumentError, _reportError, _reportUnsupportedOperation, _verifyOffsets, _wrapIOFailure, _writeTypePrefixUsingNative, _writeTypePrefixUsingWrapper, canOmitProperties, copyCurrentEventExact, copyCurrentStructureExact, 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 whichStreamWriteFeatures 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 ofBigDecimalis 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 aJsonParserthat 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 aJsonParserthat 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:
versionin interfaceVersioned- Specified by:
versionin classJsonGenerator
-
getCharacterEscapes
- Overrides:
getCharacterEscapesin classJsonGenerator
-
getHighestNonEscapedChar
public int getHighestNonEscapedChar()- Overrides:
getHighestNonEscapedCharin classJsonGenerator
-
getPrettyPrinter
- Overrides:
getPrettyPrinterin classJsonGenerator
-
getSchema
- Overrides:
getSchemain 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
ValueSerializerforTokenBuffertype; 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:
streamWriteContextin classJsonGenerator
-
currentValue
- Specified by:
currentValuein classJsonGenerator
-
assignCurrentValue
- Specified by:
assignCurrentValuein classJsonGenerator
-
objectWriteContext
- Specified by:
objectWriteContextin classJsonGenerator
-
configure
- Specified by:
configurein classJsonGenerator
-
isEnabled
- Specified by:
isEnabledin classJsonGenerator
-
streamWriteFeatures
public int streamWriteFeatures()- Specified by:
streamWriteFeaturesin classJsonGenerator
-
streamWriteCapabilities
- Specified by:
streamWriteCapabilitiesin classJsonGenerator
-
has
- Specified by:
hasin classJsonGenerator
-
flush
public void flush()- Specified by:
flushin interfaceFlushable- Specified by:
flushin classJsonGenerator
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classJsonGenerator
-
isClosed
public boolean isClosed()- Specified by:
isClosedin classJsonGenerator
-
streamWriteOutputTarget
- Specified by:
streamWriteOutputTargetin classJsonGenerator
-
streamWriteOutputBuffered
public int streamWriteOutputBuffered()- Specified by:
streamWriteOutputBufferedin classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArrayin classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArrayin classJsonGenerator
-
writeStartArray
- Specified by:
writeStartArrayin classJsonGenerator
-
writeEndArray
- Specified by:
writeEndArrayin classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObjectin classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObjectin classJsonGenerator
-
writeStartObject
- Specified by:
writeStartObjectin classJsonGenerator
-
writeEndObject
- Specified by:
writeEndObjectin classJsonGenerator
-
writeName
- Specified by:
writeNamein classJsonGenerator
-
writeName
- Specified by:
writeNamein classJsonGenerator
-
writePropertyId
- Specified by:
writePropertyIdin classJsonGenerator
-
writeString
- Specified by:
writeStringin classJsonGenerator
-
writeString
- Specified by:
writeStringin classJsonGenerator
-
writeString
- Specified by:
writeStringin classJsonGenerator
-
writeString
- Specified by:
writeStringin classJsonGenerator
-
writeRawUTF8String
- Specified by:
writeRawUTF8Stringin classJsonGenerator
-
writeUTF8String
- Specified by:
writeUTF8Stringin classJsonGenerator
-
writeRaw
- Specified by:
writeRawin classJsonGenerator
-
writeRaw
- Specified by:
writeRawin classJsonGenerator
-
writeRaw
- Overrides:
writeRawin classJsonGenerator
-
writeRaw
- Specified by:
writeRawin classJsonGenerator
-
writeRaw
- Specified by:
writeRawin classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValuein classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValuein classJsonGenerator
-
writeRawValue
- Specified by:
writeRawValuein classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin classJsonGenerator
-
writeNumber
- Specified by:
writeNumberin 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 cannot 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:
writeBooleanin classJsonGenerator
-
writeNull
- Specified by:
writeNullin classJsonGenerator
-
writePOJO
- Specified by:
writePOJOin classJsonGenerator
-
writeTree
- Specified by:
writeTreein classJsonGenerator
-
writeBinary
- Specified by:
writeBinaryin 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:
writeBinaryin classJsonGenerator
-
canWriteTypeId
public boolean canWriteTypeId()- Overrides:
canWriteTypeIdin classJsonGenerator
-
canWriteObjectId
public boolean canWriteObjectId()- Overrides:
canWriteObjectIdin classJsonGenerator
-
writeTypeId
- Overrides:
writeTypeIdin classJsonGenerator
-
writeObjectId
- Overrides:
writeObjectIdin classJsonGenerator
-
writeEmbeddedObject
- Overrides:
writeEmbeddedObjectin classJsonGenerator
-
copyCurrentEvent
- Overrides:
copyCurrentEventin classJsonGenerator
-
copyCurrentStructure
- Overrides:
copyCurrentStructurein 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:
_reportUnsupportedOperationin classJsonGenerator
-