de.undercouch.bson4jackson
Class BsonParser

java.lang.Object
  extended by com.fasterxml.jackson.core.JsonParser
      extended by com.fasterxml.jackson.core.base.ParserMinimalBase
          extended by com.fasterxml.jackson.core.base.ParserBase
              extended by de.undercouch.bson4jackson.BsonParser
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, java.io.Closeable

public class BsonParser
extends com.fasterxml.jackson.core.base.ParserBase

Reads a BSON document from the provided input stream


Nested Class Summary
static class BsonParser.Feature
          Defines toggable features
 
Nested classes/interfaces inherited from class com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.core.JsonParser.NumberType
 
Field Summary
 
Fields inherited from class com.fasterxml.jackson.core.base.ParserBase
_binaryValue, _byteArrayBuilder, _currInputProcessed, _currInputRow, _currInputRowStart, _expLength, _fractLength, _inputEnd, _inputPtr, _intLength, _ioContext, _nameCopied, _nameCopyBuffer, _nextToken, _numberBigDecimal, _numberBigInt, _numberDouble, _numberInt, _numberLong, _numberNegative, _numTypesValid, _parsingContext, _textBuffer, _tokenInputCol, _tokenInputRow, _tokenInputTotal, CHAR_NULL, INT_0, INT_1, INT_2, INT_3, INT_4, INT_5, INT_6, INT_7, INT_8, INT_9, INT_DECIMAL_POINT, INT_e, INT_E, INT_MINUS, INT_PLUS, NR_BIGDECIMAL, NR_BIGINT, NR_DOUBLE, NR_INT, NR_LONG, NR_UNKNOWN
 
Fields inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_currToken, _lastClearedToken, INT_APOSTROPHE, INT_ASTERISK, INT_b, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_f, INT_LBRACKET, INT_LCURLY, INT_LF, INT_n, INT_QUOTE, INT_r, INT_RBRACKET, INT_RCURLY, INT_SLASH, INT_SPACE, INT_t, INT_TAB, INT_u
 
Fields inherited from class com.fasterxml.jackson.core.JsonParser
_features
 
Constructor Summary
BsonParser(com.fasterxml.jackson.core.io.IOContext ctxt, int jsonFeatures, int bsonFeatures, java.io.InputStream in)
          Constructs a new parser
 
Method Summary
protected  void _closeInput()
           
protected  void _finishString()
           
protected  void _handleEOF()
           
 void close()
           
 java.math.BigInteger getBigIntegerValue()
           
 byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant b64variant)
           
 com.fasterxml.jackson.core.ObjectCodec getCodec()
           
protected  de.undercouch.bson4jackson.BsonParser.Context getContext()
           
 com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
           
 java.lang.String getCurrentName()
           
 java.math.BigDecimal getDecimalValue()
           
 double getDoubleValue()
           
 java.lang.Object getEmbeddedObject()
           
 float getFloatValue()
           
 int getIntValue()
           
 long getLongValue()
           
 com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
           
 java.lang.Number getNumberValue()
           
 com.fasterxml.jackson.core.json.JsonReadContext getParsingContext()
           
 java.lang.String getText()
           
 char[] getTextCharacters()
           
 int getTextLength()
           
 int getTextOffset()
           
 com.fasterxml.jackson.core.JsonLocation getTokenLocation()
           
protected  com.fasterxml.jackson.core.JsonToken handleBinary()
          Reads binary data from the input stream
protected  com.fasterxml.jackson.core.JsonToken handleDBPointer()
          Reads a DBPointer from the stream
protected  com.fasterxml.jackson.core.JsonToken handleJavascriptWithScope()
          Can be called when embedded javascript code with scope is found.
protected  com.fasterxml.jackson.core.JsonToken handleNewDocument(boolean array)
          Can be called when a new embedded document is found.
protected  com.fasterxml.jackson.core.JsonToken handleRegEx()
          Reads and compiles a regular expression
 boolean hasTextCharacters()
           
 boolean isClosed()
           
protected  boolean isEnabled(BsonParser.Feature f)
          Checks if a generator feature is enabled
protected  boolean loadMore()
           
 com.fasterxml.jackson.core.JsonToken nextToken()
           
protected  java.lang.String readCString()
           
protected  java.util.Map<java.lang.String,java.lang.Object> readDocument()
          Fully reads an embedded document, reusing this parser
protected  ObjectId readObjectId()
          Reads a ObjectID from the input stream
protected  java.lang.String readString()
          Reads a string that consists of a integer denoting the number of bytes, the bytes (including a terminating 0 byte)
protected  Symbol readSymbol()
          Reads a symbol object from the input stream
protected  Timestamp readTimestamp()
          Reads a timestamp object from the input stream
protected  int regexStrToFlags(java.lang.String pattern)
          Converts a BSON regex pattern string to a combined value of Java flags that can be used in Pattern.compile(String, int)
 void setCodec(com.fasterxml.jackson.core.ObjectCodec c)
           
protected  void skipCString()
          Skips over a null-terminated string in the input stream
 
Methods inherited from class com.fasterxml.jackson.core.base.ParserBase
_decodeBase64Escape, _decodeBase64Escape, _decodeEscaped, _getByteArrayBuilder, _parseNumericValue, _releaseBuffers, _reportMismatchedEndMarker, convertNumberToBigDecimal, convertNumberToBigInteger, convertNumberToDouble, convertNumberToInt, convertNumberToLong, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, loadMoreGuaranteed, overrideCurrentName, reportInvalidBase64Char, reportInvalidBase64Char, reportInvalidNumber, reportOverflowInt, reportOverflowLong, reportUnexpectedNumberChar, reset, resetAsNaN, resetFloat, resetInt
 
Methods inherited from class com.fasterxml.jackson.core.base.ParserMinimalBase
_constructError, _decodeBase64, _getCharDesc, _handleUnrecognizedCharacterEscape, _reportBase64EOF, _reportError, _reportInvalidBase64, _reportInvalidEOF, _reportInvalidEOF, _reportInvalidEOFInValue, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _throwUnquotedSpace, _wrapError, clearCurrentToken, getCurrentToken, getLastClearedToken, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, getValueAsString, hasCurrentToken, nextValue, skipChildren, version
 
Methods inherited from class com.fasterxml.jackson.core.JsonParser
_constructError, _reportUnsupportedOperation, canUseSchema, configure, disable, enable, getBinaryValue, getBooleanValue, getByteValue, getInputSource, getSchema, getShortValue, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, getValueAsString, isEnabled, isExpectedStartArrayToken, nextBooleanValue, nextFieldName, nextIntValue, nextLongValue, nextTextValue, readBinaryValue, readBinaryValue, readValueAs, readValueAs, readValueAsTree, readValuesAs, readValuesAs, releaseBuffered, releaseBuffered, requiresCustomCodec, setSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BsonParser

public BsonParser(com.fasterxml.jackson.core.io.IOContext ctxt,
                  int jsonFeatures,
                  int bsonFeatures,
                  java.io.InputStream in)
Constructs a new parser

Parameters:
ctxt - the Jackson IO context
jsonFeatures - bit flag composed of bits that indicate which JsonParser.Features are enabled.
bsonFeatures - bit flag composed of bits that indicate which BsonParser.Features are enabled.
in - the input stream to parse.
Method Detail

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

getCodec

public com.fasterxml.jackson.core.ObjectCodec getCodec()
Specified by:
getCodec in class com.fasterxml.jackson.core.JsonParser

setCodec

public void setCodec(com.fasterxml.jackson.core.ObjectCodec c)
Specified by:
setCodec in class com.fasterxml.jackson.core.JsonParser

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException

nextToken

public com.fasterxml.jackson.core.JsonToken nextToken()
                                               throws java.io.IOException,
                                                      com.fasterxml.jackson.core.JsonParseException
Specified by:
nextToken in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

handleNewDocument

protected com.fasterxml.jackson.core.JsonToken handleNewDocument(boolean array)
                                                          throws java.io.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:
java.io.IOException - if an I/O error occurs

handleBinary

protected com.fasterxml.jackson.core.JsonToken handleBinary()
                                                     throws java.io.IOException
Reads binary data from the input stream

Returns:
the json token read
Throws:
java.io.IOException - if an I/O error occurs

regexStrToFlags

protected int regexStrToFlags(java.lang.String pattern)
                       throws com.fasterxml.jackson.core.JsonParseException
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:
com.fasterxml.jackson.core.JsonParseException - if the pattern string contains a unsupported flag

handleRegEx

protected com.fasterxml.jackson.core.JsonToken handleRegEx()
                                                    throws java.io.IOException
Reads and compiles a regular expression

Returns:
the json token read
Throws:
java.io.IOException - if an I/O error occurs

handleDBPointer

protected com.fasterxml.jackson.core.JsonToken handleDBPointer()
                                                        throws java.io.IOException
Reads a DBPointer from the stream

Returns:
the json token read
Throws:
java.io.IOException - if an I/O error occurs

handleJavascriptWithScope

protected com.fasterxml.jackson.core.JsonToken handleJavascriptWithScope()
                                                                  throws java.io.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:
java.io.IOException - if an I/O error occurs

readCString

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

skipCString

protected void skipCString()
                    throws java.io.IOException
Skips over a null-terminated string in the input stream

Throws:
java.io.IOException - if an I/O error occurs

readString

protected java.lang.String readString()
                               throws java.io.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:
java.io.IOException - if the string could not be read

readSymbol

protected Symbol readSymbol()
                     throws java.io.IOException
Reads a symbol object from the input stream

Returns:
the symbol
Throws:
java.io.IOException - if the symbol could not be read

readTimestamp

protected Timestamp readTimestamp()
                           throws java.io.IOException
Reads a timestamp object from the input stream

Returns:
the timestamp
Throws:
java.io.IOException - if the timestamp could not be read

readObjectId

protected ObjectId readObjectId()
                         throws java.io.IOException
Reads a ObjectID from the input stream

Returns:
the ObjectID
Throws:
java.io.IOException - if the ObjectID could not be read

readDocument

protected java.util.Map<java.lang.String,java.lang.Object> readDocument()
                                                                 throws java.io.IOException
Fully reads an embedded document, reusing this parser

Returns:
the parsed document
Throws:
java.io.IOException - if the document could not be read

getContext

protected de.undercouch.bson4jackson.BsonParser.Context getContext()
                                                            throws java.io.IOException
Returns:
the context of the current element
Throws:
java.io.IOException - if there is no context

isClosed

public boolean isClosed()
Overrides:
isClosed in class com.fasterxml.jackson.core.base.ParserBase

getCurrentName

public java.lang.String getCurrentName()
                                throws java.io.IOException,
                                       com.fasterxml.jackson.core.JsonParseException
Overrides:
getCurrentName in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getParsingContext

public com.fasterxml.jackson.core.json.JsonReadContext getParsingContext()
Overrides:
getParsingContext in class com.fasterxml.jackson.core.base.ParserBase

getTokenLocation

public com.fasterxml.jackson.core.JsonLocation getTokenLocation()
Overrides:
getTokenLocation in class com.fasterxml.jackson.core.base.ParserBase

getCurrentLocation

public com.fasterxml.jackson.core.JsonLocation getCurrentLocation()
Overrides:
getCurrentLocation in class com.fasterxml.jackson.core.base.ParserBase

getText

public java.lang.String getText()
                         throws java.io.IOException,
                                com.fasterxml.jackson.core.JsonParseException
Specified by:
getText in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getTextCharacters

public char[] getTextCharacters()
                         throws java.io.IOException,
                                com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextCharacters in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getTextLength

public int getTextLength()
                  throws java.io.IOException,
                         com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextLength in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getTextOffset

public int getTextOffset()
                  throws java.io.IOException,
                         com.fasterxml.jackson.core.JsonParseException
Specified by:
getTextOffset in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

hasTextCharacters

public boolean hasTextCharacters()
Overrides:
hasTextCharacters in class com.fasterxml.jackson.core.base.ParserBase

getNumberValue

public java.lang.Number getNumberValue()
                                throws java.io.IOException,
                                       com.fasterxml.jackson.core.JsonParseException
Overrides:
getNumberValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getNumberType

public com.fasterxml.jackson.core.JsonParser.NumberType getNumberType()
                                                               throws java.io.IOException,
                                                                      com.fasterxml.jackson.core.JsonParseException
Overrides:
getNumberType in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getIntValue

public int getIntValue()
                throws java.io.IOException,
                       com.fasterxml.jackson.core.JsonParseException
Overrides:
getIntValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getLongValue

public long getLongValue()
                  throws java.io.IOException,
                         com.fasterxml.jackson.core.JsonParseException
Overrides:
getLongValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getBigIntegerValue

public java.math.BigInteger getBigIntegerValue()
                                        throws java.io.IOException,
                                               com.fasterxml.jackson.core.JsonParseException
Overrides:
getBigIntegerValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getFloatValue

public float getFloatValue()
                    throws java.io.IOException,
                           com.fasterxml.jackson.core.JsonParseException
Overrides:
getFloatValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws java.io.IOException,
                             com.fasterxml.jackson.core.JsonParseException
Overrides:
getDoubleValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getDecimalValue

public java.math.BigDecimal getDecimalValue()
                                     throws java.io.IOException,
                                            com.fasterxml.jackson.core.JsonParseException
Overrides:
getDecimalValue in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getBinaryValue

public byte[] getBinaryValue(com.fasterxml.jackson.core.Base64Variant b64variant)
                      throws java.io.IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
getBinaryValue in class com.fasterxml.jackson.core.base.ParserMinimalBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

getEmbeddedObject

public java.lang.Object getEmbeddedObject()
                                   throws java.io.IOException,
                                          com.fasterxml.jackson.core.JsonParseException
Specified by:
getEmbeddedObject in class com.fasterxml.jackson.core.JsonParser
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

_handleEOF

protected void _handleEOF()
                   throws com.fasterxml.jackson.core.JsonParseException
Overrides:
_handleEOF in class com.fasterxml.jackson.core.base.ParserBase
Throws:
com.fasterxml.jackson.core.JsonParseException

loadMore

protected boolean loadMore()
                    throws java.io.IOException
Specified by:
loadMore in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException

_finishString

protected void _finishString()
                      throws java.io.IOException,
                             com.fasterxml.jackson.core.JsonParseException
Specified by:
_finishString in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException
com.fasterxml.jackson.core.JsonParseException

_closeInput

protected void _closeInput()
                    throws java.io.IOException
Specified by:
_closeInput in class com.fasterxml.jackson.core.base.ParserBase
Throws:
java.io.IOException