public class BasicBSONEncoder extends java.lang.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,
java.lang.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(java.lang.String str)
Deprecated.
Replaced by
getOutputBuffer().writeCString(String). |
protected void |
_putObjectField(java.lang.String name,
java.lang.Object val)
Encodes any Object type
|
protected void |
_putValueString(java.lang.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(java.lang.String name,
BSONObject o)
Deprecated.
Override
putSpecial(String, Object) if you need to you need to handle custom types. |
protected void |
putBinary(java.lang.String name,
Binary val)
Encodes a Binary field
|
protected void |
putBinary(java.lang.String name,
byte[] data)
Encodes a byte array field
|
protected void |
putBoolean(java.lang.String name,
java.lang.Boolean b)
Encodes a field with a
Boolean or boolean value |
protected void |
putCode(java.lang.String name,
Code code)
Encodes a field to a JAVASCRIPT value.
|
protected void |
putCodeWScope(java.lang.String name,
CodeWScope code)
Encodes a field to a 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 |
putNull(java.lang.String name)
Encodes a null value
|
protected void |
putNumber(java.lang.String name,
java.lang.Number n)
Encodes any number field.
|
int |
putObject(BSONObject o)
Encodes a
BSONObject. |
protected int |
putObject(java.lang.String name,
BSONObject o)
This is really for embedded objects
|
protected void |
putObjectId(java.lang.String name,
ObjectId oid)
Encodes an ObjectId field to an OBJECT_ID.
|
protected boolean |
putSpecial(java.lang.String name,
java.lang.Object o)
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 ts)
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 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(java.lang.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)
BSONEncoderOutputBuffer, invokes the other 3 methods in
a corresponding sequence:
and returns the contents of the OutputBuffer.encode in interface BSONEncodero - the document to be encodedpublic void set(OutputBuffer out)
BSONEncoderset in interface BSONEncoderout - the buffer to be used to write a byte sequences toprotected OutputBuffer getOutputBuffer()
public void done()
BSONEncoderdone in interface BSONEncoder@Deprecated
protected boolean handleSpecialObjects(java.lang.String name,
BSONObject o)
putSpecial(String, Object) if you need to you need to handle custom types.protected boolean putSpecial(java.lang.String name,
java.lang.Object o)
name - the field nameo - the valuepublic int putObject(BSONObject o)
BSONObject. This is for the higher level api calls.putObject in interface BSONEncodero - the document to encodeprotected int putObject(java.lang.String name,
BSONObject o)
name - the field nameo - the objectprotected void _putObjectField(java.lang.String name,
java.lang.Object val)
name - the field nameval - the value to writeprotected void putNull(java.lang.String name)
name - the field nameprotected void putUndefined(java.lang.String name)
name - the field nameprotected void putTimestamp(java.lang.String name,
BSONTimestamp ts)
name - the field namets - the timestamp to encodeprotected void putCodeWScope(java.lang.String name,
CodeWScope code)
name - the field namecode - the valueprotected void putCode(java.lang.String name,
Code code)
name - the field namecode - the valueprotected void putBoolean(java.lang.String name,
java.lang.Boolean b)
Boolean or boolean valuename - the field nameb - the valueprotected void putDate(java.lang.String name,
java.util.Date date)
name - the field namedate - the valueprotected void putNumber(java.lang.String name,
java.lang.Number n)
name - the field namen - the numberprotected void putBinary(java.lang.String name,
byte[] data)
name - the field namedata - the valueprotected void putBinary(java.lang.String name,
Binary val)
name - the field nameval - the valueprotected void putUUID(java.lang.String name,
java.util.UUID val)
UUID value. This is encoded to a binary value of subtype UUID_LEGACYname - the field nameval - the valueprotected void putSymbol(java.lang.String name,
Symbol symbol)
name - the field namesymbol - the valueprotected void putString(java.lang.String name,
java.lang.String value)
name - the field namevalue - the valueprotected void putObjectId(java.lang.String name,
ObjectId oid)
name - the field nameoid - the value@Deprecated
protected void _put(byte type,
java.lang.String name)
getOutputBuffer() if you need to change how BSON is written.@Deprecated protected void _putValueString(java.lang.String s)
getOutputBuffer() if you need to change how BSON is written.
Otherwise override putString(String, String).@Deprecated protected int _put(java.lang.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(java.lang.String s)
getOutputBuffer().writeCString(String).s - the string