Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.util

public Class TokenBuffer

extends JsonGenerator
Class Inheritance
Imports
java.io.*, java.math.BigDecimal, .BigInteger, java.util.TreeMap, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.base.ParserMinimalBase, com.fasterxml.jackson.core.io.NumberInput, com.fasterxml.jackson.core.json.JsonWriteContext, com.fasterxml.jackson.core.util.ByteArrayBuilder, .JacksonFeatureSet, com.fasterxml.jackson.databind.*

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 and Inner Type Summary

Modifier and TypeClass and Description
protected static class
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).

Field Summary

Modifier and TypeField and Description
protected int
_appendAt

Offset within last segment,

protected boolean
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 com.fasterxml.jackson.core.JsonGenerator.Features are enabled.

protected boolean
_hasNativeId

Do we currently have a native type or object id buffered?

protected boolean
protected boolean
protected TokenBuffer.Segment
_last

Last segment of this buffer, one that is used for appending more tokens

protected boolean
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 StreamReadConstraints
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
protected static final int
Inherited from com.fasterxml.jackson.core.JsonGenerator:
_cfgPrettyPrinterDEFAULT_BINARY_WRITE_CAPABILITIESDEFAULT_TEXTUAL_WRITE_CAPABILITIESDEFAULT_WRITE_CAPABILITIES

Constructor Summary

AccessConstructor and Description
public
TokenBuffer(ObjectCodec
Object codec to use for stream-based object conversion through parser/generator interfaces. If null, such methods cannot be used.
codec
,
boolean
Whether resulting JsonParser (if created) is considered to support native type and object ids
hasNativeIds
)

public
public

Method Summary

Modifier and TypeMethod and Description
protected final void
_appendEndMarker(JsonToken type)

Specialized method used for appending a structural end Object/Array marker

protected final void
_appendFieldName(Object value)

Specialized method used for appending a field name, appending either String or SerializableString.

private final void
protected final void
_appendStartMarker(JsonToken type)

Specialized method used for appending a structural start Object/Array marker

protected final void
_appendValue(JsonToken type)

Method used for appending token known to represent a "simple" scalar value where token is the only information

protected 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 token

private final void
protected void
private void
protected void
public TokenBuffer

Returns:

This buffer
append
(TokenBuffer other)

Helper method that will append contents of given buffer into this buffer.

public static TokenBuffer
asCopyOfValue(JsonParser p)

Deprecated Since 2.13: use DeserializationContext#bufferAsCopyOfValue instead.
Convenience method, equivalent to:
 TokenBuffer b = new TokenBuffer(p);
 b.copyCurrentStructure(p);
 return b;
public JsonParser

Returns:

Parser that can be used for reading contents stored in this buffer
asParser
()

Method used to create a JsonParser that can read contents stored in this buffer.

public JsonParser

Returns:

Parser that can be used for reading contents stored in this buffer
asParser
(ObjectCodec
Object codec to use for stream-based object conversion through parser/generator interfaces. If null, such methods cannot be used.
codec
)

Method used to create a JsonParser that can read contents stored in this buffer.

public JsonParser
asParser(StreamReadConstraints
constraints for streaming reads
streamReadConstraints
)

public JsonParser
asParser(JsonParser
Parser to use for accessing source information like location, configured codec, streamReadConstraints
src
)

public JsonParser
asParserOnFirstToken()

Same as:

  JsonParser p = asParser();
  p.nextToken();
  return p;
public boolean
canWriteBinaryNatively()

Overrides com.fasterxml.jackson.core.JsonGenerator.canWriteBinaryNatively.

Since we can efficiently store byte[], yes.
public boolean
canWriteObjectId()

Overrides com.fasterxml.jackson.core.JsonGenerator.canWriteObjectId.

Introspection method that may be called to see if the underlying data format supports some kind of Object Ids natively (many do not; for example, JSON doesn't).
public boolean
canWriteTypeId()

Overrides com.fasterxml.jackson.core.JsonGenerator.canWriteTypeId.

Introspection method that may be called to see if the underlying data format supports some kind of Type Ids natively (many do not; for example, JSON doesn't).
public void
close()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.close.

Implements java.io.Closeable.close.

Method called to close this generator, so that no more content can be written.
public void
copyCurrentEvent(JsonParser
Parser that points to event (token) to copy
p
)

Overrides com.fasterxml.jackson.core.JsonGenerator.copyCurrentEvent.

Method for copying contents of the current event that the given parser instance points to.
public void
copyCurrentStructure(JsonParser
Parser that points to the value to copy
p
)

Overrides com.fasterxml.jackson.core.JsonGenerator.copyCurrentStructure.

Method for copying contents of the current event and following events that it encloses the given parser instance points to.
public TokenBuffer
deserialize(JsonParser p, DeserializationContext ctxt)

Helper method used by standard deserializer.

public JsonGenerator
disable(JsonGenerator.Feature
Feature to disable
f
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.disable.

Method for disabling specified feature (check Feature for list of features)
public JsonGenerator
enable(JsonGenerator.Feature
Feature to enable
f
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.enable.

Method for enabling specified generator feature: check Feature for list of available features.
public JsonToken
public void
flush()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.flush.

Implements java.io.Flushable.flush.

Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.
public TokenBuffer
public ObjectCodec
getCodec()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.getCodec.

Method for accessing the object used for writing Java object as JSON content (using method writeObject).
public int
getFeatureMask()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.getFeatureMask.

Bulk access method for getting state of all standard (non-dataformat-specific) JsonGenerator.Features.
public final JsonWriteContext
getOutputContext()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.getOutputContext.

Accessor for context object that provides information about low-level logical position withing output token stream.
public JacksonFeatureSet<StreamWriteCapability>
getWriteCapabilities()

Overrides com.fasterxml.jackson.core.JsonGenerator.getWriteCapabilities.

Accessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).
public boolean
isClosed()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.isClosed.

Method that can be called to determine whether this generator is closed or not.
public boolean

Returns:

True if this buffer instance has no tokens
isEmpty
()

Accessor for checking whether this buffer has one or more tokens or not.

public boolean
isEnabled(JsonGenerator.Feature
Feature to check
f
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.isEnabled.

Method for checking whether given feature is enabled.
public TokenBuffer
overrideParentContext(JsonStreamContext ctxt)

Method that allows explicitly specifying parent parse context to associate with contents of this buffer.

public JsonGenerator
overrideStdFeatures(int
Bit mask of set/clear state for features to change
values
,
int
Bit mask of features to change
mask
)

Overrides com.fasterxml.jackson.core.JsonGenerator.overrideStdFeatures.

Bulk set method for (re)setting states of features specified by mask.
public void
serialize(JsonGenerator gen)

Helper method that will write all contents of this buffer using given JsonGenerator.

public JsonGenerator
setCodec(ObjectCodec
Codec to assign, if any; null if none
oc
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.setCodec.

Method that can be called to set or reset the object to use for writing Java objects as JsonContent (using method writeObject).
public JsonGenerator
setFeatureMask(int
Bitmask that defines which Features are enabled and which disabled
mask
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.setFeatureMask.

Deprecated
Bulk set method for (re)setting states of all standard Features
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public JsonGenerator
useDefaultPrettyPrinter()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.useDefaultPrettyPrinter.

Convenience method for enabling pretty-printing using the default pretty printer (com.fasterxml.jackson.core.util.DefaultPrettyPrinter).
public Version
version()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.version.

Implements com.fasterxml.jackson.core.Versioned.version.

Accessor for finding out version of the bundle that provided this generator instance.
public void
writeBinary(Base64Variant
Base64 variant to use: defines details such as whether padding is used (and if so, using which character); what is the maximum line length before adding linefeed, and also the underlying alphabet to use.
b64variant
,
byte[]
Buffer that contains binary data to write
data
,
int
Offset in data of the first byte of data to write
offset
,
int
Length of data to write
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeBinary.

Method that will output given chunk of binary data as base64 encoded, as a complete String value (surrounded by double quotes).
public int
writeBinary(Base64Variant
Base64 variant to use
b64variant
,
InputStream
InputStream to use for reading binary data to write. Will not be closed after successful write operation
data
,
int
(optional) number of bytes that will be available; or -1 to be indicate it is not known. If a positive length is given, data MUST provide at least that many bytes: if not, an exception will be thrown. Note that implementations need not support cases where length is not known in advance; this depends on underlying data format: JSON output does NOT require length, other formats may.
dataLength
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.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.
public void
writeBoolean(boolean
Boolean value to write
state
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeBoolean.

Method for outputting literal JSON boolean value (one of Strings 'true' and 'false').
public void
writeEmbeddedObject(Object
Native format-specific value to write
object
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeEmbeddedObject.

Method that can be called on backends that support passing opaque native values that some data formats support; not used with JSON backend, more common with binary formats.
public final void
writeEndArray()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeEndArray.

Method for writing closing marker of a JSON Array value (character ']'; plus possible white space decoration if pretty-printing is enabled).
public final void
writeEndObject()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeEndObject.

Method for writing closing marker of an Object value (character '}'; plus possible white space decoration if pretty-printing is enabled).
public final void
writeFieldName(String
Field name to write
name
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeFieldName.

Method for writing a field name (JSON String surrounded by double quotes: syntactically identical to a JSON String value), possibly decorated by white space if pretty-printing is enabled.
public void
writeFieldName(SerializableString
Field name to write
name
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeFieldName.

Method similar to writeFieldName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.
private void
writeLazyDecimal(Object encodedValue)

private void
writeLazyInteger(Object encodedValue)

public void
writeNull()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNull.

Method for outputting literal JSON null value.
public void
writeNumber(short
Number value to write
i
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.
public void
writeNumber(int
Number value to write
i
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.
public void
writeNumber(long
Number value to write
l
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.
public void
writeNumber(double
Number value to write
d
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.
public void
writeNumber(float
Number value to write
f
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.
public void
writeNumber(BigDecimal
Number value to write
dec
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.
public void
writeNumber(BigInteger
Number value to write
v
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.
public void
writeNumber(String
Textual (possibly format) number representation to write
encodedValue
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Write method that can be used for custom numeric types that can not be (easily?) converted to "standard" Java number types.
public void
writeObject(Object
Java value (usually POJO) to write
value
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeObject.

Older alias for writePOJO(Object)
public void
writeObjectId(Object
Native Object Id to write
id
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeObjectId.

Method that can be called to output so-called native Object Id. Note that it may only be called after ensuring this is legal (with canWriteObjectId()), as not all data formats have native type id support; and some may only allow them in certain positions or locations.
public void
writeRaw(String
Textual contents to include as-is in output.
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
public void
writeRaw(String
String that has contents to include as-is in output
text
,
int
Offset within text of the first character to output
offset
,
int
Length of content (from text, starting at offset offset) to output
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
public void
writeRaw(SerializableString
Pre-encoded textual contents to included in output
text
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
public void
writeRaw(char[]
Buffer that has contents to include as-is in output
text
,
int
Offset within text of the first character to output
offset
,
int
Length of content (from text, starting at offset offset) to output
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
public void
writeRaw(char
Character to included in output
c
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).
public void
writeRawUTF8String(byte[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first byte of String value to write
offset
,
int
Length of the String value (in characters) to write
length
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRawUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String that is to be output as-is, without additional escaping (type of which depends on data format; backslashes for JSON).
public void
writeRawValue(String
Textual contents to included in output
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRawValue.

Method that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List).
public void
writeRawValue(String text, int offset, int len)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRawValue.

public void
writeRawValue(char[] text, int offset, int len)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRawValue.

public final void
writeStartArray()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeStartArray.

Method for writing starting marker of a Array value (for JSON this is character '['; plus possible white space decoration if pretty-printing is enabled).
public void
writeStartArray(Object
"Current value" to assign for the Array context being created
forValue
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeStartArray.

Method for writing start marker of an Array value, similar to writeStartArray(), but also specifying the "current value" to assign to the new Array context being created.
public void
writeStartArray(Object
"Current value" to assign for the Array context being created
forValue
,
int
Number of elements this Array will have: actual number of values written (before matching call to writeEndArray() MUST match; generator MAY verify this is the case (and SHOULD if format itself encodes length)
size
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeStartArray.

Method for writing start marker of an Array value, similar to writeStartArray(), but also specifying the "current value" to assign to the new Array context being created as well as how many elements will be written for the array before calling writeEndArray().
public final void
writeStartObject()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).
public void
writeStartObject(Object
"Current value" to assign for the Object context being created
forValue
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value to represent the given Java Object value.
public void
writeStartObject(Object
"Current value" to assign for the Object context being created
forValue
,
int
Number of key/value pairs this Object will have: actual number of entries written (before matching call to writeEndObject() MUST match; generator MAY verify this is the case (and SHOULD if format itself encodes length)
size
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value to represent the given Java Object value.
public void
writeString(String
Text value to write
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.
public void
writeString(char[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first character of String value to write
offset
,
int
Length of the String value (in characters) to write
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.
public void
writeString(SerializableString
Pre-encoded String value to write
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeString.

Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.
public void
writeString(Reader
Reader to use for reading Text value to write
reader
,
final int
Maximum Length of Text value to read (in chars, non-negative) if known; -1 to indicate "read and write it all"
len
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.
public void
writeTree(TreeNode
TreeNode to write
node
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeTree.

Method for writing given JSON tree (expressed as a tree where given JsonNode is the root) using this generator.
public void
writeTypeId(Object
Native Type Id to write
id
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeTypeId.

Method that can be called to output so-called native Type Id. Note that it may only be called after ensuring this is legal (with canWriteTypeId()), as not all data formats have native type id support; and some may only allow them in certain positions or locations.
public void
writeUTF8String(byte[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first byte of String value to write
offset
,
int
Length of the String value (in characters) to write
length
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String which has not been escaped using whatever escaping scheme data format requires (for JSON that is backslash-escaping for control characters and double-quotes; for other formats something else).
Inherited from com.fasterxml.jackson.core.JsonGenerator:
_copyCurrentContents_copyCurrentFloatValue_copyCurrentFloatValueExact_copyCurrentIntValue_copyCurrentStringValue_reportError_throwInternal_verifyOffsets_writeSimpleObjectassignCurrentValuecanOmitFieldscanUseSchemacanWriteFormattedNumbersconfigurecopyCurrentEventExactcurrentValuegetCharacterEscapesgetCurrentValuegetFormatFeaturesgetHighestEscapedChargetOutputBufferedgetOutputTargetgetPrettyPrintergetSchemaisEnabledoverrideFormatFeaturessetCharacterEscapessetCurrentValuesetHighestNonEscapedCharsetPrettyPrintersetRootValueSeparatorsetSchemastreamWriteConstraintswriteArraywriteArraywriteArraywriteArraywriteArrayFieldStartwriteBinarywriteBinarywriteBinarywriteBinaryFieldwriteBooleanFieldwriteFieldIdwriteNullFieldwriteNumberwriteNumberFieldwriteNumberFieldwriteNumberFieldwriteNumberFieldwriteNumberFieldwriteNumberFieldwriteNumberFieldwriteObjectFieldwriteObjectFieldStartwriteObjectRefwriteOmittedFieldwritePOJOwritePOJOFieldwriteRawValuewriteStartArraywriteStringFieldwriteTypePrefixwriteTypeSuffix