Package org.bson
Class BasicBSONEncoder
java.lang.Object
org.bson.BasicBSONEncoder
- All Implemented Interfaces:
BSONEncoder
This is meant to be pooled or cached. There is some per instance memory for string conversion, etc...
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
_putObjectField
(String name, Object value) Encodes any Object typevoid
done()
Free the resources.byte[]
encode
(BSONObject document) Encode a document into byte array.protected BsonBinaryWriter
Gets the writer responsible for writing the encoded BSON.protected OutputBuffer
Gets the buffer the BSON is being encoded into.protected void
Encodes an array field.protected void
Encodes a byte array fieldprotected void
Encodes a Binary fieldprotected void
putBoolean
(String name, Boolean value) Encodes a field with aBoolean
orboolean
valueprotected void
Encodes a field to aBsonType.JAVASCRIPT
value.protected void
putCodeWScope
(String name, CodeWScope codeWScope) Encodes a field to aBsonType.JAVASCRIPT_WITH_SCOPE
value.protected void
Encodes a field with data and time value.protected void
putDecimal128
(String name, Decimal128 value) Encodes a Decimal128 field.protected void
putIterable
(String name, Iterable iterable) Encodes an Iterable, for exampleList
valuesprotected void
Encodes a map, as a BSON documentprotected void
Encodes a field to aBsonType.MAX_KEY
value.protected void
Encodes a field to aBsonType.MIN_KEY
value.protected void
Writes a field nameprotected void
Encodes a null valueprotected void
Encodes any number field.protected int
putObject
(String name, BSONObject document) Encodes anyBSONObject
, as a documentint
putObject
(BSONObject document) Encodes aBSONObject
.protected void
putObjectId
(String name, ObjectId objectId) Encodes an ObjectId field to aBsonType.OBJECT_ID
.protected void
putPattern
(String name, Pattern value) Encodes a Pattern field to aBsonType.REGULAR_EXPRESSION
.protected boolean
putSpecial
(String name, Object special) Special values are not encoded into documents.protected void
Encodes a String fieldprotected void
Encodes a Symbol fieldprotected void
putTimestamp
(String name, BSONTimestamp timestamp) Encodes a BSON timestampprotected void
putUndefined
(String name) Encodes an undefined valueprotected void
Encodes a field with aUUID
value.void
set
(OutputBuffer buffer) Sets the buffer to wrich the result of encoding will be written.
-
Constructor Details
-
BasicBSONEncoder
public BasicBSONEncoder()
-
-
Method Details
-
encode
Description copied from interface:BSONEncoder
Encode a document into byte array. This is a shortcut method which creates a newOutputBuffer
, invokes the other 3 methods in a corresponding sequence: and returns the contents of theOutputBuffer
.- Specified by:
encode
in interfaceBSONEncoder
- Parameters:
document
- the document to be encoded- Returns:
- a byte sequence
-
done
public void done()Description copied from interface:BSONEncoder
Free the resources.- Specified by:
done
in interfaceBSONEncoder
-
set
Description copied from interface:BSONEncoder
Sets the buffer to wrich the result of encoding will be written.- Specified by:
set
in interfaceBSONEncoder
- Parameters:
buffer
- the buffer to be used to write a byte sequences to
-
getOutputBuffer
Gets the buffer the BSON is being encoded into.- Returns:
- the OutputBuffer
-
getBsonWriter
Gets the writer responsible for writing the encoded BSON.- Returns:
- the writer used to write the encoded BSON
-
putObject
Encodes aBSONObject
. This is for the higher level api calls.- Specified by:
putObject
in interfaceBSONEncoder
- Parameters:
document
- the document to encode- Returns:
- the number of characters in the encoding
-
putName
Writes a field name- Parameters:
name
- the field name
-
_putObjectField
Encodes any Object type- Parameters:
name
- the field namevalue
- the value to write
-
putNull
Encodes a null value- Parameters:
name
- the field name- See Also:
-
putUndefined
Encodes an undefined value- Parameters:
name
- the field name- See Also:
-
putTimestamp
Encodes a BSON timestamp- Parameters:
name
- the field nametimestamp
- the timestamp to encode- See Also:
-
putCode
Encodes a field to aBsonType.JAVASCRIPT
value.- Parameters:
name
- the field namecode
- the value
-
putCodeWScope
Encodes a field to aBsonType.JAVASCRIPT_WITH_SCOPE
value.- Parameters:
name
- the field namecodeWScope
- the value
-
putBoolean
Encodes a field with aBoolean
orboolean
value- Parameters:
name
- the field namevalue
- the value
-
putDate
Encodes a field with data and time value.- Parameters:
name
- the field namedate
- the value- See Also:
-
putNumber
Encodes any number field.- Parameters:
name
- the field namenumber
- the value
-
putDecimal128
Encodes a Decimal128 field.- Parameters:
name
- the field namevalue
- the value- Since:
- 3.4
- Since server release
- 3.4
-
putBinary
Encodes a byte array field- Parameters:
name
- the field namebytes
- the value- See Also:
-
putBinary
Encodes a Binary field- Parameters:
name
- the field namebinary
- the value- See Also:
-
putUUID
Encodes a field with aUUID
value. This is encoded to a binary value of subtypeBsonBinarySubType.UUID_LEGACY
- Parameters:
name
- the field nameuuid
- the value
-
putSymbol
Encodes a Symbol field- Parameters:
name
- the field namesymbol
- the value- See Also:
-
putString
Encodes a String field- Parameters:
name
- the field namevalue
- the value- See Also:
-
putPattern
Encodes a Pattern field to aBsonType.REGULAR_EXPRESSION
.- Parameters:
name
- the field namevalue
- the value- See Also:
- MongoDB documentation
- $regex
-
putObjectId
Encodes an ObjectId field to aBsonType.OBJECT_ID
.- Parameters:
name
- the field nameobjectId
- the value
-
putArray
Encodes an array field.- Parameters:
name
- the field nameobject
- the array, which can be any sort of primitive or String array
-
putIterable
Encodes an Iterable, for exampleList
values- Parameters:
name
- the field nameiterable
- the value
-
putMap
Encodes a map, as a BSON document- Parameters:
name
- the field namemap
- the value
-
putObject
Encodes anyBSONObject
, as a document- Parameters:
name
- the field namedocument
- the value- Returns:
- the number of characters in the encoding
-
putSpecial
Special values are not encoded into documents.- Parameters:
name
- the field namespecial
- the value- Returns:
- true if the operation is successful. This implementation always returns false.
-
putMinKey
Encodes a field to aBsonType.MIN_KEY
value.- Parameters:
name
- the field name
-
putMaxKey
Encodes a field to aBsonType.MAX_KEY
value.- Parameters:
name
- the field name
-