Package org.bson

Class RawBsonDocument

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​BsonValue>, Bson

    public final class RawBsonDocument
    extends BsonDocument
    An immutable BSON document that is represented using only the raw bytes.
    Since:
    3.0
    See Also:
    Serialized Form
    • Constructor Detail

      • RawBsonDocument

        public RawBsonDocument​(byte[] bytes)
        Constructs a new instance with the given byte array. Note that it does not make a copy of the array, so do not modify it after passing it to this constructor.
        Parameters:
        bytes - the bytes representing a BSON document. Note that the byte array is NOT copied, so care must be taken not to modify it after passing it to this construction, unless of course that is your intention.
      • RawBsonDocument

        public RawBsonDocument​(byte[] bytes,
                               int offset,
                               int length)
        Constructs a new instance with the given byte array, offset, and length. Note that it does not make a copy of the array, so do not modify it after passing it to this constructor.
        Parameters:
        bytes - the bytes representing a BSON document. Note that the byte array is NOT copied, so care must be taken not to modify it after passing it to this construction, unless of course that is your intention.
        offset - the offset into the byte array
        length - the length of the subarray to use
        Since:
        3.3
      • RawBsonDocument

        public RawBsonDocument​(T document,
                               Codec<T> codec)
        Construct a new instance from the given document and codec for the document type.
        Type Parameters:
        T - the BSON type that the codec encodes/decodes
        Parameters:
        document - the document to transform
        codec - the codec to facilitate the transformation
    • Method Detail

      • parse

        public static RawBsonDocument parse​(java.lang.String json)
        Parses a string in MongoDB Extended JSON format to a RawBsonDocument
        Parameters:
        json - the JSON string
        Returns:
        a corresponding RawBsonDocument object
        Since:
        3.3
        See Also:
        JsonReader
      • getByteBuffer

        public ByteBuf getByteBuffer()
        Returns a ByteBuf that wraps the byte array, with the proper byte order. Any changes made to the returned will be reflected in the underlying byte array owned by this instance.
        Returns:
        a byte buffer that wraps the byte array owned by this instance.
      • decode

        public <T> T decode​(Codec<T> codec)
        Decode this into a document.
        Type Parameters:
        T - the BSON type that the codec encodes/decodes
        Parameters:
        codec - the codec to facilitate the transformation
        Returns:
        the decoded document
      • decode

        public <T> T decode​(Decoder<T> decoder)
        Decode this into a document.
        Type Parameters:
        T - the BSON type that the codec encodes/decodes
        Parameters:
        decoder - the decoder to facilitate the transformation
        Returns:
        the decoded document
        Since:
        3.6
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        clear in class BsonDocument
      • append

        public BsonDocument append​(java.lang.String key,
                                   BsonValue value)
        Description copied from class: BsonDocument
        Put the given key and value into this document, and return the document.
        Overrides:
        append in class BsonDocument
        Parameters:
        key - the key
        value - the value
        Returns:
        this
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​? extends BsonValue> m)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        putAll in class BsonDocument
      • remove

        public BsonValue remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        remove in class BsonDocument
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        isEmpty in class BsonDocument
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        size in class BsonDocument
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​BsonValue>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        entrySet in class BsonDocument
      • values

        public java.util.Collection<BsonValue> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        values in class BsonDocument
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        keySet in class BsonDocument
      • getFirstKey

        public java.lang.String getFirstKey()
        Description copied from class: BsonDocument
        Gets the first key in the document.
        Overrides:
        getFirstKey in class BsonDocument
        Returns:
        the first key in the document
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        containsKey in class BsonDocument
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        containsValue in class BsonDocument
      • get

        public BsonValue get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        get in class BsonDocument
      • toJson

        public java.lang.String toJson​(JsonWriterSettings settings)
        Description copied from class: BsonDocument
        Gets a JSON representation of this document using the given JsonWriterSettings.
        Overrides:
        toJson in class BsonDocument
        Parameters:
        settings - the JSON writer settings
        Returns:
        a JSON representation of this document
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        equals in class BsonDocument
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,​BsonValue>
        Overrides:
        hashCode in class BsonDocument