Package org.bson

Class LazyBSONObject

  • All Implemented Interfaces:
    BSONObject
    Direct Known Subclasses:
    LazyBSONList, LazyDBObject

    public class LazyBSONObject
    extends java.lang.Object
    implements BSONObject
    An immutable BSONObject backed 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean containsField​(java.lang.String s)
      Checks if this object contains a field with the given name.
      boolean containsKey​(java.lang.String key)
      Deprecated.
      java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()
      Gets the entry set for all the key/value pairs in this BSONObject.
      boolean equals​(java.lang.Object o)  
      java.lang.Object get​(java.lang.String key)
      Gets a field from this object by a given name.
      int getBSONSize()
      Gets the size in bytes of the BSON document.
      int hashCode()  
      boolean isEmpty()
      Gets whether this is an empty BSONObject.
      java.util.Set<java.lang.String> keySet()
      Returns this object's fields' names
      int pipe​(java.io.OutputStream os)
      Pipe the raw bytes into the given output stream.
      java.lang.Object put​(java.lang.String key, java.lang.Object v)
      Always throws UnsupportedOperationException.
      void putAll​(java.util.Map m)
      Always throws UnsupportedOperationException.
      void putAll​(BSONObject o)
      Always throws UnsupportedOperationException.
      java.lang.Object removeField​(java.lang.String key)
      Always throws UnsupportedOperationException.
      java.util.Map toMap()
      Returns a map representing this BSONObject.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LazyBSONObject

        public LazyBSONObject​(byte[] bytes,
                              LazyBSONCallback callback)
        Construct an instance.
        Parameters:
        bytes - the raw bytes
        callback - the callback to use to construct nested values
      • LazyBSONObject

        public LazyBSONObject​(byte[] bytes,
                              int offset,
                              LazyBSONCallback callback)
        Construct an instance.
        Parameters:
        bytes - the raw bytes
        offset - the offset into the raw bytes representing the start of the document
        callback - the callback to use to construct nested values
    • Method Detail

      • get

        public java.lang.Object get​(java.lang.String key)
        Description copied from interface: BSONObject
        Gets a field from this object by a given name.
        Specified by:
        get in interface BSONObject
        Parameters:
        key - The name of the field fetch
        Returns:
        The field, if found
      • containsKey

        @Deprecated
        public boolean containsKey​(java.lang.String key)
        Deprecated.
        Description copied from interface: BSONObject
        Deprecated
        Specified by:
        containsKey in interface BSONObject
        Parameters:
        key - the key to check
        Returns:
        True if the key is present
      • containsField

        public boolean containsField​(java.lang.String s)
        Description copied from interface: BSONObject
        Checks if this object contains a field with the given name.
        Specified by:
        containsField in interface BSONObject
        Parameters:
        s - Field name for which to check
        Returns:
        True if the field is present
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Description copied from interface: BSONObject
        Returns this object's fields' names
        Specified by:
        keySet in interface BSONObject
        Returns:
        The names of the fields in this object
      • isEmpty

        public boolean isEmpty()
        Gets whether this is an empty BSONObject.
        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​(java.io.OutputStream os)
                 throws java.io.IOException
        Pipe the raw bytes into the given output stream.
        Parameters:
        os - the output stream
        Returns:
        the number of bytes written
        Throws:
        java.io.IOException - any IOException thrown by the output stream
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> entrySet()
        Gets the entry set for all the key/value pairs in this BSONObject. The returned set is immutable.
        Returns:
        then entry set
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • put

        public java.lang.Object put​(java.lang.String key,
                                    java.lang.Object v)
        Always throws UnsupportedOperationException.
        Specified by:
        put in interface BSONObject
        Parameters:
        key - Name to set
        v - Corresponding value
        Returns:
        will not return normally
        Throws:
        java.lang.UnsupportedOperationException - the object is read only
      • putAll

        public void putAll​(BSONObject o)
        Always throws UnsupportedOperationException.
        Specified by:
        putAll in interface BSONObject
        Parameters:
        o - the object
        Throws:
        java.lang.UnsupportedOperationException - the object is read only
      • putAll

        public void putAll​(java.util.Map m)
        Always throws UnsupportedOperationException.
        Specified by:
        putAll in interface BSONObject
        Parameters:
        m - the map
        Throws:
        java.lang.UnsupportedOperationException - the object is read only
      • removeField

        public java.lang.Object removeField​(java.lang.String key)
        Always throws UnsupportedOperationException.
        Specified by:
        removeField in interface BSONObject
        Parameters:
        key - The name of the field to remove
        Returns:
        will not return normally
        Throws:
        java.lang.UnsupportedOperationException - the object is read only
      • toMap

        public java.util.Map toMap()
        Description copied from interface: BSONObject
        Returns a map representing this BSONObject.
        Specified by:
        toMap in interface BSONObject
        Returns:
        the map