Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.fasterxml.jackson.databind.util
Class TokenBuffer

    java.lang.Object
      com.fasterxml.jackson.core.JsonGenerator
          com.fasterxml.jackson.databind.util.TokenBuffer

All Implemented Interfaces:
  Versioned, Closeable, Flushable

    public class TokenBuffer

extends JsonGenerator

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.

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

Nested Class Summary
`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).

Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonGenerator
`JsonGenerator.Feature`

Field Summary
`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.Feature`s 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`

Fields inherited from class com.fasterxml.jackson.core.JsonGenerator
`_cfgPrettyPrinter`

Constructor Summary
`TokenBuffer(ObjectCodec codec)`

Method Summary
`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)`
`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(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)`

Methods inherited from class com.fasterxml.jackson.core.JsonGenerator
`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, writeStringField`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### DEFAULT_PARSER_FEATURES

    protected static final int DEFAULT_PARSER_FEATURES

### _objectCodec

    protected ObjectCodec _objectCodec

  Object codec to use for stream-based object conversion through parser/generator interfaces. If null, such methods can not be used.

### _generatorFeatures

    protected int _generatorFeatures

  Bit flag composed of bits that indicate which `JsonGenerator.Feature`s are enabled.

  NOTE: most features have no effect on this class

### _closed

    protected boolean _closed

### _first

    protected TokenBuffer.Segment _first

  First segment, for contents this buffer has

### _last

    protected TokenBuffer.Segment _last

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

### _appendOffset

    protected int _appendOffset

  Offset within last segment,

### _writeContext

    protected JsonWriteContext _writeContext

Constructor Detail

### TokenBuffer

    public TokenBuffer(ObjectCodec codec)

Parameters:
  `codec` - Object codec to use for stream-based object conversion through parser/generator interfaces. If null, such methods can not be used.

Method Detail

### version

    public Version version()

  Specified by:
    `version` in interface `Versioned`
  Specified by:
    `version` in class `JsonGenerator`

### asParser

    public JsonParser asParser()

  Method used to create a `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.

  Returns:
    Parser that can be used for reading contents stored in this buffer

### asParser

    public JsonParser asParser(ObjectCodec codec)

  Method used to create a `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.

  Parameters:
    `codec` - Object codec to use for stream-based object conversion through parser/generator interfaces. If null, such methods can not be used.
  Returns:
    Parser that can be used for reading contents stored in this buffer

### asParser

    public JsonParser asParser(JsonParser src)

  Parameters:
    `src` - Parser to use for accessing source information like location, configured codec

### append

    public TokenBuffer append(TokenBuffer other)
                       throws IOException,
                              JsonGenerationException

  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
  Throws:
    `IOException`
    `JsonGenerationException`

### serialize

    public void serialize(JsonGenerator jgen)
                   throws IOException,
                          JsonGenerationException

  Helper method that will write all contents of this buffer using given `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.

  Throws:
    `IOException`
    `JsonGenerationException`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### enable

    public JsonGenerator enable(JsonGenerator.Feature f)

  Specified by:
    `enable` in class `JsonGenerator`

### disable

    public JsonGenerator disable(JsonGenerator.Feature f)

  Specified by:
    `disable` in class `JsonGenerator`

### isEnabled

    public boolean isEnabled(JsonGenerator.Feature f)

  Specified by:
    `isEnabled` in class `JsonGenerator`

### useDefaultPrettyPrinter

    public JsonGenerator useDefaultPrettyPrinter()

  Specified by:
    `useDefaultPrettyPrinter` in class `JsonGenerator`

### setCodec

    public JsonGenerator setCodec(ObjectCodec oc)

  Specified by:
    `setCodec` in class `JsonGenerator`

### getCodec

    public ObjectCodec getCodec()

  Specified by:
    `getCodec` in class `JsonGenerator`

### getOutputContext

    public final JsonWriteContext getOutputContext()

  Specified by:
    `getOutputContext` in class `JsonGenerator`

### flush

    public void flush()
               throws IOException

  Specified by:
    `flush` in interface `Flushable`
  Specified by:
    `flush` in class `JsonGenerator`
  Throws:
    `IOException`

### close

    public void close()
               throws IOException

  Specified by:
    `close` in interface `Closeable`
  Specified by:
    `close` in class `JsonGenerator`
  Throws:
    `IOException`

### isClosed

    public boolean isClosed()

  Specified by:
    `isClosed` in class `JsonGenerator`

### writeStartArray

    public final void writeStartArray()
                               throws IOException,
                                      JsonGenerationException

  Specified by:
    `writeStartArray` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeEndArray

    public final void writeEndArray()
                             throws IOException,
                                    JsonGenerationException

  Specified by:
    `writeEndArray` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeStartObject

    public final void writeStartObject()
                                throws IOException,
                                       JsonGenerationException

  Specified by:
    `writeStartObject` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeEndObject

    public final void writeEndObject()
                              throws IOException,
                                     JsonGenerationException

  Specified by:
    `writeEndObject` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeFieldName

    public final void writeFieldName(String name)
                              throws IOException,
                                     JsonGenerationException

  Specified by:
    `writeFieldName` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeFieldName

    public void writeFieldName(SerializableString name)
                        throws IOException,
                               JsonGenerationException

  Specified by:
    `writeFieldName` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeString

    public void writeString(String text)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeString` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeString

    public void writeString(char[] text,
                            int offset,
                            int len)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeString` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeString

    public void writeString(SerializableString text)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeString` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRawUTF8String

    public void writeRawUTF8String(byte[] text,
                                   int offset,
                                   int length)
                            throws IOException,
                                   JsonGenerationException

  Specified by:
    `writeRawUTF8String` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeUTF8String

    public void writeUTF8String(byte[] text,
                                int offset,
                                int length)
                         throws IOException,
                                JsonGenerationException

  Specified by:
    `writeUTF8String` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRaw

    public void writeRaw(String text)
                  throws IOException,
                         JsonGenerationException

  Specified by:
    `writeRaw` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRaw

    public void writeRaw(String text,
                         int offset,
                         int len)
                  throws IOException,
                         JsonGenerationException

  Specified by:
    `writeRaw` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRaw

    public void writeRaw(SerializableString text)
                  throws IOException,
                         JsonGenerationException

  Overrides:
    `writeRaw` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRaw

    public void writeRaw(char[] text,
                         int offset,
                         int len)
                  throws IOException,
                         JsonGenerationException

  Specified by:
    `writeRaw` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRaw

    public void writeRaw(char c)
                  throws IOException,
                         JsonGenerationException

  Specified by:
    `writeRaw` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRawValue

    public void writeRawValue(String text)
                       throws IOException,
                              JsonGenerationException

  Specified by:
    `writeRawValue` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRawValue

    public void writeRawValue(String text,
                              int offset,
                              int len)
                       throws IOException,
                              JsonGenerationException

  Specified by:
    `writeRawValue` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeRawValue

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

  Specified by:
    `writeRawValue` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(int i)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(long l)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(double d)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(float f)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(BigDecimal dec)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(BigInteger v)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNumber

    public void writeNumber(String encodedValue)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeNumber` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeBoolean

    public void writeBoolean(boolean state)
                      throws IOException,
                             JsonGenerationException

  Specified by:
    `writeBoolean` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeNull

    public void writeNull()
                   throws IOException,
                          JsonGenerationException

  Specified by:
    `writeNull` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeObject

    public void writeObject(Object value)
                     throws IOException,
                            JsonProcessingException

  Specified by:
    `writeObject` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonProcessingException`

### writeTree

    public void writeTree(TreeNode rootNode)
                   throws IOException,
                          JsonProcessingException

  Specified by:
    `writeTree` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonProcessingException`

### writeBinary

    public void writeBinary(Base64Variant b64variant,
                            byte[] data,
                            int offset,
                            int len)
                     throws IOException,
                            JsonGenerationException

  Specified by:
    `writeBinary` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonGenerationException`

### writeBinary

    public 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. Because of this, currently this will simply throw `UnsupportedOperationException`

  Specified by:
    `writeBinary` in class `JsonGenerator`

### copyCurrentEvent

    public void copyCurrentEvent(JsonParser jp)
                          throws IOException,
                                 JsonProcessingException

  Specified by:
    `copyCurrentEvent` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonProcessingException`

### copyCurrentStructure

    public void copyCurrentStructure(JsonParser jp)
                              throws IOException,
                                     JsonProcessingException

  Specified by:
    `copyCurrentStructure` in class `JsonGenerator`
  Throws:
    `IOException`
    `JsonProcessingException`

### _append

    protected final void _append(JsonToken type)

### _append

    protected final void _append(JsonToken type,
                                 Object value)

### _appendRaw

    protected final void _appendRaw(int rawType,
                                    Object value)

### _reportUnsupportedOperation

    protected void _reportUnsupportedOperation()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2012 FasterXML. All Rights Reserved.