public class BasicBSONEncoder extends java.lang.Object implements BSONEncoder
Constructor and Description |
---|
BasicBSONEncoder() |
Modifier and Type | Method and Description |
---|---|
protected void |
_putObjectField(java.lang.String name,
java.lang.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(java.lang.String name,
java.lang.Object object)
Encodes an array field.
|
protected void |
putBinary(java.lang.String name,
Binary binary)
Encodes a Binary field
|
protected void |
putBinary(java.lang.String name,
byte[] bytes)
Encodes a byte array field
|
protected void |
putBoolean(java.lang.String name,
java.lang.Boolean value)
Encodes a field with a
Boolean or boolean value |
protected void |
putCode(java.lang.String name,
Code code)
Encodes a field to a
BsonType.JAVASCRIPT value. |
protected void |
putCodeWScope(java.lang.String name,
CodeWScope codeWScope)
Encodes a field to a
BsonType.JAVASCRIPT_WITH_SCOPE value. |
protected void |
putDate(java.lang.String name,
java.util.Date date)
Encodes a field with data and time value.
|
protected void |
putDecimal128(java.lang.String name,
Decimal128 value)
Encodes a Decimal128 field.
|
protected void |
putIterable(java.lang.String name,
java.lang.Iterable iterable)
Encodes an Iterable, for example
List values |
protected void |
putMap(java.lang.String name,
java.util.Map map)
Encodes a map, as a BSON document
|
protected void |
putMaxKey(java.lang.String name)
Encodes a field to a
BsonType.MAX_KEY value. |
protected void |
putMinKey(java.lang.String name)
Encodes a field to a
BsonType.MIN_KEY value. |
protected void |
putName(java.lang.String name)
Writes a field name
|
protected void |
putNull(java.lang.String name)
Encodes a null value
|
protected void |
putNumber(java.lang.String name,
java.lang.Number number)
Encodes any number field.
|
int |
putObject(BSONObject document)
Encodes a
BSONObject . |
protected int |
putObject(java.lang.String name,
BSONObject document)
Encodes any
BSONObject , as a document |
protected void |
putObjectId(java.lang.String name,
ObjectId objectId)
Encodes an ObjectId field to a
BsonType.OBJECT_ID . |
protected void |
putPattern(java.lang.String name,
java.util.regex.Pattern value)
Encodes a Pattern field to a
BsonType.REGULAR_EXPRESSION . |
protected boolean |
putSpecial(java.lang.String name,
java.lang.Object special)
Special values are not encoded into documents.
|
protected void |
putString(java.lang.String name,
java.lang.String value)
Encodes a String field
|
protected void |
putSymbol(java.lang.String name,
Symbol symbol)
Encodes a Symbol field
|
protected void |
putTimestamp(java.lang.String name,
BSONTimestamp timestamp)
Encodes a BSON timestamp
|
protected void |
putUndefined(java.lang.String name)
Encodes an undefined value
|
protected void |
putUUID(java.lang.String name,
java.util.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(java.lang.String name)
name
- the field nameprotected void _putObjectField(java.lang.String name, java.lang.Object initialValue)
name
- the field nameinitialValue
- the value to writeprotected void putNull(java.lang.String name)
name
- the field nameBsonType.NULL
protected void putUndefined(java.lang.String name)
name
- the field nameBsonType.UNDEFINED
protected void putTimestamp(java.lang.String name, BSONTimestamp timestamp)
name
- the field nametimestamp
- the timestamp to encodeBsonType.TIMESTAMP
protected void putCode(java.lang.String name, Code code)
BsonType.JAVASCRIPT
value.name
- the field namecode
- the valueprotected void putCodeWScope(java.lang.String name, CodeWScope codeWScope)
BsonType.JAVASCRIPT_WITH_SCOPE
value.name
- the field namecodeWScope
- the valueprotected void putBoolean(java.lang.String name, java.lang.Boolean value)
Boolean
or boolean
valuename
- the field namevalue
- the valueprotected void putDate(java.lang.String name, java.util.Date date)
name
- the field namedate
- the valueBsonType.DATE_TIME
protected void putNumber(java.lang.String name, java.lang.Number number)
name
- the field namenumber
- the valueprotected void putDecimal128(java.lang.String name, Decimal128 value)
name
- the field namevalue
- the valueprotected void putBinary(java.lang.String name, byte[] bytes)
name
- the field namebytes
- the valueBsonType.BINARY
protected void putBinary(java.lang.String name, Binary binary)
name
- the field namebinary
- the valueBsonType.BINARY
protected void putUUID(java.lang.String name, java.util.UUID uuid)
UUID
value. This is encoded to a binary value of subtype BsonBinarySubType.UUID_LEGACY
name
- the field nameuuid
- the valueprotected void putSymbol(java.lang.String name, Symbol symbol)
name
- the field namesymbol
- the valueBsonType.SYMBOL
protected void putString(java.lang.String name, java.lang.String value)
name
- the field namevalue
- the valueBsonType.STRING
protected void putPattern(java.lang.String name, java.util.regex.Pattern value)
BsonType.REGULAR_EXPRESSION
.name
- the field namevalue
- the valueBsonType.BINARY
protected void putObjectId(java.lang.String name, ObjectId objectId)
BsonType.OBJECT_ID
.name
- the field nameobjectId
- the valueprotected void putArray(java.lang.String name, java.lang.Object object)
name
- the field nameobject
- the array, which can be any sort of primitive or String arrayprotected void putIterable(java.lang.String name, java.lang.Iterable iterable)
List
valuesname
- the field nameiterable
- the valueprotected void putMap(java.lang.String name, java.util.Map map)
name
- the field namemap
- the valueprotected int putObject(java.lang.String name, BSONObject document)
BSONObject
, as a documentname
- the field namedocument
- the valueprotected boolean putSpecial(java.lang.String name, java.lang.Object special)
name
- the field namespecial
- the valueprotected void putMinKey(java.lang.String name)
BsonType.MIN_KEY
value.name
- the field nameprotected void putMaxKey(java.lang.String name)
BsonType.MAX_KEY
value.name
- the field name