Package org.bson
Class LazyBSONObject
- java.lang.Object
-
- org.bson.LazyBSONObject
-
- All Implemented Interfaces:
BSONObject
- Direct Known Subclasses:
LazyBSONList,LazyDBObject
public class LazyBSONObject extends Object implements BSONObject
An immutableBSONObjectbacked by a byte buffer that lazily provides keys and values on request. This is useful for transferring BSON documents between servers when you don't want to pay the performance penalty of encoding or decoding them fully.
-
-
Constructor Summary
Constructors Constructor Description LazyBSONObject(byte[] bytes, int offset, LazyBSONCallback callback)Construct an instance.LazyBSONObject(byte[] bytes, LazyBSONCallback callback)Construct an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontainsField(String s)Checks if this object contains a field with the given name.booleancontainsKey(String key)Deprecated.Set<Map.Entry<String,Object>>entrySet()Gets the entry set for all the key/value pairs in thisBSONObject.booleanequals(Object o)Objectget(String key)Gets a field from this object by a given name.intgetBSONSize()Gets the size in bytes of the BSON document.protected byte[]getBytes()Gets the raw bytes.protected intgetOffset()Gets the offset into the raw bytes representing the start of the documentinthashCode()booleanisEmpty()Gets whether this is an emptyBSONObject.Set<String>keySet()Returns this object's fields' namesintpipe(OutputStream os)Pipe the raw bytes into the given output stream.Objectput(String key, Object v)Always throwsUnsupportedOperationException.voidputAll(Map m)Always throwsUnsupportedOperationException.voidputAll(BSONObject o)Always throwsUnsupportedOperationException.ObjectremoveField(String key)Always throwsUnsupportedOperationException.MaptoMap()Returns a map representing this BSONObject.
-
-
-
Constructor Detail
-
LazyBSONObject
public LazyBSONObject(byte[] bytes, LazyBSONCallback callback)Construct an instance.- Parameters:
bytes- the raw bytescallback- the callback to use to construct nested values
-
LazyBSONObject
public LazyBSONObject(byte[] bytes, int offset, LazyBSONCallback callback)Construct an instance.- Parameters:
bytes- the raw bytesoffset- the offset into the raw bytes representing the start of the documentcallback- the callback to use to construct nested values
-
-
Method Detail
-
getOffset
protected int getOffset()
Gets the offset into the raw bytes representing the start of the document- Returns:
- the offset
-
getBytes
protected byte[] getBytes()
Gets the raw bytes.- Returns:
- the raw bytes
-
get
public Object get(String key)
Description copied from interface:BSONObjectGets a field from this object by a given name.- Specified by:
getin interfaceBSONObject- Parameters:
key- The name of the field fetch- Returns:
- The field, if found
-
containsKey
@Deprecated public boolean containsKey(String key)
Deprecated.Description copied from interface:BSONObjectDeprecated- Specified by:
containsKeyin interfaceBSONObject- Parameters:
key- the key to check- Returns:
- True if the key is present
-
containsField
public boolean containsField(String s)
Description copied from interface:BSONObjectChecks if this object contains a field with the given name.- Specified by:
containsFieldin interfaceBSONObject- Parameters:
s- Field name for which to check- Returns:
- True if the field is present
-
keySet
public Set<String> keySet()
Description copied from interface:BSONObjectReturns this object's fields' names- Specified by:
keySetin interfaceBSONObject- Returns:
- The names of the fields in this object
-
isEmpty
public boolean isEmpty()
Gets whether this is an emptyBSONObject.- Returns:
- true if this has no keys
-
getBSONSize
public int getBSONSize()
Gets the size in bytes of the BSON document.- Returns:
- the size in bytes
-
pipe
public int pipe(OutputStream os) throws IOException
Pipe the raw bytes into the given output stream.- Parameters:
os- the output stream- Returns:
- the number of bytes written
- Throws:
IOException- any IOException thrown by the output stream
-
entrySet
public Set<Map.Entry<String,Object>> entrySet()
Gets the entry set for all the key/value pairs in thisBSONObject. The returned set is immutable.- Returns:
- then entry set
-
put
public Object put(String key, Object v)
Always throwsUnsupportedOperationException.- Specified by:
putin interfaceBSONObject- Parameters:
key- Name to setv- Corresponding value- Returns:
- will not return normally
- Throws:
UnsupportedOperationException- the object is read only
-
putAll
public void putAll(BSONObject o)
Always throwsUnsupportedOperationException.- Specified by:
putAllin interfaceBSONObject- Parameters:
o- the object- Throws:
UnsupportedOperationException- the object is read only
-
putAll
public void putAll(Map m)
Always throwsUnsupportedOperationException.- Specified by:
putAllin interfaceBSONObject- Parameters:
m- the map- Throws:
UnsupportedOperationException- the object is read only
-
removeField
public Object removeField(String key)
Always throwsUnsupportedOperationException.- Specified by:
removeFieldin interfaceBSONObject- Parameters:
key- The name of the field to remove- Returns:
- will not return normally
- Throws:
UnsupportedOperationException- the object is read only
-
toMap
public Map toMap()
Description copied from interface:BSONObjectReturns a map representing this BSONObject.- Specified by:
toMapin interfaceBSONObject- Returns:
- the map
-
-