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 int |
_generatorFeatures
Bit flag composed of bits that indicate which
JsonGenerator.Feature s
are enabled. |
protected boolean |
_hasNativeId
Do we currnetly 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 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 jp) |
TokenBuffer(ObjectCodec codec)
Deprecated.
since 2.3 preferred variant is one that takes
JsonParser or additional boolean parameter. |
TokenBuffer(ObjectCodec codec,
boolean hasNativeIds) |
Modifier and Type | Method and Description |
---|---|
protected void |
_append(JsonToken type) |
protected void |
_append(JsonToken type,
Object value) |
protected void |
_appendRaw(int rawType,
Object value) |
protected void |
_reportUnsupportedOperation() |
TokenBuffer |
append(TokenBuffer other)
Helper method that will append contents of given buffer into this
buffer.
|
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. |
boolean |
canWriteBinaryNatively()
Since we can efficiently store
byte[] , yes. |
boolean |
canWriteObjectId() |
boolean |
canWriteTypeId() |
void |
close() |
void |
copyCurrentEvent(JsonParser jp) |
void |
copyCurrentStructure(JsonParser jp) |
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() |
ObjectCodec |
getCodec() |
int |
getFeatureMask() |
JsonWriteContext |
getOutputContext() |
boolean |
isClosed() |
boolean |
isEnabled(JsonGenerator.Feature f) |
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) |
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 can not make good use of streaming because buffer must
hold all the data.
|
void |
writeBoolean(boolean state) |
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 |
writeStartObject() |
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) |
_reportError, _throwInternal, _writeSimpleObject, canOmitFields, canUseSchema, configure, getCharacterEscapes, getCurrentValue, getFormatFeatures, getHighestEscapedChar, getOutputBuffered, getOutputTarget, getPrettyPrinter, getSchema, overrideFormatFeatures, overrideStdFeatures, setCharacterEscapes, setCurrentValue, setHighestNonEscapedChar, setPrettyPrinter, setRootValueSeparator, setSchema, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeNullField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeObjectRef, writeOmittedField, writeRawValue, writeStartArray, writeStringField
protected static final int DEFAULT_GENERATOR_FEATURES
protected ObjectCodec _objectCodec
protected int _generatorFeatures
JsonGenerator.Feature
s
are enabled.
NOTE: most features have no effect on this class
protected boolean _closed
protected boolean _hasNativeTypeIds
protected boolean _hasNativeObjectIds
protected boolean _mayHaveNativeIds
protected TokenBuffer.Segment _first
protected TokenBuffer.Segment _last
protected int _appendAt
protected Object _typeId
protected Object _objectId
protected boolean _hasNativeId
protected JsonWriteContext _writeContext
@Deprecated public TokenBuffer(ObjectCodec codec)
JsonParser
or additional boolean parameter.codec
- Object codec to use for stream-based object
conversion through parser/generator interfaces. If null,
such methods can not be used.public TokenBuffer(ObjectCodec codec, boolean hasNativeIds)
codec
- Object codec to use for stream-based object
conversion through parser/generator interfaces. If null,
such methods can not be used.hasNativeIds
- Whether resulting JsonParser
(if created)
is considered to support native type and object idspublic TokenBuffer(JsonParser jp)
public Version version()
version
in interface Versioned
version
in class JsonGenerator
public 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 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 can not 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
IOException
public void serialize(JsonGenerator gen) throws IOException
JsonGenerator
.
Note: this method would be enough to implement
JsonSerializer
for TokenBuffer
type;
but we can not have upwards
references (from core to mapper package); and as such we also
can not take second argument.
IOException
public TokenBuffer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
IOException
public JsonGenerator enable(JsonGenerator.Feature f)
enable
in class JsonGenerator
public JsonGenerator disable(JsonGenerator.Feature f)
disable
in class JsonGenerator
public boolean isEnabled(JsonGenerator.Feature f)
isEnabled
in class JsonGenerator
public int getFeatureMask()
getFeatureMask
in class JsonGenerator
public JsonGenerator setFeatureMask(int mask)
setFeatureMask
in class JsonGenerator
public JsonGenerator useDefaultPrettyPrinter()
useDefaultPrettyPrinter
in class JsonGenerator
public JsonGenerator setCodec(ObjectCodec oc)
setCodec
in class JsonGenerator
public ObjectCodec getCodec()
getCodec
in class JsonGenerator
public final JsonWriteContext getOutputContext()
getOutputContext
in class JsonGenerator
public boolean canWriteBinaryNatively()
byte[]
, yes.canWriteBinaryNatively
in class JsonGenerator
public void flush() throws IOException
flush
in interface Flushable
flush
in class JsonGenerator
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class JsonGenerator
IOException
public boolean isClosed()
isClosed
in class JsonGenerator
public final void writeStartArray() throws IOException
writeStartArray
in class JsonGenerator
IOException
public final void writeEndArray() throws IOException
writeEndArray
in class JsonGenerator
IOException
public final void writeStartObject() throws IOException
writeStartObject
in class JsonGenerator
IOException
public final void writeEndObject() throws IOException
writeEndObject
in class JsonGenerator
IOException
public final void writeFieldName(String name) throws IOException
writeFieldName
in class JsonGenerator
IOException
public void writeFieldName(SerializableString name) throws IOException
writeFieldName
in class JsonGenerator
IOException
public void writeString(String text) throws IOException
writeString
in class JsonGenerator
IOException
public void writeString(char[] text, int offset, int len) throws IOException
writeString
in class JsonGenerator
IOException
public void writeString(SerializableString text) throws IOException
writeString
in class JsonGenerator
IOException
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
writeRawUTF8String
in class JsonGenerator
IOException
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
writeUTF8String
in class JsonGenerator
IOException
public void writeRaw(String text) throws IOException
writeRaw
in class JsonGenerator
IOException
public void writeRaw(String text, int offset, int len) throws IOException
writeRaw
in class JsonGenerator
IOException
public void writeRaw(SerializableString text) throws IOException
writeRaw
in class JsonGenerator
IOException
public void writeRaw(char[] text, int offset, int len) throws IOException
writeRaw
in class JsonGenerator
IOException
public void writeRaw(char c) throws IOException
writeRaw
in class JsonGenerator
IOException
public void writeRawValue(String text) throws IOException
writeRawValue
in class JsonGenerator
IOException
public void writeRawValue(String text, int offset, int len) throws IOException
writeRawValue
in class JsonGenerator
IOException
public void writeRawValue(char[] text, int offset, int len) throws IOException
writeRawValue
in class JsonGenerator
IOException
public void writeNumber(short i) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(int i) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(long l) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(double d) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(float f) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(BigDecimal dec) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(BigInteger v) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeNumber(String encodedValue) throws IOException
writeNumber
in class JsonGenerator
IOException
public void writeBoolean(boolean state) throws IOException
writeBoolean
in class JsonGenerator
IOException
public void writeNull() throws IOException
writeNull
in class JsonGenerator
IOException
public void writeObject(Object value) throws IOException
writeObject
in class JsonGenerator
IOException
public void writeTree(TreeNode node) throws IOException
writeTree
in class JsonGenerator
IOException
public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException
writeBinary
in class JsonGenerator
IOException
public int writeBinary(Base64Variant b64variant, InputStream data, int dataLength)
UnsupportedOperationException
writeBinary
in class JsonGenerator
public boolean canWriteTypeId()
canWriteTypeId
in class JsonGenerator
public boolean canWriteObjectId()
canWriteObjectId
in class JsonGenerator
public void writeTypeId(Object id)
writeTypeId
in class JsonGenerator
public void writeObjectId(Object id)
writeObjectId
in class JsonGenerator
public void copyCurrentEvent(JsonParser jp) throws IOException
copyCurrentEvent
in class JsonGenerator
IOException
public void copyCurrentStructure(JsonParser jp) throws IOException
copyCurrentStructure
in class JsonGenerator
IOException
protected final void _append(JsonToken type)
protected final void _appendRaw(int rawType, Object value)
protected void _reportUnsupportedOperation()
_reportUnsupportedOperation
in class JsonGenerator
Copyright © 2014–2015 FasterXML. All rights reserved.