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 |
_appendOffset
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.Features
are enabled. |
protected TokenBuffer.Segment |
_last
Last segment of this buffer, one that is used
for appending more tokens
|
protected ObjectCodec |
_objectCodec
Object codec to use for stream-based object
conversion through parser/generator interfaces.
|
protected JsonWriteContext |
_writeContext |
protected static int |
DEFAULT_PARSER_FEATURES |
_cfgPrettyPrinter| Constructor and Description |
|---|
TokenBuffer(ObjectCodec codec) |
| 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. |
void |
close() |
void |
copyCurrentEvent(JsonParser jp) |
void |
copyCurrentStructure(JsonParser jp) |
JsonGenerator |
disable(JsonGenerator.Feature f) |
JsonGenerator |
enable(JsonGenerator.Feature f) |
JsonToken |
firstToken() |
void |
flush() |
ObjectCodec |
getCodec() |
JsonWriteContext |
getOutputContext() |
boolean |
isClosed() |
boolean |
isEnabled(JsonGenerator.Feature f) |
void |
serialize(JsonGenerator jgen)
Helper method that will write all contents of this buffer
using given
JsonGenerator. |
JsonGenerator |
setCodec(ObjectCodec oc) |
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 |
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 rootNode) |
void |
writeUTF8String(byte[] text,
int offset,
int length) |
canUseSchema, configure, getCharacterEscapes, getHighestEscapedChar, getOutputTarget, getPrettyPrinter, getSchema, setCharacterEscapes, setHighestNonEscapedChar, setPrettyPrinter, setRootValueSeparator, setSchema, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeNullField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeStringFieldprotected static final int DEFAULT_PARSER_FEATURES
protected ObjectCodec _objectCodec
protected int _generatorFeatures
JsonGenerator.Features
are enabled.
NOTE: most features have no effect on this class
protected boolean _closed
protected TokenBuffer.Segment _first
protected TokenBuffer.Segment _last
protected int _appendOffset
protected JsonWriteContext _writeContext
public TokenBuffer(ObjectCodec codec)
codec - Object codec to use for stream-based object
conversion through parser/generator interfaces. If null,
such methods can not be used.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 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, JsonGenerationException
IOExceptionJsonGenerationExceptionpublic void serialize(JsonGenerator jgen) throws IOException, JsonGenerationException
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.
IOExceptionJsonGenerationExceptionpublic 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 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 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,
JsonGenerationException
writeStartArray in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic final void writeEndArray()
throws IOException,
JsonGenerationException
writeEndArray in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic final void writeStartObject()
throws IOException,
JsonGenerationException
writeStartObject in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic final void writeEndObject()
throws IOException,
JsonGenerationException
writeEndObject in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic final void writeFieldName(String name) throws IOException, JsonGenerationException
writeFieldName in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeFieldName(SerializableString name) throws IOException, JsonGenerationException
writeFieldName in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeString(String text) throws IOException, JsonGenerationException
writeString in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeString(char[] text,
int offset,
int len)
throws IOException,
JsonGenerationException
writeString in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeString(SerializableString text) throws IOException, JsonGenerationException
writeString in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRawUTF8String(byte[] text,
int offset,
int length)
throws IOException,
JsonGenerationException
writeRawUTF8String in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeUTF8String(byte[] text,
int offset,
int length)
throws IOException,
JsonGenerationException
writeUTF8String in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRaw(String text) throws IOException, JsonGenerationException
writeRaw in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRaw(String text, int offset, int len) throws IOException, JsonGenerationException
writeRaw in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRaw(SerializableString text) throws IOException, JsonGenerationException
writeRaw in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRaw(char[] text,
int offset,
int len)
throws IOException,
JsonGenerationException
writeRaw in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRaw(char c)
throws IOException,
JsonGenerationException
writeRaw in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRawValue(String text) throws IOException, JsonGenerationException
writeRawValue in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRawValue(String text, int offset, int len) throws IOException, JsonGenerationException
writeRawValue in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeRawValue(char[] text,
int offset,
int len)
throws IOException,
JsonGenerationException
writeRawValue in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(short i)
throws IOException,
JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(int i)
throws IOException,
JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(long l)
throws IOException,
JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(double d)
throws IOException,
JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(float f)
throws IOException,
JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(BigDecimal dec) throws IOException, JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(BigInteger v) throws IOException, JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNumber(String encodedValue) throws IOException, JsonGenerationException
writeNumber in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeBoolean(boolean state)
throws IOException,
JsonGenerationException
writeBoolean in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeNull()
throws IOException,
JsonGenerationException
writeNull in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic void writeObject(Object value) throws IOException, JsonProcessingException
writeObject in class JsonGeneratorIOExceptionJsonProcessingExceptionpublic void writeTree(TreeNode rootNode) throws IOException, JsonProcessingException
writeTree in class JsonGeneratorIOExceptionJsonProcessingExceptionpublic void writeBinary(Base64Variant b64variant, byte[] data, int offset, int len) throws IOException, JsonGenerationException
writeBinary in class JsonGeneratorIOExceptionJsonGenerationExceptionpublic int writeBinary(Base64Variant b64variant, InputStream data, int dataLength)
UnsupportedOperationExceptionwriteBinary in class JsonGeneratorpublic void copyCurrentEvent(JsonParser jp) throws IOException, JsonProcessingException
copyCurrentEvent in class JsonGeneratorIOExceptionJsonProcessingExceptionpublic void copyCurrentStructure(JsonParser jp) throws IOException, JsonProcessingException
copyCurrentStructure in class JsonGeneratorIOExceptionJsonProcessingExceptionprotected final void _append(JsonToken type)
protected final void _appendRaw(int rawType,
Object value)
protected void _reportUnsupportedOperation()
Copyright © 2012-2013 FasterXML. All Rights Reserved.