public class BasicBSONDecoder extends Object implements BSONDecoder
In driver versions before 2.12 BasicBSONDecoder
exposed several protected members to its subclasses:
protected BSONInput _in
protected BSONCallback _callback
protected int _len
protected int _pos
protected void _binary(String)
protected class BSONInput
BSONCallback
implementationWith callbacks you can handle the process of creating objects from bytes in BSON format.
For example to get away from overriging BasicBSONDecoder._binary(String)
you can use the following piece of code:
public class CustomBSONCallback extends BasicBSONCallback {
public void gotBinary(String name, byte type, byte[] data) {
_put(name,toHex(data));
}
private static String toHex(byte[] bytes) {...}
}
This solution covers majority of the cases.
BSONDecoder
implementationIf you need to customize byte-level decoding at the lowest layer you have to provide you own
implementation of the BSONDecoder
interface.
Please check http://bsonspec.org/ for more information.
Modifier and Type | Class and Description |
---|---|
protected class |
BasicBSONDecoder.BSONInput
Deprecated.
This class should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
Modifier and Type | Field and Description |
---|---|
protected BSONCallback |
_callback
Deprecated.
This field should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
protected BasicBSONDecoder.BSONInput |
_in
Deprecated.
This field should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
protected int |
_len
Deprecated.
This field should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
protected int |
_pos
Deprecated.
This field should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
Constructor and Description |
---|
BasicBSONDecoder() |
Modifier and Type | Method and Description |
---|---|
protected void |
_binary(String name)
Deprecated.
This method should not be a part of API.
Please see the class-level documentation for a migration instructions.
|
int |
decode(byte[] b,
BSONCallback callback)
Decode a single BSON object into the given callback from the given byte array.
|
int |
decode(InputStream in,
BSONCallback callback)
Decode a single BSON object into the given callback from the given input stream.
|
BSONObject |
readObject(byte[] b)
Read a single BSON object from the given bytes.
|
BSONObject |
readObject(InputStream in)
Read a single BSON object from the given input stream.
|
@Deprecated protected BasicBSONDecoder.BSONInput _in
@Deprecated protected BSONCallback _callback
@Deprecated protected int _pos
@Deprecated protected int _len
public BSONObject readObject(byte[] b)
BSONDecoder
readObject
in interface BSONDecoder
b
- the bytes in BSON formatpublic BSONObject readObject(InputStream in) throws IOException
BSONDecoder
readObject
in interface BSONDecoder
in
- the input stream in BSON formatIOException
- if there's a problem reading the object from the InputStream
public int decode(byte[] b, BSONCallback callback)
BSONDecoder
decode
in interface BSONDecoder
b
- the bytes in BSON formatcallback
- the callbackpublic int decode(InputStream in, BSONCallback callback) throws IOException
BSONDecoder
decode
in interface BSONDecoder
in
- the input stream in BSON formatcallback
- the callbackIOException
- if there's a problem reading from the InputStream
@Deprecated protected void _binary(String name) throws IOException
name
- the field nameIOException