Class DocumentWriter

  • All Implemented Interfaces:
    org.bson.BsonWriter

    public class DocumentWriter
    extends Object
    implements org.bson.BsonWriter
    Utility to write out to a Document
    • Constructor Detail

      • DocumentWriter

        public DocumentWriter()
        Creates a new Writer
      • DocumentWriter

        public DocumentWriter​(org.bson.Document seed)
        Creates a new Writer with a seeded Document
        Parameters:
        seed - the seed Document
    • Method Detail

      • getRoot

        public <T> T getRoot()
        Type Parameters:
        T - the root type
        Returns:
        the root, or output, of this writer. usually a Document.
      • encode

        public DocumentWriter encode​(org.bson.codecs.configuration.CodecRegistry codecRegistry,
                                     Object value,
                                     org.bson.codecs.EncoderContext encoderContext)
        Encodes a value in to this Writer
        Parameters:
        codecRegistry - the registry to use
        value - the value to encode
        encoderContext - the context
        Returns:
        this
      • flush

        public void flush()
        Description copied from interface: org.bson.BsonWriter
        Flushes any pending data to the output destination.
        Specified by:
        flush in interface org.bson.BsonWriter
      • writeBinaryData

        public void writeBinaryData​(org.bson.BsonBinary binary)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Binary data element to the writer.
        Specified by:
        writeBinaryData in interface org.bson.BsonWriter
        Parameters:
        binary - The Binary data.
      • writeBinaryData

        public void writeBinaryData​(String name,
                                    org.bson.BsonBinary binary)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Binary data element to the writer.
        Specified by:
        writeBinaryData in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        binary - The Binary data value.
      • writeBoolean

        public void writeBoolean​(boolean value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Boolean to the writer.
        Specified by:
        writeBoolean in interface org.bson.BsonWriter
        Parameters:
        value - The Boolean value.
      • writeBoolean

        public void writeBoolean​(String name,
                                 boolean value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Boolean element to the writer.
        Specified by:
        writeBoolean in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The Boolean value.
      • writeDateTime

        public void writeDateTime​(long value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON DateTime to the writer.
        Specified by:
        writeDateTime in interface org.bson.BsonWriter
        Parameters:
        value - The number of milliseconds since the Unix epoch.
      • writeDateTime

        public void writeDateTime​(String name,
                                  long value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON DateTime element to the writer.
        Specified by:
        writeDateTime in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The number of milliseconds since the Unix epoch.
      • writeDBPointer

        public void writeDBPointer​(org.bson.BsonDbPointer value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON DBPointer to the writer.
        Specified by:
        writeDBPointer in interface org.bson.BsonWriter
        Parameters:
        value - The DBPointer to write
      • writeDBPointer

        public void writeDBPointer​(String name,
                                   org.bson.BsonDbPointer value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON DBPointer element to the writer.
        Specified by:
        writeDBPointer in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The DBPointer to write
      • writeDouble

        public void writeDouble​(double value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Double to the writer.
        Specified by:
        writeDouble in interface org.bson.BsonWriter
        Parameters:
        value - The Double value.
      • writeDouble

        public void writeDouble​(String name,
                                double value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Double element to the writer.
        Specified by:
        writeDouble in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The Double value.
      • writeEndArray

        public void writeEndArray()
        Description copied from interface: org.bson.BsonWriter
        Writes the end of a BSON array to the writer.
        Specified by:
        writeEndArray in interface org.bson.BsonWriter
      • writeEndDocument

        public void writeEndDocument()
        Description copied from interface: org.bson.BsonWriter
        Writes the end of a BSON document to the writer.
        Specified by:
        writeEndDocument in interface org.bson.BsonWriter
      • writeInt32

        public void writeInt32​(int value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Int32 to the writer.
        Specified by:
        writeInt32 in interface org.bson.BsonWriter
        Parameters:
        value - The Int32 value.
      • writeInt32

        public void writeInt32​(String name,
                               int value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Int32 element to the writer.
        Specified by:
        writeInt32 in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The Int32 value.
      • writeInt64

        public void writeInt64​(long value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Int64 to the writer.
        Specified by:
        writeInt64 in interface org.bson.BsonWriter
        Parameters:
        value - The Int64 value.
      • writeInt64

        public void writeInt64​(String name,
                               long value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Int64 element to the writer.
        Specified by:
        writeInt64 in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The Int64 value.
      • writeDecimal128

        public void writeDecimal128​(org.bson.types.Decimal128 value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Decimal128 to the writer.
        Specified by:
        writeDecimal128 in interface org.bson.BsonWriter
        Parameters:
        value - The Decimal128 value.
      • writeDecimal128

        public void writeDecimal128​(String name,
                                    org.bson.types.Decimal128 value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Decimal128 element to the writer.
        Specified by:
        writeDecimal128 in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The Decimal128 value.
      • writeJavaScript

        public void writeJavaScript​(String code)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON JavaScript to the writer.
        Specified by:
        writeJavaScript in interface org.bson.BsonWriter
        Parameters:
        code - The JavaScript code.
      • writeJavaScript

        public void writeJavaScript​(String name,
                                    String code)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON JavaScript element to the writer.
        Specified by:
        writeJavaScript in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        code - The JavaScript code.
      • writeJavaScriptWithScope

        public void writeJavaScriptWithScope​(String code)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
        Specified by:
        writeJavaScriptWithScope in interface org.bson.BsonWriter
        Parameters:
        code - The JavaScript code.
      • writeJavaScriptWithScope

        public void writeJavaScriptWithScope​(String name,
                                             String code)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).
        Specified by:
        writeJavaScriptWithScope in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        code - The JavaScript code.
      • writeMaxKey

        public void writeMaxKey()
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON MaxKey to the writer.
        Specified by:
        writeMaxKey in interface org.bson.BsonWriter
      • writeMaxKey

        public void writeMaxKey​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON MaxKey element to the writer.
        Specified by:
        writeMaxKey in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeMinKey

        public void writeMinKey()
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON MinKey to the writer.
        Specified by:
        writeMinKey in interface org.bson.BsonWriter
      • writeMinKey

        public void writeMinKey​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON MinKey element to the writer.
        Specified by:
        writeMinKey in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeName

        public void writeName​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes the name of an element to the writer.
        Specified by:
        writeName in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeNull

        public void writeNull()
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON null to the writer.
        Specified by:
        writeNull in interface org.bson.BsonWriter
      • writeNull

        public void writeNull​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON null element to the writer.
        Specified by:
        writeNull in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeObjectId

        public void writeObjectId​(org.bson.types.ObjectId objectId)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON ObjectId to the writer.
        Specified by:
        writeObjectId in interface org.bson.BsonWriter
        Parameters:
        objectId - The ObjectId value.
      • writeObjectId

        public void writeObjectId​(String name,
                                  org.bson.types.ObjectId objectId)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON ObjectId element to the writer.
        Specified by:
        writeObjectId in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        objectId - The ObjectId value.
      • writeRegularExpression

        public void writeRegularExpression​(org.bson.BsonRegularExpression regularExpression)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON regular expression to the writer.
        Specified by:
        writeRegularExpression in interface org.bson.BsonWriter
        Parameters:
        regularExpression - the regular expression to write.
      • writeRegularExpression

        public void writeRegularExpression​(String name,
                                           org.bson.BsonRegularExpression regularExpression)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON regular expression element to the writer.
        Specified by:
        writeRegularExpression in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        regularExpression - The RegularExpression value.
      • writeStartArray

        public void writeStartArray()
        Description copied from interface: org.bson.BsonWriter
        Writes the start of a BSON array to the writer.
        Specified by:
        writeStartArray in interface org.bson.BsonWriter
      • writeStartArray

        public void writeStartArray​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes the start of a BSON array element to the writer.
        Specified by:
        writeStartArray in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeStartDocument

        public void writeStartDocument()
        Description copied from interface: org.bson.BsonWriter
        Writes the start of a BSON document to the writer.
        Specified by:
        writeStartDocument in interface org.bson.BsonWriter
      • writeStartDocument

        public void writeStartDocument​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes the start of a BSON document element to the writer.
        Specified by:
        writeStartDocument in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • writeString

        public void writeString​(String value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON String to the writer.
        Specified by:
        writeString in interface org.bson.BsonWriter
        Parameters:
        value - The String value.
      • writeString

        public void writeString​(String name,
                                String value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON String element to the writer.
        Specified by:
        writeString in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The String value.
      • writeSymbol

        public void writeSymbol​(String value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Symbol to the writer.
        Specified by:
        writeSymbol in interface org.bson.BsonWriter
        Parameters:
        value - The symbol.
      • writeSymbol

        public void writeSymbol​(String name,
                                String value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Symbol element to the writer.
        Specified by:
        writeSymbol in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The symbol.
      • writeTimestamp

        public void writeTimestamp​(org.bson.BsonTimestamp value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Timestamp to the writer.
        Specified by:
        writeTimestamp in interface org.bson.BsonWriter
        Parameters:
        value - The combined timestamp/increment value.
      • writeTimestamp

        public void writeTimestamp​(String name,
                                   org.bson.BsonTimestamp value)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON Timestamp element to the writer.
        Specified by:
        writeTimestamp in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
        value - The combined timestamp/increment value.
      • writeUndefined

        public void writeUndefined()
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON undefined to the writer.
        Specified by:
        writeUndefined in interface org.bson.BsonWriter
      • writeUndefined

        public void writeUndefined​(String name)
        Description copied from interface: org.bson.BsonWriter
        Writes a BSON undefined element to the writer.
        Specified by:
        writeUndefined in interface org.bson.BsonWriter
        Parameters:
        name - The name of the element.
      • pipe

        public void pipe​(org.bson.BsonReader reader)
        Description copied from interface: org.bson.BsonWriter
        Reads a single document from a BsonReader and writes it to this.
        Specified by:
        pipe in interface org.bson.BsonWriter
        Parameters:
        reader - The source.