public class BasicBSONEncoder extends Object implements BSONEncoder
Modifier and Type | Field and Description |
---|---|
protected OutputBuffer |
_buf
Deprecated.
Replaced by
getOutputBuffer() . |
Constructor and Description |
---|
BasicBSONEncoder() |
Modifier and Type | Method and Description |
---|---|
protected void |
_put(byte type,
String name)
Deprecated.
This method is NOT a part of public API and will be dropped in 3.x versions.
Access buffer directly via
getOutputBuffer() if you need to change how BSON is written. |
protected int |
_put(String str)
Deprecated.
Replaced by
getOutputBuffer().writeCString(String) . |
protected void |
_putObjectField(String name,
Object val)
Encodes any Object type
|
protected void |
_putValueString(String s)
Deprecated.
This method is NOT a part of public API and will be dropped in 3.x versions.
Access buffer directly via
getOutputBuffer() if you need to change how BSON is written.
Otherwise override putString(String, String) . |
void |
done()
Free the resources.
|
byte[] |
encode(BSONObject o)
Encode a document into byte array.
|
protected OutputBuffer |
getOutputBuffer()
Gets the buffer the BSON is being encoded into.
|
protected boolean |
handleSpecialObjects(String name,
BSONObject o)
Deprecated.
Override
putSpecial(String, Object) if you need to you need to handle custom types. |
protected void |
putBinary(String name,
Binary val)
Encodes a Binary field
|
protected void |
putBinary(String name,
byte[] data)
Encodes a byte array field
|
protected void |
putBoolean(String name,
Boolean b)
Encodes a field with a
Boolean or boolean value |
protected void |
putCode(String name,
Code code)
Encodes a field to a JAVASCRIPT value.
|
protected void |
putCodeWScope(String name,
CodeWScope code)
Encodes a field to a JAVASCRIPT_WITH_SCOPE value.
|
protected void |
putDate(String name,
Date date)
Encodes a field with data and time value.
|
protected void |
putNull(String name)
Encodes a null value
|
protected void |
putNumber(String name,
Number n)
Encodes any number field.
|
int |
putObject(BSONObject o)
Encodes a
BSONObject . |
protected int |
putObject(String name,
BSONObject o)
This is really for embedded objects
|
protected void |
putObjectId(String name,
ObjectId oid)
Encodes an ObjectId field to an OBJECT_ID.
|
protected boolean |
putSpecial(String name,
Object o)
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 ts)
Encodes a BSON timestamp
|
protected void |
putUndefined(String name)
Encodes an undefined value
|
protected void |
putUUID(String name,
UUID val)
Encodes a field with a
UUID value. |
void |
set(OutputBuffer out)
Sets the buffer to wrich the result of encoding will be written.
|
void |
writeCString(String s)
Deprecated.
Replaced by
getOutputBuffer().writeCString(String) . |
void |
writeInt(int x)
Deprecated.
Replaced by
getOutputBuffer().writeInt(int) . |
void |
writeLong(long x)
Deprecated.
Replaced by
getOutputBuffer().writeLong(long) . |
@Deprecated protected OutputBuffer _buf
getOutputBuffer()
.public byte[] encode(BSONObject o)
BSONEncoder
OutputBuffer
, invokes the other 3 methods in
a corresponding sequence:
and returns the contents of the OutputBuffer
.encode
in interface BSONEncoder
o
- the document to be encodedpublic void set(OutputBuffer out)
BSONEncoder
set
in interface BSONEncoder
out
- the buffer to be used to write a byte sequences toprotected OutputBuffer getOutputBuffer()
public void done()
BSONEncoder
done
in interface BSONEncoder
@Deprecated protected boolean handleSpecialObjects(String name, BSONObject o)
putSpecial(String, Object)
if you need to you need to handle custom types.protected boolean putSpecial(String name, Object o)
name
- the field nameo
- the valuepublic int putObject(BSONObject o)
BSONObject
. This is for the higher level api calls.putObject
in interface BSONEncoder
o
- the document to encodeprotected int putObject(String name, BSONObject o)
name
- the field nameo
- the objectprotected void _putObjectField(String name, Object val)
name
- the field nameval
- the value to writeprotected void putNull(String name)
name
- the field nameprotected void putUndefined(String name)
name
- the field nameprotected void putTimestamp(String name, BSONTimestamp ts)
name
- the field namets
- the timestamp to encodeprotected void putCodeWScope(String name, CodeWScope code)
name
- the field namecode
- the valueprotected void putCode(String name, Code code)
name
- the field namecode
- the valueprotected void putBoolean(String name, Boolean b)
Boolean
or boolean
valuename
- the field nameb
- the valueprotected void putDate(String name, Date date)
name
- the field namedate
- the valueprotected void putNumber(String name, Number n)
name
- the field namen
- the numberprotected void putBinary(String name, byte[] data)
name
- the field namedata
- the valueprotected void putBinary(String name, Binary val)
name
- the field nameval
- the valueprotected void putUUID(String name, UUID val)
UUID
value. This is encoded to a binary value of subtype UUID_LEGACYname
- the field nameval
- the valueprotected void putSymbol(String name, Symbol symbol)
name
- the field namesymbol
- the valueprotected void putString(String name, String value)
name
- the field namevalue
- the valueprotected void putObjectId(String name, ObjectId oid)
name
- the field nameoid
- the value@Deprecated protected void _put(byte type, String name)
getOutputBuffer()
if you need to change how BSON is written.@Deprecated protected void _putValueString(String s)
getOutputBuffer()
if you need to change how BSON is written.
Otherwise override putString(String, String)
.@Deprecated protected int _put(String str)
getOutputBuffer().writeCString(String)
.@Deprecated public void writeInt(int x)
getOutputBuffer().writeInt(int)
.x
- the integer number@Deprecated public void writeLong(long x)
getOutputBuffer().writeLong(long)
.x
- the long number@Deprecated public void writeCString(String s)
getOutputBuffer().writeCString(String)
.s
- the string