BSONEncoder
DefaultDBEncoder
public class BasicBSONEncoder extends Object implements BSONEncoder
Constructor | Description |
---|---|
BasicBSONEncoder() |
Modifier and Type | Method | Description |
---|---|---|
protected void |
_putObjectField(String name,
Object initialValue) |
Encodes any Object type
|
void |
done() |
Free the resources.
|
byte[] |
encode(BSONObject document) |
Encode a document into byte array.
|
protected BsonBinaryWriter |
getBsonWriter() |
Gets the writer responsible for writing the encoded BSON.
|
protected OutputBuffer |
getOutputBuffer() |
Gets the buffer the BSON is being encoded into.
|
protected void |
putArray(String name,
Object object) |
Encodes an array field.
|
protected void |
putBinary(String name,
byte[] bytes) |
Encodes a byte array field
|
protected void |
putBinary(String name,
Binary binary) |
Encodes a Binary field
|
protected void |
putBoolean(String name,
Boolean value) |
Encodes a field with a
Boolean or boolean value |
protected void |
putCode(String name,
Code code) |
Encodes a field to a
BsonType.JAVASCRIPT value. |
protected void |
putCodeWScope(String name,
CodeWScope codeWScope) |
Encodes a field to a
BsonType.JAVASCRIPT_WITH_SCOPE value. |
protected void |
putDate(String name,
Date date) |
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 example
List values |
protected void |
putMap(String name,
Map map) |
Encodes a map, as a BSON document
|
protected void |
putMaxKey(String name) |
Encodes a field to a
BsonType.MAX_KEY value. |
protected void |
putMinKey(String name) |
Encodes a field to a
BsonType.MIN_KEY value. |
protected void |
putName(String name) |
Writes a field name
|
protected void |
putNull(String name) |
Encodes a null value
|
protected void |
putNumber(String name,
Number number) |
Encodes any number field.
|
protected int |
putObject(String name,
BSONObject document) |
Encodes any
BSONObject , as a document |
int |
putObject(BSONObject document) |
Encodes a
BSONObject . |
protected void |
putObjectId(String name,
ObjectId objectId) |
Encodes an ObjectId field to a
BsonType.OBJECT_ID . |
protected void |
putPattern(String name,
Pattern value) |
Encodes a Pattern field to a
BsonType.REGULAR_EXPRESSION . |
protected boolean |
putSpecial(String name,
Object special) |
Special values are not encoded into documents.
|
protected void |
putString(String name,
String value) |
Encodes a String field
|
protected void |
putSymbol(String name,
Symbol symbol) |
Encodes a Symbol field
|
protected void |
putTimestamp(String name,
BSONTimestamp timestamp) |
Encodes a BSON timestamp
|
protected void |
putUndefined(String name) |
Encodes an undefined value
|
protected void |
putUUID(String name,
UUID uuid) |
Encodes a field with a
UUID value. |
void |
set(OutputBuffer buffer) |
Sets the buffer to wrich the result of encoding will be written.
|
public byte[] encode(BSONObject document)
BSONEncoder
OutputBuffer
,
invokes the other 3 methods in a corresponding sequence:
and returns the contents of the OutputBuffer
.encode
in interface BSONEncoder
document
- the document to be encodedpublic void done()
BSONEncoder
done
in interface BSONEncoder
public void set(OutputBuffer buffer)
BSONEncoder
set
in interface BSONEncoder
buffer
- the buffer to be used to write a byte sequences toprotected OutputBuffer getOutputBuffer()
protected BsonBinaryWriter getBsonWriter()
public int putObject(BSONObject document)
BSONObject
. This is for the higher level api calls.putObject
in interface BSONEncoder
document
- the document to encodeprotected void putName(String name)
name
- the field nameprotected void _putObjectField(String name, Object initialValue)
name
- the field nameinitialValue
- the value to writeprotected void putNull(String name)
name
- the field nameBsonType.NULL
protected void putUndefined(String name)
name
- the field nameBsonType.UNDEFINED
protected void putTimestamp(String name, BSONTimestamp timestamp)
name
- the field nametimestamp
- the timestamp to encodeBsonType.TIMESTAMP
protected void putCode(String name, Code code)
BsonType.JAVASCRIPT
value.name
- the field namecode
- the valueprotected void putCodeWScope(String name, CodeWScope codeWScope)
BsonType.JAVASCRIPT_WITH_SCOPE
value.name
- the field namecodeWScope
- the valueprotected void putBoolean(String name, Boolean value)
Boolean
or boolean
valuename
- the field namevalue
- the valueprotected void putDate(String name, Date date)
name
- the field namedate
- the valueBsonType.DATE_TIME
protected void putNumber(String name, Number number)
name
- the field namenumber
- the valueprotected void putDecimal128(String name, Decimal128 value)
name
- the field namevalue
- the valueprotected void putBinary(String name, byte[] bytes)
name
- the field namebytes
- the valueBsonType.BINARY
protected void putBinary(String name, Binary binary)
name
- the field namebinary
- the valueBsonType.BINARY
protected void putUUID(String name, UUID uuid)
UUID
value. This is encoded to a binary value of subtype BsonBinarySubType.UUID_LEGACY
name
- the field nameuuid
- the valueprotected void putSymbol(String name, Symbol symbol)
name
- the field namesymbol
- the valueBsonType.SYMBOL
protected void putString(String name, String value)
name
- the field namevalue
- the valueBsonType.STRING
protected void putPattern(String name, Pattern value)
BsonType.REGULAR_EXPRESSION
.name
- the field namevalue
- the valueBsonType.BINARY
protected void putObjectId(String name, ObjectId objectId)
BsonType.OBJECT_ID
.name
- the field nameobjectId
- the valueprotected void putArray(String name, Object object)
name
- the field nameobject
- the array, which can be any sort of primitive or String arrayprotected void putIterable(String name, Iterable iterable)
List
valuesname
- the field nameiterable
- the valueprotected void putMap(String name, Map map)
name
- the field namemap
- the valueprotected int putObject(String name, BSONObject document)
BSONObject
, as a documentname
- the field namedocument
- the valueprotected boolean putSpecial(String name, Object special)
name
- the field namespecial
- the valueprotected void putMinKey(String name)
BsonType.MIN_KEY
value.name
- the field nameprotected void putMaxKey(String name)
BsonType.MAX_KEY
value.name
- the field name