de.undercouch.bson4jackson
Class BsonParser

java.lang.Object
  extended by org.codehaus.jackson.JsonParser
      extended by org.codehaus.jackson.impl.JsonParserMinimalBase
          extended by de.undercouch.bson4jackson.BsonParser
All Implemented Interfaces:
java.io.Closeable, org.codehaus.jackson.Versioned

public class BsonParser
extends org.codehaus.jackson.impl.JsonParserMinimalBase

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 org.codehaus.jackson.JsonParser
org.codehaus.jackson.JsonParser.NumberType
 
Field Summary
 
Fields inherited from class org.codehaus.jackson.impl.JsonParserMinimalBase
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 org.codehaus.jackson.JsonParser
_currToken, _features, _lastClearedToken
 
Constructor Summary
BsonParser(int jsonFeatures, int bsonFeatures, java.io.InputStream in)
          Constructs a new parser
 
Method Summary
protected  void _handleEOF()
           
 void close()
           
 java.math.BigInteger getBigIntegerValue()
           
 byte[] getBinaryValue(org.codehaus.jackson.Base64Variant b64variant)
           
 org.codehaus.jackson.ObjectCodec getCodec()
           
protected  de.undercouch.bson4jackson.BsonParser.Context getContext()
           
 org.codehaus.jackson.JsonLocation getCurrentLocation()
           
 java.lang.String getCurrentName()
           
 java.math.BigDecimal getDecimalValue()
           
 double getDoubleValue()
           
 java.lang.Object getEmbeddedObject()
           
 float getFloatValue()
           
 int getIntValue()
           
 long getLongValue()
           
 org.codehaus.jackson.JsonParser.NumberType getNumberType()
           
 java.lang.Number getNumberValue()
           
 org.codehaus.jackson.JsonStreamContext getParsingContext()
           
 java.lang.String getText()
           
 char[] getTextCharacters()
           
 int getTextLength()
           
 int getTextOffset()
           
 org.codehaus.jackson.JsonLocation getTokenLocation()
           
protected  org.codehaus.jackson.JsonToken handleBinary()
          Reads binary data from the input stream
protected  org.codehaus.jackson.JsonToken handleDBPointer()
          Reads a DBPointer from the stream
protected  org.codehaus.jackson.JsonToken handleJavascriptWithScope()
          Can be called when embedded javascript code with scope is found.
protected  org.codehaus.jackson.JsonToken handleNewDocument(boolean array)
          Can be called when a new embedded document is found.
protected  org.codehaus.jackson.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
 org.codehaus.jackson.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(org.codehaus.jackson.ObjectCodec c)
           
protected  void skipCString()
          Skips over a null-terminated string in the input stream
 
Methods inherited from class org.codehaus.jackson.impl.JsonParserMinimalBase
_constructError, _getCharDesc, _handleUnrecognizedCharacterEscape, _reportError, _reportInvalidEOF, _reportInvalidEOF, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _throwUnquotedSpace, _wrapError, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, skipChildren
 
Methods inherited from class org.codehaus.jackson.JsonParser
_constructError, clearCurrentToken, configure, disable, disableFeature, enable, enableFeature, getBinaryValue, getBooleanValue, getByteValue, getCurrentToken, getLastClearedToken, getShortValue, getValueAsBoolean, getValueAsDouble, getValueAsInt, getValueAsLong, hasCurrentToken, isEnabled, isExpectedStartArrayToken, isFeatureEnabled, nextValue, readValueAs, readValueAs, readValueAsTree, releaseBuffered, releaseBuffered, setFeature, version
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BsonParser

public BsonParser(int jsonFeatures,
                  int bsonFeatures,
                  java.io.InputStream in)
Constructs a new parser

Parameters:
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 org.codehaus.jackson.ObjectCodec getCodec()
Specified by:
getCodec in class org.codehaus.jackson.JsonParser

setCodec

public void setCodec(org.codehaus.jackson.ObjectCodec c)
Specified by:
setCodec in class org.codehaus.jackson.JsonParser

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException

nextToken

public org.codehaus.jackson.JsonToken nextToken()
                                         throws java.io.IOException,
                                                org.codehaus.jackson.JsonParseException
Specified by:
nextToken in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

handleNewDocument

protected org.codehaus.jackson.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 org.codehaus.jackson.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 org.codehaus.jackson.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:
org.codehaus.jackson.JsonParseException - if the pattern string contains a unsupported flag

handleRegEx

protected org.codehaus.jackson.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 org.codehaus.jackson.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 org.codehaus.jackson.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()
Specified by:
isClosed in class org.codehaus.jackson.impl.JsonParserMinimalBase

getCurrentName

public java.lang.String getCurrentName()
                                throws java.io.IOException,
                                       org.codehaus.jackson.JsonParseException
Specified by:
getCurrentName in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getParsingContext

public org.codehaus.jackson.JsonStreamContext getParsingContext()
Specified by:
getParsingContext in class org.codehaus.jackson.impl.JsonParserMinimalBase

getTokenLocation

public org.codehaus.jackson.JsonLocation getTokenLocation()
Specified by:
getTokenLocation in class org.codehaus.jackson.JsonParser

getCurrentLocation

public org.codehaus.jackson.JsonLocation getCurrentLocation()
Specified by:
getCurrentLocation in class org.codehaus.jackson.JsonParser

getText

public java.lang.String getText()
                         throws java.io.IOException,
                                org.codehaus.jackson.JsonParseException
Specified by:
getText in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getTextCharacters

public char[] getTextCharacters()
                         throws java.io.IOException,
                                org.codehaus.jackson.JsonParseException
Specified by:
getTextCharacters in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getTextLength

public int getTextLength()
                  throws java.io.IOException,
                         org.codehaus.jackson.JsonParseException
Specified by:
getTextLength in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getTextOffset

public int getTextOffset()
                  throws java.io.IOException,
                         org.codehaus.jackson.JsonParseException
Specified by:
getTextOffset in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

hasTextCharacters

public boolean hasTextCharacters()
Specified by:
hasTextCharacters in class org.codehaus.jackson.impl.JsonParserMinimalBase

getNumberValue

public java.lang.Number getNumberValue()
                                throws java.io.IOException,
                                       org.codehaus.jackson.JsonParseException
Specified by:
getNumberValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getNumberType

public org.codehaus.jackson.JsonParser.NumberType getNumberType()
                                                         throws java.io.IOException,
                                                                org.codehaus.jackson.JsonParseException
Specified by:
getNumberType in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getIntValue

public int getIntValue()
                throws java.io.IOException,
                       org.codehaus.jackson.JsonParseException
Specified by:
getIntValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getLongValue

public long getLongValue()
                  throws java.io.IOException,
                         org.codehaus.jackson.JsonParseException
Specified by:
getLongValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getBigIntegerValue

public java.math.BigInteger getBigIntegerValue()
                                        throws java.io.IOException,
                                               org.codehaus.jackson.JsonParseException
Specified by:
getBigIntegerValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getFloatValue

public float getFloatValue()
                    throws java.io.IOException,
                           org.codehaus.jackson.JsonParseException
Specified by:
getFloatValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws java.io.IOException,
                             org.codehaus.jackson.JsonParseException
Specified by:
getDoubleValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getDecimalValue

public java.math.BigDecimal getDecimalValue()
                                     throws java.io.IOException,
                                            org.codehaus.jackson.JsonParseException
Specified by:
getDecimalValue in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getBinaryValue

public byte[] getBinaryValue(org.codehaus.jackson.Base64Variant b64variant)
                      throws java.io.IOException,
                             org.codehaus.jackson.JsonParseException
Specified by:
getBinaryValue in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

getEmbeddedObject

public java.lang.Object getEmbeddedObject()
                                   throws java.io.IOException,
                                          org.codehaus.jackson.JsonParseException
Overrides:
getEmbeddedObject in class org.codehaus.jackson.JsonParser
Throws:
java.io.IOException
org.codehaus.jackson.JsonParseException

_handleEOF

protected void _handleEOF()
                   throws org.codehaus.jackson.JsonParseException
Specified by:
_handleEOF in class org.codehaus.jackson.impl.JsonParserMinimalBase
Throws:
org.codehaus.jackson.JsonParseException