Class BsonParser

java.lang.Object
tools.jackson.core.JsonParser
tools.jackson.core.base.ParserMinimalBase
tools.jackson.core.base.ParserBase
de.undercouch.bson4jackson.BsonParser
All Implemented Interfaces:
Closeable, AutoCloseable, tools.jackson.core.Versioned

public class BsonParser extends tools.jackson.core.base.ParserBase
Reads a BSON document from the provided input stream
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
     
    protected static class 
    Information about the element currently begin parsed
    static enum 
    Defines toggable features
    protected static enum 
    Specifies what the parser is currently parsing (field name or value) or if it is done with the current element

    Nested classes/interfaces inherited from class tools.jackson.core.JsonParser

    tools.jackson.core.JsonParser.NumberType, tools.jackson.core.JsonParser.NumberTypeFP
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The features for this parser
    Counts the number of bytes read from _in
    The current parser state
    The input stream to read from
    protected InputStream
    The raw input stream passed in
    protected tools.jackson.core.json.JsonReadContext
    The Jackson read context for tracking parsing state
    protected int
    The position of the current token

    Fields inherited from class tools.jackson.core.base.ParserBase

    _binaryValue, _byteArrayBuilder, _currInputProcessed, _currInputRow, _currInputRowStart, _expLength, _fractLength, _inputEnd, _inputPtr, _intLength, _numberBigDecimal, _numberBigInt, _numberDouble, _numberFloat, _numberInt, _numberIsNaN, _numberLong, _numberNegative, _numberString, _numTypesValid, _textBuffer, _tokenInputCol, _tokenInputRow, _tokenInputTotal

    Fields inherited from class tools.jackson.core.base.ParserMinimalBase

    _closed, _currToken, _ioContext, _lastClearedToken, _objectReadContext, _streamReadConstraints, _streamReadFeatures, _tokenCount, _trackMaxTokenCount, BD_MAX_INT, BD_MAX_LONG, BD_MIN_INT, BD_MIN_LONG, BI_MAX_INT, BI_MAX_LONG, BI_MIN_INT, BI_MIN_LONG, CHAR_NULL, INT_0, INT_9, INT_APOS, INT_ASTERISK, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_e, INT_E, INT_HASH, INT_LBRACKET, INT_LCURLY, INT_LF, INT_MINUS, INT_PERIOD, INT_PLUS, INT_QUOTE, INT_RBRACKET, INT_RCURLY, INT_RS, INT_SLASH, INT_SPACE, INT_TAB, MAX_BYTE_I, MAX_INT_D, MAX_INT_L, MAX_LONG_D, MAX_SHORT_I, MIN_BYTE_I, MIN_INT_D, MIN_INT_L, MIN_LONG_D, MIN_SHORT_I, NO_BYTES, NO_INTS, NR_BIGDECIMAL, NR_BIGINT, NR_DOUBLE, NR_FLOAT, NR_INT, NR_LONG, NR_UNKNOWN, STREAM_READ_FEATURE_DEFAULTS

    Fields inherited from class tools.jackson.core.JsonParser

    DEFAULT_READ_CAPABILITIES
  • Constructor Summary

    Constructors
    Constructor
    Description
    BsonParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ctxt, int jsonFeatures, int bsonFeatures, InputStream in)
    Constructs a new parser
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
     
    protected int
     
    protected void
    _parseNumericValue(int expType)
     
    void
     
    tools.jackson.core.TokenStreamLocation
     
     
    tools.jackson.core.TokenStreamLocation
     
     
    byte[]
    getBinaryValue(tools.jackson.core.Base64Variant b64variant)
     
     
    byte
     
     
    double
     
     
    float
     
    int
     
    long
     
    tools.jackson.core.JsonParser.NumberType
     
     
     
     
     
    char[]
     
    int
     
    int
     
    protected tools.jackson.core.JsonToken
    Reads binary data from the input stream
    protected tools.jackson.core.JsonToken
    Reads a DBPointer from the stream
    protected tools.jackson.core.JsonToken
    Can be called when embedded javascript code with scope is found.
    protected tools.jackson.core.JsonToken
    handleNewDocument(boolean array)
    Can be called when a new embedded document is found.
    protected tools.jackson.core.JsonToken
    Reads and compiles a regular expression
    boolean
     
    protected boolean
    Checks if a generator feature is enabled
    boolean
     
    tools.jackson.core.JsonToken
     
    protected String
     
    protected Map<String,Object>
    Fully reads an embedded document, reusing this parser
    protected ObjectId
    Reads a ObjectID from the input stream
    protected String
    Reads a string that consists of a integer denoting the number of bytes, the bytes (including a terminating 0 byte)
    protected Symbol
    Reads a symbol object from the input stream
    protected Timestamp
    Reads a timestamp object from the input stream
    protected int
    Converts a BSON regex pattern string to a combined value of Java flags that can be used in Pattern.compile(String, int)
    protected void
    Skips over a null-terminated string in the input stream
    tools.jackson.core.TokenStreamContext
     
     
    tools.jackson.core.Version
     

    Methods inherited from class tools.jackson.core.base.ParserBase

    _contentReference, _contentReferenceRedacted, _convertBigDecimalToBigInteger, _decodeBase64Escape, _decodeBase64Escape, _decodeEscaped, _eofAsNextChar, _getBigDecimal, _getBigInteger, _getByteArrayBuilder, _getNumberDouble, _getNumberFloat, _growNameDecodeBuffer, _handleBase64MissingPadding, _releaseBuffers, _reportInvalidBase64Char, _reportInvalidBase64Char, assignCurrentValue, convertNumberToBigDecimal, convertNumberToBigInteger, convertNumberToDouble, convertNumberToFloat, convertNumberToInt, convertNumberToLong, currentValue, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, growArrayBy, isNaN, reset, resetAsNaN, resetFloat, resetInt

    Methods inherited from class tools.jackson.core.base.ParserMinimalBase

    _constructInputCoercion, _constructNotNumericType, _currentLocationMinusOne, _decodeBase64, _getCharDesc, _hasTextualNull, _longIntegerDesc, _longNumberDesc, _nullSafeUpdateToken, _reportBadInputStream, _reportBadReader, _reportError, _reportError, _reportError, _reportError, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportInvalidNumber, _reportInvalidSpace, _reportInvalidUTF8Surrogate, _reportMissingRootWS, _reportOverflowByte, _reportOverflowInt, _reportOverflowInt, _reportOverflowInt, _reportOverflowLong, _reportOverflowLong, _reportOverflowLong, _reportOverflowShort, _reportUnexpectedChar, _reportUnexpectedNumberChar, _throwInternal, _updateToken, _updateTokenToNA, _updateTokenToNull, _wrapIOFailure, clearCurrentToken, currentNameMatch, currentToken, currentTokenCount, currentTokenId, finishToken, getBooleanValue, getByteValue, getLastClearedToken, getNumberTypeFP, getShortValue, getString, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsInt, getValueAsLong, getValueAsLong, getValueAsString, getValueAsString, hasCurrentToken, hasToken, hasTokenId, isClosed, isEnabled, isExpectedNumberIntToken, isExpectedStartObjectToken, nextName, nextName, nextNameMatch, nextValue, objectReadContext, readValueAs, readValueAs, readValueAs, readValueAsTree, skipChildren, streamReadCapabilities, streamReadConstraints, streamReadFeatures

    Methods inherited from class tools.jackson.core.JsonParser

    _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _constructReadException, _reportUnsupportedOperation, canParseAsync, canReadObjectId, canReadTypeId, getBinaryValue, getObjectId, getSchema, getText, getTextCharacters, getTextLength, getTextOffset, getTypeId, getValueAsBoolean, getValueAsDouble, nextBooleanValue, nextIntValue, nextLongValue, nextStringValue, nonBlockingInputFeeder, readBinaryValue, readBinaryValue, readString, releaseBuffered, releaseBuffered

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _bsonFeatures

      protected int _bsonFeatures
      The features for this parser
    • _in

      protected LittleEndianInputStream _in
      The input stream to read from
    • _counter

      protected CountingInputStream _counter
      Counts the number of bytes read from _in
    • _rawInputStream

      protected InputStream _rawInputStream
      The raw input stream passed in
    • _tokenPos

      protected int _tokenPos
      The position of the current token
    • _streamReadContext

      protected tools.jackson.core.json.JsonReadContext _streamReadContext
      The Jackson read context for tracking parsing state
    • _currentContext

      protected BsonParser.Context _currentContext
      The current parser state
  • Constructor Details

    • BsonParser

      public BsonParser(tools.jackson.core.ObjectReadContext readCtxt, tools.jackson.core.io.IOContext ctxt, int jsonFeatures, int bsonFeatures, InputStream in)
      Constructs a new parser
      Parameters:
      readCtxt - the object read context
      ctxt - the Jackson IO context
      jsonFeatures - bit flag composed of bits that indicate which StreamReadFeatures are enabled.
      bsonFeatures - bit flag composed of bits that indicate which BsonParser.Features are enabled.
      in - the input stream to parse.
  • Method Details

    • isEnabled

      protected boolean isEnabled(BsonParser.Feature f)
      Checks if a generator feature is enabled
      Parameters:
      f - the feature
      Returns:
      true if the given feature is enabled
    • isExpectedStartArrayToken

      public boolean isExpectedStartArrayToken()
      Overrides:
      isExpectedStartArrayToken in class tools.jackson.core.base.ParserMinimalBase
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class tools.jackson.core.base.ParserBase
    • nextToken

      public tools.jackson.core.JsonToken nextToken()
      Specified by:
      nextToken in class tools.jackson.core.JsonParser
    • handleNewDocument

      protected tools.jackson.core.JsonToken handleNewDocument(boolean array) throws IOException
      Can be called when a new embedded document is found. Reads the document's header and creates a new context on the stack.
      Parameters:
      array - true if the document is an embedded array
      Returns:
      the json token read
      Throws:
      IOException - if an I/O error occurs
    • handleBinary

      protected tools.jackson.core.JsonToken handleBinary() throws IOException
      Reads binary data from the input stream
      Returns:
      the json token read
      Throws:
      IOException - if an I/O error occurs
    • regexStrToFlags

      protected int regexStrToFlags(String pattern) throws tools.jackson.core.exc.StreamReadException
      Converts a BSON regex pattern string to a combined value of Java flags that can be used in Pattern.compile(String, int)
      Parameters:
      pattern - the regex pattern string
      Returns:
      the Java flags
      Throws:
      tools.jackson.core.exc.StreamReadException - if the pattern string contains a unsupported flag
    • handleRegEx

      protected tools.jackson.core.JsonToken handleRegEx() throws IOException
      Reads and compiles a regular expression
      Returns:
      the json token read
      Throws:
      IOException - if an I/O error occurs
    • handleDBPointer

      protected tools.jackson.core.JsonToken handleDBPointer() throws IOException
      Reads a DBPointer from the stream
      Returns:
      the json token read
      Throws:
      IOException - if an I/O error occurs
    • handleJavascriptWithScope

      protected tools.jackson.core.JsonToken handleJavascriptWithScope() throws IOException
      Can be called when embedded javascript code with scope is found. Reads the code and the embedded document.
      Returns:
      the json token read
      Throws:
      IOException - if an I/O error occurs
    • readCString

      protected String readCString() throws IOException
      Returns:
      a null-terminated string read from the input stream
      Throws:
      IOException - if the string could not be read
    • skipCString

      protected void skipCString() throws IOException
      Skips over a null-terminated string in the input stream
      Throws:
      IOException - if an I/O error occurs
    • readString

      protected String readString() throws IOException
      Reads a string that consists of a integer denoting the number of bytes, the bytes (including a terminating 0 byte)
      Returns:
      the string
      Throws:
      IOException - if the string could not be read
    • readSymbol

      protected Symbol readSymbol() throws IOException
      Reads a symbol object from the input stream
      Returns:
      the symbol
      Throws:
      IOException - if the symbol could not be read
    • readTimestamp

      protected Timestamp readTimestamp() throws IOException
      Reads a timestamp object from the input stream
      Returns:
      the timestamp
      Throws:
      IOException - if the timestamp could not be read
    • readObjectId

      protected ObjectId readObjectId() throws IOException
      Reads a ObjectID from the input stream
      Returns:
      the ObjectID
      Throws:
      IOException - if the ObjectID could not be read
    • readDocument

      protected Map<String,Object> readDocument() throws IOException
      Fully reads an embedded document, reusing this parser
      Returns:
      the parsed document
      Throws:
      IOException - if the document could not be read
    • getContext

      protected BsonParser.Context getContext()
      Returns:
      the context of the current element
      Throws:
      IllegalStateException - if there is no context
    • currentName

      public String currentName()
      Specified by:
      currentName in class tools.jackson.core.JsonParser
    • getCurrentBsonType

      public byte getCurrentBsonType()
      Returns:
      the BSON type of the current element
    • currentTokenLocation

      public tools.jackson.core.TokenStreamLocation currentTokenLocation()
      Specified by:
      currentTokenLocation in class tools.jackson.core.JsonParser
    • currentLocation

      public tools.jackson.core.TokenStreamLocation currentLocation()
      Specified by:
      currentLocation in class tools.jackson.core.JsonParser
    • getString

      public String getString()
      Specified by:
      getString in class tools.jackson.core.JsonParser
    • getStringCharacters

      public char[] getStringCharacters()
      Specified by:
      getStringCharacters in class tools.jackson.core.JsonParser
    • getStringLength

      public int getStringLength()
      Specified by:
      getStringLength in class tools.jackson.core.JsonParser
    • getStringOffset

      public int getStringOffset()
      Specified by:
      getStringOffset in class tools.jackson.core.JsonParser
    • hasStringCharacters

      public boolean hasStringCharacters()
      Overrides:
      hasStringCharacters in class tools.jackson.core.base.ParserBase
    • getNumberValue

      public Number getNumberValue()
      Overrides:
      getNumberValue in class tools.jackson.core.base.ParserBase
    • getNumberValueExact

      public Number getNumberValueExact()
      Overrides:
      getNumberValueExact in class tools.jackson.core.base.ParserBase
    • getNumberValueDeferred

      public Object getNumberValueDeferred()
      Overrides:
      getNumberValueDeferred in class tools.jackson.core.base.ParserBase
    • getNumberType

      public tools.jackson.core.JsonParser.NumberType getNumberType()
      Overrides:
      getNumberType in class tools.jackson.core.base.ParserBase
    • getIntValue

      public int getIntValue()
      Overrides:
      getIntValue in class tools.jackson.core.base.ParserBase
    • getLongValue

      public long getLongValue()
      Overrides:
      getLongValue in class tools.jackson.core.base.ParserBase
    • getBigIntegerValue

      public BigInteger getBigIntegerValue()
      Overrides:
      getBigIntegerValue in class tools.jackson.core.base.ParserBase
    • getFloatValue

      public float getFloatValue()
      Overrides:
      getFloatValue in class tools.jackson.core.base.ParserBase
    • getDoubleValue

      public double getDoubleValue()
      Overrides:
      getDoubleValue in class tools.jackson.core.base.ParserBase
    • getDecimalValue

      public BigDecimal getDecimalValue()
      Overrides:
      getDecimalValue in class tools.jackson.core.base.ParserBase
    • getBinaryValue

      public byte[] getBinaryValue(tools.jackson.core.Base64Variant b64variant)
      Overrides:
      getBinaryValue in class tools.jackson.core.base.ParserBase
    • getEmbeddedObject

      public Object getEmbeddedObject()
      Overrides:
      getEmbeddedObject in class tools.jackson.core.base.ParserMinimalBase
    • _handleEOF

      protected void _handleEOF() throws tools.jackson.core.exc.StreamReadException
      Overrides:
      _handleEOF in class tools.jackson.core.base.ParserBase
      Throws:
      tools.jackson.core.exc.StreamReadException
    • streamReadContext

      public tools.jackson.core.TokenStreamContext streamReadContext()
      Specified by:
      streamReadContext in class tools.jackson.core.JsonParser
    • streamReadInputSource

      public Object streamReadInputSource()
      Specified by:
      streamReadInputSource in class tools.jackson.core.JsonParser
    • version

      public tools.jackson.core.Version version()
      Specified by:
      version in interface tools.jackson.core.Versioned
      Specified by:
      version in class tools.jackson.core.JsonParser
    • _closeInput

      protected void _closeInput() throws IOException
      Specified by:
      _closeInput in class tools.jackson.core.base.ParserMinimalBase
      Throws:
      IOException
    • _parseIntValue

      protected int _parseIntValue()
      Specified by:
      _parseIntValue in class tools.jackson.core.base.ParserBase
    • _parseNumericValue

      protected void _parseNumericValue(int expType)
      Specified by:
      _parseNumericValue in class tools.jackson.core.base.ParserBase