Package org.bson
Class RawBsonDocument
java.lang.Object
org.bson.BsonValue
org.bson.BsonDocument
org.bson.RawBsonDocument
A BSON document that is represented using only the raw bytes.
- Since:
- 3.0
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY -
Constructor Summary
ConstructorsConstructorDescriptionRawBsonDocument(byte[] bytes) Constructs a new instance with the given byte array.RawBsonDocument(byte[] bytes, int offset, int length) Constructs a new instance with the given byte array, offset, and length.RawBsonDocument(T document, Codec<T> codec) Construct a new instance from the given document and codec for the document type. -
Method Summary
Modifier and TypeMethodDescriptionPut the given key and value into this document, and return the document.voidclear()clone()booleancontainsKey(Object key) booleancontainsValue(Object value) <T> TDecode this into a document.<T> TDecode this into a document.entrySet()booleanbyte[]Returns the byte array backing this document.Returns aByteBufthat wraps the byte array, with the proper byte order.intReturns the length of this document within the backing byte array.intReturns the offset into the backing byte array where this document starts.Gets the first key in the document.inthashCode()booleanisEmpty()keySet()static RawBsonDocumentParses a string in MongoDB Extended JSON format to aRawBsonDocumentvoidintsize()toJson()Gets a JSON representation of this document using theJsonMode.RELAXEDoutput mode, and otherwise the default settings ofJsonWriterSettings.Builder.toJson(JsonWriterSettings settings) Gets a JSON representation of this document using the givenJsonWriterSettings.values()Methods inherited from class org.bson.BsonDocument
asBsonReader, get, getArray, getArray, getBinary, getBinary, getBoolean, getBoolean, getBsonType, getDateTime, getDateTime, getDecimal128, getDecimal128, getDocument, getDocument, getDouble, getDouble, getInt32, getInt32, getInt64, getInt64, getNumber, getNumber, getObjectId, getObjectId, getRegularExpression, getRegularExpression, getString, getString, getTimestamp, getTimestamp, isArray, isBinary, isBoolean, isDateTime, isDecimal128, isDocument, isDouble, isInt32, isInt64, isNull, isNumber, isObjectId, isString, isTimestamp, toBsonDocument, toStringMethods inherited from class org.bson.BsonValue
asArray, asBinary, asBoolean, asDateTime, asDBPointer, asDecimal128, asDocument, asDouble, asInt32, asInt64, asJavaScript, asJavaScriptWithScope, asNumber, asObjectId, asRegularExpression, asString, asSymbol, asTimestamp, isArray, isBinary, isBoolean, isDateTime, isDBPointer, isDecimal128, isDocument, isDouble, isInt32, isInt64, isJavaScript, isJavaScriptWithScope, isNull, isNumber, isObjectId, isRegularExpression, isString, isSymbol, isTimestampMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.bson.conversions.Bson
toBsonDocumentMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
RawBsonDocument
public RawBsonDocument(byte[] bytes) Constructs a new instance with the given byte array. Note that it does not make a copy of the array, so do not modify it after passing it to this constructor.- Parameters:
bytes- the bytes representing a BSON document. Note that the byte array is NOT copied, so care must be taken not to modify it after passing it to this construction, unless of course that is your intention.
-
RawBsonDocument
public RawBsonDocument(byte[] bytes, int offset, int length) Constructs a new instance with the given byte array, offset, and length. Note that it does not make a copy of the array, so do not modify it after passing it to this constructor.- Parameters:
bytes- the bytes representing a BSON document. Note that the byte array is NOT copied, so care must be taken not to modify it after passing it to this construction, unless of course that is your intention.offset- the offset into the byte arraylength- the length of the subarray to use- Since:
- 3.3
-
RawBsonDocument
Construct a new instance from the given document and codec for the document type.- Type Parameters:
T- the BSON type that the codec encodes/decodes- Parameters:
document- the document to transformcodec- the codec to facilitate the transformation
-
-
Method Details
-
parse
Parses a string in MongoDB Extended JSON format to aRawBsonDocument- Parameters:
json- the JSON string- Returns:
- a corresponding
RawBsonDocumentobject - Since:
- 3.3
- See Also:
- MongoDB documentation
- MongoDB Extended JSON
-
getByteBuffer
Returns aByteBufthat wraps the byte array, with the proper byte order. Any changes made to the returned will be reflected in the underlying byte array owned by this instance.- Returns:
- a byte buffer that wraps the byte array owned by this instance.
-
getBackingArray
public byte[] getBackingArray()Returns the byte array backing this document. The returned array may be larger than the BSON document itself; only the range fromgetByteOffset()togetByteOffset() +getByteLength()contains valid document bytes. Changes to the returned array will be reflected in this document.- Returns:
- the backing byte array
- Since:
- 5.8
- See Also:
-
getByteOffset
public int getByteOffset()Returns the offset into the backing byte array where this document starts.- Returns:
- the offset
- Since:
- 5.8
-
getByteLength
public int getByteLength()Returns the length of this document within the backing byte array.- Returns:
- the length
- Since:
- 5.8
-
decode
Decode this into a document.- Type Parameters:
T- the BSON type that the codec encodes/decodes- Parameters:
codec- the codec to facilitate the transformation- Returns:
- the decoded document
-
decode
Decode this into a document.- Type Parameters:
T- the BSON type that the codec encodes/decodes- Parameters:
decoder- the decoder to facilitate the transformation- Returns:
- the decoded document
- Since:
- 3.6
-
clear
public void clear() -
put
-
append
Description copied from class:BsonDocumentPut the given key and value into this document, and return the document.- Overrides:
appendin classBsonDocument- Parameters:
key- the keyvalue- the value- Returns:
- this
-
putAll
-
remove
-
isEmpty
public boolean isEmpty() -
size
public int size() -
entrySet
-
values
-
keySet
-
getFirstKey
Description copied from class:BsonDocumentGets the first key in the document.- Overrides:
getFirstKeyin classBsonDocument- Returns:
- the first key in the document
-
containsKey
- Specified by:
containsKeyin interfaceMap<String,BsonValue> - Overrides:
containsKeyin classBsonDocument
-
containsValue
- Specified by:
containsValuein interfaceMap<String,BsonValue> - Overrides:
containsValuein classBsonDocument
-
get
-
toJson
Description copied from class:BsonDocumentGets a JSON representation of this document using theJsonMode.RELAXEDoutput mode, and otherwise the default settings ofJsonWriterSettings.Builder.- Overrides:
toJsonin classBsonDocument- Returns:
- a JSON representation of this document
- See Also:
-
toJson
Description copied from class:BsonDocumentGets a JSON representation of this document using the givenJsonWriterSettings.- Overrides:
toJsonin classBsonDocument- Parameters:
settings- the JSON writer settings- Returns:
- a JSON representation of this document
-
equals
-
hashCode
public int hashCode() -
clone
- Overrides:
clonein classBsonDocument
-