Package org.bson
Class AbstractBsonReader
java.lang.Object
org.bson.AbstractBsonReader
- All Implemented Interfaces:
Closeable,AutoCloseable,BsonReader
- Direct Known Subclasses:
BsonBinaryReader,BsonDocumentReader,JsonReader
Abstract base class for BsonReader implementations.
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe context for the reader.protected classAn implementation ofBsonReaderMark.static enumThe state of a reader. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInitializes a new instance of the BsonReader class. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckPreconditions(String methodName, BsonType type) Ensures any conditions are met before reading commences.voidclose()Closes the reader.protected abstract intHandles the logic to peek at the binary size.protected abstract byteHandles the logic to peek at the binary subtype.protected abstract BsonBinaryHandles the logic to read binary dataprotected abstract booleanHandles the logic to read booleansprotected abstract longHandles the logic to read date timeprotected abstract BsonDbPointerHandles the logic to read a DBPointerprotected abstract Decimal128Handles the logic to read Decimal128protected abstract doubleHandles the logic to read doublesprotected abstract voidHandles the logic when reading the end of an arrayprotected abstract voidHandles the logic when reading the end of a documentprotected abstract intHandles the logic to read 32 bit intsprotected abstract longHandles the logic to read 64 bit intsprotected abstract StringHandles the logic to read JavaScript functionsprotected abstract StringHandles the logic to read scoped JavaScript functionsprotected abstract voidHandles the logic to read a Max keyprotected abstract voidHandles the logic to read a Min keyprotected abstract voidHandles the logic to read a null valueprotected abstract ObjectIdHandles the logic to read an ObjectIdprotected abstract BsonRegularExpressionHandles the logic to read a regular expressionprotected abstract voidHandles the logic to read the start of an arrayprotected abstract voidHandles the logic to read the start of a documentprotected abstract StringHandles the logic to read a Stringprotected abstract StringHandles the logic to read a Symbolprotected abstract BsonTimestampHandles the logic to read a timestampprotected abstract voidHandles the logic to read an Undefined valueprotected abstract voidHandles any logic required to skip the name (reader must be positioned on a name).protected abstract voidHandles any logic required to skip the value (reader must be positioned on a value).protected AbstractBsonReader.ContextGet the context, which will indicate which state the reader is in, for example which part of a document it's currently reading.Gets the most recently read name.protected AbstractBsonReader.StateReturns the nextStateto transition to, based on theAbstractBsonReader.Contextof this reader.getState()protected booleanisClosed()Return true if the reader has been closed.intPeeks the size of the binary data that the reader is positioned at.bytePeeks the subtype of the binary data that the reader is positioned at.Reads BSON Binary data from the reader.readBinaryData(String name) Reads a BSON Binary data element from the reader.booleanReads a BSON Boolean from the reader.booleanreadBoolean(String name) Reads a BSON Boolean element from the reader.abstract BsonTypeReads a BSONType from the reader.longReads a BSON DateTime from the reader.longreadDateTime(String name) Reads a BSON DateTime element from the reader.Reads a BSON DBPointer from the reader.readDBPointer(String name) Reads a BSON DBPointer element from the reader.Reads a BSON Decimal128 from the reader.readDecimal128(String name) Reads a BSON Decimal128 element from the reader.doubleReads a BSON Double from the reader.doublereadDouble(String name) Reads a BSON Double element from the reader.voidReads the end of a BSON array from the reader.voidReads the end of a BSON document from the reader.intReads a BSON Int32 from the reader.intReads a BSON Int32 element from the reader.longReads a BSON Int64 from the reader.longReads a BSON Int64 element from the reader.Reads a BSON JavaScript from the reader.readJavaScript(String name) Reads a BSON JavaScript element from the reader.Reads a BSON JavaScript with scope from the reader (call readStartDocument next to read the scope).Reads a BSON JavaScript with scope element from the reader (call readStartDocument next to read the scope).voidReads a BSON MaxKey from the reader.voidreadMaxKey(String name) Reads a BSON MaxKey element from the reader.voidReads a BSON MinKey from the reader.voidreadMinKey(String name) Reads a BSON MinKey element from the reader.readName()Reads the name of an element from the reader.voidReads the name of an element from the reader.voidreadNull()Reads a BSON null from the reader.voidReads a BSON null element from the reader.Reads a BSON ObjectId from the reader.readObjectId(String name) Reads a BSON ObjectId element from the reader.Reads a BSON regular expression from the reader.readRegularExpression(String name) Reads a BSON regular expression element from the reader.voidReads the start of a BSON array.voidReads the start of a BSON document.Reads a BSON String from the reader.readString(String name) Reads a BSON string element from the reader.Reads a BSON symbol from the reader.readSymbol(String name) Reads a BSON symbol element from the reader.Reads a BSON timestamp from the reader.readTimestamp(String name) Reads a BSON timestamp element from the reader.voidReads a BSON undefined from the reader.voidreadUndefined(String name) Reads a BSON undefined element from the reader.protected voidsetContext(AbstractBsonReader.Context context) Set the context, which will indicate which state the reader is in, for example which part of a document it's currently reading.protected voidsetCurrentBsonType(BsonType newType) Sets the type of the current value being read.protected voidsetCurrentName(String newName) Sets the field name for the key/value pair being read.protected voidsetState(AbstractBsonReader.State newState) Sets the new current state of this reader.voidskipName()Skips the name (reader must be positioned on a name).voidSkips the value (reader must be positioned on a value).protected voidthrowInvalidContextType(String methodName, BsonContextType actualContextType, BsonContextType... validContextTypes) Throws an InvalidOperationException when the method called is not valid for the current ContextType.protected voidthrowInvalidState(String methodName, AbstractBsonReader.State... validStates) Throws an InvalidOperationException when the method called is not valid for the current state.protected voidverifyBSONType(String methodName, BsonType requiredBsonType) Verifies the current state and BSONType of the reader.protected voidverifyName(String expectedName) Verifies the name of the current element.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bson.BsonReader
getMark
-
Constructor Details
-
AbstractBsonReader
protected AbstractBsonReader()Initializes a new instance of the BsonReader class.
-
-
Method Details
-
getCurrentBsonType
- Specified by:
getCurrentBsonTypein interfaceBsonReader- Returns:
- The current BsonType.
-
getCurrentName
Description copied from interface:BsonReaderGets the most recently read name.- Specified by:
getCurrentNamein interfaceBsonReader- Returns:
- the most recently read name
-
setCurrentBsonType
Sets the type of the current value being read.- Parameters:
newType- the BSON Type.
-
getState
- Returns:
- The current state of the reader.
-
setState
Sets the new current state of this reader.- Parameters:
newState- the state to set this reader to.
-
setCurrentName
Sets the field name for the key/value pair being read.- Parameters:
newName- the field name
-
close
public void close()Closes the reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBsonReader- Specified by:
closein interfaceCloseable
-
isClosed
protected boolean isClosed()Return true if the reader has been closed.- Returns:
- true if closed
-
doReadBinaryData
Handles the logic to read binary data- Returns:
- the BsonBinary value
-
doPeekBinarySubType
protected abstract byte doPeekBinarySubType()Handles the logic to peek at the binary subtype.- Returns:
- the binary subtype
-
doPeekBinarySize
protected abstract int doPeekBinarySize()Handles the logic to peek at the binary size.- Returns:
- the binary size
- Since:
- 3.4
-
doReadBoolean
protected abstract boolean doReadBoolean()Handles the logic to read booleans- Returns:
- the boolean value
-
doReadDateTime
protected abstract long doReadDateTime()Handles the logic to read date time- Returns:
- the long value
-
doReadDouble
protected abstract double doReadDouble()Handles the logic to read doubles- Returns:
- the double value
-
doReadEndArray
protected abstract void doReadEndArray()Handles the logic when reading the end of an array -
doReadEndDocument
protected abstract void doReadEndDocument()Handles the logic when reading the end of a document -
doReadInt32
protected abstract int doReadInt32()Handles the logic to read 32 bit ints- Returns:
- the int value
-
doReadInt64
protected abstract long doReadInt64()Handles the logic to read 64 bit ints- Returns:
- the long value
-
doReadDecimal128
Handles the logic to read Decimal128- Returns:
- the Decimal128 value
- Since:
- 3.4
-
doReadJavaScript
Handles the logic to read JavaScript functions- Returns:
- the String value
-
doReadJavaScriptWithScope
Handles the logic to read scoped JavaScript functions- Returns:
- the String value
-
doReadMaxKey
protected abstract void doReadMaxKey()Handles the logic to read a Max key -
doReadMinKey
protected abstract void doReadMinKey()Handles the logic to read a Min key -
doReadNull
protected abstract void doReadNull()Handles the logic to read a null value -
doReadObjectId
Handles the logic to read an ObjectId- Returns:
- the ObjectId value
-
doReadRegularExpression
Handles the logic to read a regular expression- Returns:
- the BsonRegularExpression value
-
doReadDBPointer
Handles the logic to read a DBPointer- Returns:
- the BsonDbPointer value
-
doReadStartArray
protected abstract void doReadStartArray()Handles the logic to read the start of an array -
doReadStartDocument
protected abstract void doReadStartDocument()Handles the logic to read the start of a document -
doReadString
Handles the logic to read a String- Returns:
- the String value
-
doReadSymbol
Handles the logic to read a Symbol- Returns:
- the String value
-
doReadTimestamp
Handles the logic to read a timestamp- Returns:
- the BsonTimestamp value
-
doReadUndefined
protected abstract void doReadUndefined()Handles the logic to read an Undefined value -
doSkipName
protected abstract void doSkipName()Handles any logic required to skip the name (reader must be positioned on a name). -
doSkipValue
protected abstract void doSkipValue()Handles any logic required to skip the value (reader must be positioned on a value). -
readBinaryData
Description copied from interface:BsonReaderReads BSON Binary data from the reader.- Specified by:
readBinaryDatain interfaceBsonReader- Returns:
- A Binary.
-
peekBinarySubType
public byte peekBinarySubType()Description copied from interface:BsonReaderPeeks the subtype of the binary data that the reader is positioned at. This operation is not permitted if the mark is already set.- Specified by:
peekBinarySubTypein interfaceBsonReader- Returns:
- the subtype
- See Also:
-
peekBinarySize
public int peekBinarySize()Description copied from interface:BsonReaderPeeks the size of the binary data that the reader is positioned at. This operation is not permitted if the mark is already set.- Specified by:
peekBinarySizein interfaceBsonReader- Returns:
- the size of the binary data
- See Also:
-
readBoolean
public boolean readBoolean()Description copied from interface:BsonReaderReads a BSON Boolean from the reader.- Specified by:
readBooleanin interfaceBsonReader- Returns:
- A Boolean.
-
readBsonType
Description copied from interface:BsonReaderReads a BSONType from the reader.- Specified by:
readBsonTypein interfaceBsonReader- Returns:
- A BSONType.
-
readDateTime
public long readDateTime()Description copied from interface:BsonReaderReads a BSON DateTime from the reader.- Specified by:
readDateTimein interfaceBsonReader- Returns:
- The number of milliseconds since the Unix epoch.
-
readDouble
public double readDouble()Description copied from interface:BsonReaderReads a BSON Double from the reader.- Specified by:
readDoublein interfaceBsonReader- Returns:
- A Double.
-
readEndArray
public void readEndArray()Description copied from interface:BsonReaderReads the end of a BSON array from the reader.- Specified by:
readEndArrayin interfaceBsonReader
-
readEndDocument
public void readEndDocument()Description copied from interface:BsonReaderReads the end of a BSON document from the reader.- Specified by:
readEndDocumentin interfaceBsonReader
-
readInt32
public int readInt32()Description copied from interface:BsonReaderReads a BSON Int32 from the reader.- Specified by:
readInt32in interfaceBsonReader- Returns:
- An Int32.
-
readInt64
public long readInt64()Description copied from interface:BsonReaderReads a BSON Int64 from the reader.- Specified by:
readInt64in interfaceBsonReader- Returns:
- An Int64.
-
readDecimal128
Description copied from interface:BsonReaderReads a BSON Decimal128 from the reader.- Specified by:
readDecimal128in interfaceBsonReader- Returns:
- A Decimal128
-
readJavaScript
Description copied from interface:BsonReaderReads a BSON JavaScript from the reader.- Specified by:
readJavaScriptin interfaceBsonReader- Returns:
- A string.
-
readJavaScriptWithScope
Description copied from interface:BsonReaderReads a BSON JavaScript with scope from the reader (call readStartDocument next to read the scope).- Specified by:
readJavaScriptWithScopein interfaceBsonReader- Returns:
- A string.
-
readMaxKey
public void readMaxKey()Description copied from interface:BsonReaderReads a BSON MaxKey from the reader.- Specified by:
readMaxKeyin interfaceBsonReader
-
readMinKey
public void readMinKey()Description copied from interface:BsonReaderReads a BSON MinKey from the reader.- Specified by:
readMinKeyin interfaceBsonReader
-
readNull
public void readNull()Description copied from interface:BsonReaderReads a BSON null from the reader.- Specified by:
readNullin interfaceBsonReader
-
readObjectId
Description copied from interface:BsonReaderReads a BSON ObjectId from the reader.- Specified by:
readObjectIdin interfaceBsonReader- Returns:
- the
ObjectIdvalue
-
readRegularExpression
Description copied from interface:BsonReaderReads a BSON regular expression from the reader.- Specified by:
readRegularExpressionin interfaceBsonReader- Returns:
- A regular expression.
-
readDBPointer
Description copied from interface:BsonReaderReads a BSON DBPointer from the reader.- Specified by:
readDBPointerin interfaceBsonReader- Returns:
- A DBPointer.
-
readStartArray
public void readStartArray()Description copied from interface:BsonReaderReads the start of a BSON array.- Specified by:
readStartArrayin interfaceBsonReader
-
readStartDocument
public void readStartDocument()Description copied from interface:BsonReaderReads the start of a BSON document.- Specified by:
readStartDocumentin interfaceBsonReader
-
readString
Description copied from interface:BsonReaderReads a BSON String from the reader.- Specified by:
readStringin interfaceBsonReader- Returns:
- A String.
-
readSymbol
Description copied from interface:BsonReaderReads a BSON symbol from the reader.- Specified by:
readSymbolin interfaceBsonReader- Returns:
- A string.
-
readTimestamp
Description copied from interface:BsonReaderReads a BSON timestamp from the reader.- Specified by:
readTimestampin interfaceBsonReader- Returns:
- The combined timestamp/increment.
-
readUndefined
public void readUndefined()Description copied from interface:BsonReaderReads a BSON undefined from the reader.- Specified by:
readUndefinedin interfaceBsonReader
-
skipName
public void skipName()Description copied from interface:BsonReaderSkips the name (reader must be positioned on a name).- Specified by:
skipNamein interfaceBsonReader
-
skipValue
public void skipValue()Description copied from interface:BsonReaderSkips the value (reader must be positioned on a value).- Specified by:
skipValuein interfaceBsonReader
-
readBinaryData
Description copied from interface:BsonReaderReads a BSON Binary data element from the reader.- Specified by:
readBinaryDatain interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A Binary.
-
readBoolean
Description copied from interface:BsonReaderReads a BSON Boolean element from the reader.- Specified by:
readBooleanin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A Boolean.
-
readDateTime
Description copied from interface:BsonReaderReads a BSON DateTime element from the reader.- Specified by:
readDateTimein interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- The number of milliseconds since the Unix epoch.
-
readDouble
Description copied from interface:BsonReaderReads a BSON Double element from the reader.- Specified by:
readDoublein interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A Double.
-
readInt32
Description copied from interface:BsonReaderReads a BSON Int32 element from the reader.- Specified by:
readInt32in interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- An Int32.
-
readInt64
Description copied from interface:BsonReaderReads a BSON Int64 element from the reader.- Specified by:
readInt64in interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- An Int64.
-
readDecimal128
Description copied from interface:BsonReaderReads a BSON Decimal128 element from the reader.- Specified by:
readDecimal128in interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A Decimal128
-
readJavaScript
Description copied from interface:BsonReaderReads a BSON JavaScript element from the reader.- Specified by:
readJavaScriptin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A string.
-
readJavaScriptWithScope
Description copied from interface:BsonReaderReads a BSON JavaScript with scope element from the reader (call readStartDocument next to read the scope).- Specified by:
readJavaScriptWithScopein interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A string.
-
readMaxKey
Description copied from interface:BsonReaderReads a BSON MaxKey element from the reader.- Specified by:
readMaxKeyin interfaceBsonReader- Parameters:
name- The name of the element.
-
readMinKey
Description copied from interface:BsonReaderReads a BSON MinKey element from the reader.- Specified by:
readMinKeyin interfaceBsonReader- Parameters:
name- The name of the element.
-
readName
Description copied from interface:BsonReaderReads the name of an element from the reader.- Specified by:
readNamein interfaceBsonReader- Returns:
- The name of the element.
-
readName
Description copied from interface:BsonReaderReads the name of an element from the reader.- Specified by:
readNamein interfaceBsonReader- Parameters:
name- The name of the element.
-
readNull
Description copied from interface:BsonReaderReads a BSON null element from the reader.- Specified by:
readNullin interfaceBsonReader- Parameters:
name- The name of the element.
-
readObjectId
Description copied from interface:BsonReaderReads a BSON ObjectId element from the reader.- Specified by:
readObjectIdin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- ObjectId.
-
readRegularExpression
Description copied from interface:BsonReaderReads a BSON regular expression element from the reader.- Specified by:
readRegularExpressionin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A regular expression.
-
readDBPointer
Description copied from interface:BsonReaderReads a BSON DBPointer element from the reader.- Specified by:
readDBPointerin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A DBPointer.
-
readString
Description copied from interface:BsonReaderReads a BSON string element from the reader.- Specified by:
readStringin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A String.
-
readSymbol
Description copied from interface:BsonReaderReads a BSON symbol element from the reader.- Specified by:
readSymbolin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- A string.
-
readTimestamp
Description copied from interface:BsonReaderReads a BSON timestamp element from the reader.- Specified by:
readTimestampin interfaceBsonReader- Parameters:
name- The name of the element.- Returns:
- The combined timestamp/increment.
-
readUndefined
Description copied from interface:BsonReaderReads a BSON undefined element from the reader.- Specified by:
readUndefinedin interfaceBsonReader- Parameters:
name- The name of the element.
-
throwInvalidContextType
protected void throwInvalidContextType(String methodName, BsonContextType actualContextType, BsonContextType... validContextTypes) Throws an InvalidOperationException when the method called is not valid for the current ContextType.- Parameters:
methodName- The name of the method.actualContextType- The actual ContextType.validContextTypes- The valid ContextTypes.- Throws:
BsonInvalidOperationException- when the method called is not valid for the current ContextType.
-
throwInvalidState
Throws an InvalidOperationException when the method called is not valid for the current state.- Parameters:
methodName- The name of the method.validStates- The valid states.- Throws:
BsonInvalidOperationException- when the method called is not valid for the current state.
-
verifyBSONType
Verifies the current state and BSONType of the reader.- Parameters:
methodName- The name of the method calling this one.requiredBsonType- The required BSON type.
-
verifyName
Verifies the name of the current element.- Parameters:
expectedName- The expected name.- Throws:
BsonSerializationException- when the name read is not the expected name
-
checkPreconditions
Ensures any conditions are met before reading commences. Throws exceptions if the conditions are not met.- Parameters:
methodName- the name of the current method, which will indicate the field being readtype- the type of this field
-
getContext
Get the context, which will indicate which state the reader is in, for example which part of a document it's currently reading.- Returns:
- the context
-
setContext
Set the context, which will indicate which state the reader is in, for example which part of a document it's currently reading.- Parameters:
context- the current context.
-
getNextState
Returns the nextStateto transition to, based on theAbstractBsonReader.Contextof this reader.- Returns:
- the next state
-