public class BSON extends Object
Transformer
Modifier and Type | Field and Description |
---|---|
static byte |
ARRAY |
static byte |
B_BINARY |
static byte |
B_FUNC |
static byte |
B_GENERAL |
static byte |
B_UUID |
static byte |
BINARY |
static byte |
BOOLEAN |
static byte |
CODE |
static byte |
CODE_W_SCOPE |
static byte |
DATE |
static byte |
EOO |
static byte |
MAXKEY |
static byte |
MINKEY |
static byte |
NULL |
static byte |
NUMBER |
static byte |
NUMBER_INT |
static byte |
NUMBER_LONG |
static byte |
OBJECT |
static byte |
OID |
static byte |
REF |
static byte |
REGEX |
static byte |
STRING |
static byte |
SYMBOL |
static byte |
TIMESTAMP |
static byte |
UNDEFINED |
Constructor and Description |
---|
BSON() |
Modifier and Type | Method and Description |
---|---|
static void |
addDecodingHook(Class<?> clazz,
Transformer transformer)
Registers a
Transformer to use when decoding a specific class from BSON. |
static void |
addEncodingHook(Class<?> clazz,
Transformer transformer)
Registers a
Transformer to use to encode a specific class into BSON. |
static Object |
applyDecodingHooks(Object objectToDecode)
Transforms the
objectToDecode using all transformers registered for the class of this object. |
static Object |
applyEncodingHooks(Object objectToEncode)
Transforms the
objectToEncode using all transformers registered for the class of this object. |
static void |
clearAllHooks()
Remove all decoding and encoding hooks for all classes.
|
static void |
clearDecodingHooks()
Clears all decoding hooks.
|
static void |
clearEncodingHooks()
Clears all encoding hooks.
|
static BSONObject |
decode(byte[] bytes)
Decodes a BSON byte array into a DBObject instance.
|
static byte[] |
encode(BSONObject doc)
Encodes a DBObject as a BSON byte array.
|
static List<Transformer> |
getDecodingHooks(Class<?> clazz)
Returns the decoding hook(s) associated with the specific class
|
static List<Transformer> |
getEncodingHooks(Class<?> clazz)
Returns the encoding hook(s) associated with the specified class.
|
static boolean |
hasDecodeHooks()
Gets whether any decoding transformers have been registered for any classes.
|
static boolean |
hasEncodeHooks()
Gets whether any encoding transformers have been registered for any classes.
|
static int |
regexFlag(char c)
Converts a regular expression modifier from the database into Java regular expression flags.
|
static String |
regexFlags(int flags)
Converts Java regular expression flags into regular expression modifiers from the database.
|
static int |
regexFlags(String s)
Converts a sequence of regular expression modifiers from the database into Java regular expression flags.
|
static void |
removeDecodingHook(Class<?> clazz,
Transformer transformer)
Remove a specific encoding hook for a specific class.
|
static void |
removeDecodingHooks(Class<?> clazz)
Remove all decoding hooks for a specific class.
|
static void |
removeEncodingHook(Class<?> clazz,
Transformer transformer)
Remove a specific encoding hook for a specific class.
|
static void |
removeEncodingHooks(Class<?> clazz)
Remove all encoding hooks for a specific class.
|
static int |
toInt(Object number)
Provides an integer representation of Boolean or Number.
|
public static final byte EOO
public static final byte NUMBER
public static final byte STRING
public static final byte OBJECT
public static final byte ARRAY
public static final byte BINARY
public static final byte UNDEFINED
public static final byte OID
public static final byte BOOLEAN
public static final byte DATE
public static final byte NULL
public static final byte REGEX
public static final byte REF
public static final byte CODE
public static final byte SYMBOL
public static final byte CODE_W_SCOPE
public static final byte NUMBER_INT
public static final byte TIMESTAMP
public static final byte NUMBER_LONG
public static final byte MINKEY
public static final byte MAXKEY
public static final byte B_GENERAL
public static final byte B_FUNC
public static final byte B_BINARY
public static final byte B_UUID
public static boolean hasEncodeHooks()
public static boolean hasDecodeHooks()
public static void addEncodingHook(Class<?> clazz, Transformer transformer)
Transformer
to use to encode a specific class into BSON.clazz
- the class to be transformed during encodingtransformer
- the transformer to use during encodingpublic static void addDecodingHook(Class<?> clazz, Transformer transformer)
Transformer
to use when decoding a specific class from BSON. This class will be one of the basic types supported
by BSON.clazz
- the class to be transformed during decodingtransformer
- the transformer to use during decodingpublic static Object applyEncodingHooks(Object objectToEncode)
objectToEncode
using all transformers registered for the class of this object.objectToEncode
- the object being written to BSON.public static Object applyDecodingHooks(Object objectToDecode)
objectToDecode
using all transformers registered for the class of this object.objectToDecode
- the BSON object to decodepublic static List<Transformer> getEncodingHooks(Class<?> clazz)
clazz
- the class to fetch the encoding hooks forpublic static void clearEncodingHooks()
public static void removeEncodingHooks(Class<?> clazz)
clazz
- the class to remove all the decoding hooks forpublic static void removeEncodingHook(Class<?> clazz, Transformer transformer)
transformer
passed as the parameter must be equals
to the
transformer to remove.clazz
- the class to remove the encoding hook fortransformer
- the specific encoding hook to remove.public static List<Transformer> getDecodingHooks(Class<?> clazz)
clazz
- the class to fetch the decoding hooks forpublic static void clearDecodingHooks()
public static void removeDecodingHooks(Class<?> clazz)
clazz
- the class to remove all the decoding hooks forpublic static void removeDecodingHook(Class<?> clazz, Transformer transformer)
transformer
passed as the parameter must be equals
to the
transformer to remove.clazz
- the class to remove the decoding hook fortransformer
- the specific decoding hook to remove.public static void clearAllHooks()
public static byte[] encode(BSONObject doc)
doc
- the document to encodepublic static BSONObject decode(byte[] bytes)
bytes
- a document encoded as BSONpublic static int regexFlags(String s)
s
- regular expression modifiersIllegalArgumentException
- If sequence contains invalid flags.public static int regexFlag(char c)
c
- regular expression modifierIllegalArgumentException
- If sequence contains invalid flags.public static String regexFlags(int flags)
flags
- the Java flagsIllegalArgumentException
- if some flags couldn't be recognized.public static int toInt(Object number)
Boolean
, then 1
for true
will be
returned or @{code 0} otherwise. If argument is Number
, then Number.intValue()
will be called.number
- the number to convert to an intIllegalArgumentException
- if the argument is null
or not Boolean
or Number