Package de.undercouch.bson4jackson
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 ClassesModifier and TypeClassDescriptionprotected static classprotected static classInformation about the element currently begin parsedstatic enumDefines toggable featuresprotected static enumSpecifies what the parser is currently parsing (field name or value) or if it is done with the current elementNested classes/interfaces inherited from class tools.jackson.core.JsonParser
tools.jackson.core.JsonParser.NumberType, tools.jackson.core.JsonParser.NumberTypeFP -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe features for this parserprotected CountingInputStreamCounts the number of bytes read from_inprotected BsonParser.ContextThe current parser stateprotected LittleEndianInputStreamThe input stream to read fromprotected InputStreamThe raw input stream passed inprotected tools.jackson.core.json.JsonReadContextThe Jackson read context for tracking parsing stateprotected intThe position of the current tokenFields 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, _tokenInputTotalFields 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_DEFAULTSFields inherited from class tools.jackson.core.JsonParser
DEFAULT_READ_CAPABILITIES -
Constructor Summary
ConstructorsConstructorDescriptionBsonParser(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 TypeMethodDescriptionprotected voidprotected voidprotected intprotected void_parseNumericValue(int expType) voidclose()tools.jackson.core.TokenStreamLocationtools.jackson.core.TokenStreamLocationbyte[]getBinaryValue(tools.jackson.core.Base64Variant b64variant) protected BsonParser.Contextbytedoublefloatintlongtools.jackson.core.JsonParser.NumberTypechar[]intintprotected tools.jackson.core.JsonTokenReads binary data from the input streamprotected tools.jackson.core.JsonTokenReads a DBPointer from the streamprotected tools.jackson.core.JsonTokenCan be called when embedded javascript code with scope is found.protected tools.jackson.core.JsonTokenhandleNewDocument(boolean array) Can be called when a new embedded document is found.protected tools.jackson.core.JsonTokenReads and compiles a regular expressionbooleanprotected booleanChecks if a generator feature is enabledbooleantools.jackson.core.JsonTokenprotected StringFully reads an embedded document, reusing this parserprotected ObjectIdReads a ObjectID from the input streamprotected StringReads a string that consists of a integer denoting the number of bytes, the bytes (including a terminating 0 byte)protected SymbolReads a symbol object from the input streamprotected TimestampReads a timestamp object from the input streamprotected intregexStrToFlags(String pattern) Converts a BSON regex pattern string to a combined value of Java flags that can be used inPattern.compile(String, int)protected voidSkips over a null-terminated string in the input streamtools.jackson.core.TokenStreamContexttools.jackson.core.Versionversion()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, resetIntMethods 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, streamReadFeaturesMethods 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
-
Field Details
-
_bsonFeatures
protected int _bsonFeaturesThe features for this parser -
_in
The input stream to read from -
_counter
Counts the number of bytes read from_in -
_rawInputStream
The raw input stream passed in -
_tokenPos
protected int _tokenPosThe position of the current token -
_streamReadContext
protected tools.jackson.core.json.JsonReadContext _streamReadContextThe Jackson read context for tracking parsing state -
_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 contextctxt- the Jackson IO contextjsonFeatures- bit flag composed of bits that indicate whichStreamReadFeatures are enabled.bsonFeatures- bit flag composed of bits that indicate whichBsonParser.Features are enabled.in- the input stream to parse.
-
-
Method Details
-
isEnabled
Checks if a generator feature is enabled- Parameters:
f- the feature- Returns:
- true if the given feature is enabled
-
isExpectedStartArrayToken
public boolean isExpectedStartArrayToken()- Overrides:
isExpectedStartArrayTokenin classtools.jackson.core.base.ParserMinimalBase
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classtools.jackson.core.base.ParserBase
-
nextToken
public tools.jackson.core.JsonToken nextToken()- Specified by:
nextTokenin classtools.jackson.core.JsonParser
-
handleNewDocument
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
Reads binary data from the input stream- Returns:
- the json token read
- Throws:
IOException- if an I/O error occurs
-
regexStrToFlags
Converts a BSON regex pattern string to a combined value of Java flags that can be used inPattern.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
Reads and compiles a regular expression- Returns:
- the json token read
- Throws:
IOException- if an I/O error occurs
-
handleDBPointer
Reads a DBPointer from the stream- Returns:
- the json token read
- Throws:
IOException- if an I/O error occurs
-
handleJavascriptWithScope
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
- Returns:
- a null-terminated string read from the input stream
- Throws:
IOException- if the string could not be read
-
skipCString
Skips over a null-terminated string in the input stream- Throws:
IOException- if an I/O error occurs
-
readString
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
Reads a symbol object from the input stream- Returns:
- the symbol
- Throws:
IOException- if the symbol could not be read
-
readTimestamp
Reads a timestamp object from the input stream- Returns:
- the timestamp
- Throws:
IOException- if the timestamp could not be read
-
readObjectId
Reads a ObjectID from the input stream- Returns:
- the ObjectID
- Throws:
IOException- if the ObjectID could not be read
-
readDocument
Fully reads an embedded document, reusing this parser- Returns:
- the parsed document
- Throws:
IOException- if the document could not be read
-
getContext
- Returns:
- the context of the current element
- Throws:
IllegalStateException- if there is no context
-
currentName
- Specified by:
currentNamein classtools.jackson.core.JsonParser
-
getCurrentBsonType
public byte getCurrentBsonType()- Returns:
- the BSON type of the current element
-
currentTokenLocation
public tools.jackson.core.TokenStreamLocation currentTokenLocation()- Specified by:
currentTokenLocationin classtools.jackson.core.JsonParser
-
currentLocation
public tools.jackson.core.TokenStreamLocation currentLocation()- Specified by:
currentLocationin classtools.jackson.core.JsonParser
-
getString
- Specified by:
getStringin classtools.jackson.core.JsonParser
-
getStringCharacters
public char[] getStringCharacters()- Specified by:
getStringCharactersin classtools.jackson.core.JsonParser
-
getStringLength
public int getStringLength()- Specified by:
getStringLengthin classtools.jackson.core.JsonParser
-
getStringOffset
public int getStringOffset()- Specified by:
getStringOffsetin classtools.jackson.core.JsonParser
-
hasStringCharacters
public boolean hasStringCharacters()- Overrides:
hasStringCharactersin classtools.jackson.core.base.ParserBase
-
getNumberValue
- Overrides:
getNumberValuein classtools.jackson.core.base.ParserBase
-
getNumberValueExact
- Overrides:
getNumberValueExactin classtools.jackson.core.base.ParserBase
-
getNumberValueDeferred
- Overrides:
getNumberValueDeferredin classtools.jackson.core.base.ParserBase
-
getNumberType
public tools.jackson.core.JsonParser.NumberType getNumberType()- Overrides:
getNumberTypein classtools.jackson.core.base.ParserBase
-
getIntValue
public int getIntValue()- Overrides:
getIntValuein classtools.jackson.core.base.ParserBase
-
getLongValue
public long getLongValue()- Overrides:
getLongValuein classtools.jackson.core.base.ParserBase
-
getBigIntegerValue
- Overrides:
getBigIntegerValuein classtools.jackson.core.base.ParserBase
-
getFloatValue
public float getFloatValue()- Overrides:
getFloatValuein classtools.jackson.core.base.ParserBase
-
getDoubleValue
public double getDoubleValue()- Overrides:
getDoubleValuein classtools.jackson.core.base.ParserBase
-
getDecimalValue
- Overrides:
getDecimalValuein classtools.jackson.core.base.ParserBase
-
getBinaryValue
public byte[] getBinaryValue(tools.jackson.core.Base64Variant b64variant) - Overrides:
getBinaryValuein classtools.jackson.core.base.ParserBase
-
getEmbeddedObject
- Overrides:
getEmbeddedObjectin classtools.jackson.core.base.ParserMinimalBase
-
_handleEOF
protected void _handleEOF() throws tools.jackson.core.exc.StreamReadException- Overrides:
_handleEOFin classtools.jackson.core.base.ParserBase- Throws:
tools.jackson.core.exc.StreamReadException
-
streamReadContext
public tools.jackson.core.TokenStreamContext streamReadContext()- Specified by:
streamReadContextin classtools.jackson.core.JsonParser
-
streamReadInputSource
- Specified by:
streamReadInputSourcein classtools.jackson.core.JsonParser
-
version
public tools.jackson.core.Version version()- Specified by:
versionin interfacetools.jackson.core.Versioned- Specified by:
versionin classtools.jackson.core.JsonParser
-
_closeInput
- Specified by:
_closeInputin classtools.jackson.core.base.ParserMinimalBase- Throws:
IOException
-
_parseIntValue
protected int _parseIntValue()- Specified by:
_parseIntValuein classtools.jackson.core.base.ParserBase
-
_parseNumericValue
protected void _parseNumericValue(int expType) - Specified by:
_parseNumericValuein classtools.jackson.core.base.ParserBase
-