Package org.bson

Class BsonBinaryWriter

All Implemented Interfaces:
Closeable, AutoCloseable, BsonWriter

public class BsonBinaryWriter extends AbstractBsonWriter
A BsonWriter implementation that writes to a binary stream of data. This is the most commonly used implementation.
Since:
3.0
  • Constructor Details

    • BsonBinaryWriter

      public BsonBinaryWriter(BsonOutput bsonOutput, FieldNameValidator validator)
      Construct an instance.
      Parameters:
      bsonOutput - the output to write to
      validator - the field name validator to apply
    • BsonBinaryWriter

      public BsonBinaryWriter(BsonOutput bsonOutput)
      Construct an instance.
      Parameters:
      bsonOutput - the output to write to
    • BsonBinaryWriter

      public BsonBinaryWriter(BsonWriterSettings settings, BsonBinaryWriterSettings binaryWriterSettings, BsonOutput bsonOutput)
      Construct an instance.
      Parameters:
      settings - the generic BsonWriter settings
      binaryWriterSettings - the settings specific to a BsonBinaryWriter
      bsonOutput - the output to write to
    • BsonBinaryWriter

      public BsonBinaryWriter(BsonWriterSettings settings, BsonBinaryWriterSettings binaryWriterSettings, BsonOutput bsonOutput, FieldNameValidator validator)
      Construct an instance.
      Parameters:
      settings - the generic BsonWriter settings
      binaryWriterSettings - the settings specific to a BsonBinaryWriter
      bsonOutput - the output to write to
      validator - the field name validator to apply
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class AbstractBsonWriter
    • getBsonOutput

      public BsonOutput getBsonOutput()
      Gets the BSON output backing this instance.
      Returns:
      the BSON output
    • getBinaryWriterSettings

      public BsonBinaryWriterSettings getBinaryWriterSettings()
      Returns:
      the BsonBinaryWriterSettings
      Since:
      3.6
    • getContext

      protected BsonBinaryWriter.Context getContext()
      Description copied from class: AbstractBsonWriter
      Get the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.
      Overrides:
      getContext in class AbstractBsonWriter
      Returns:
      the current context.
    • doWriteStartDocument

      protected void doWriteStartDocument()
      Description copied from class: AbstractBsonWriter
      Handles the logic to start writing a document
      Specified by:
      doWriteStartDocument in class AbstractBsonWriter
    • doWriteEndDocument

      protected void doWriteEndDocument()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing the end of a document
      Specified by:
      doWriteEndDocument in class AbstractBsonWriter
    • doWriteStartArray

      protected void doWriteStartArray()
      Description copied from class: AbstractBsonWriter
      Handles the logic to start writing an array
      Specified by:
      doWriteStartArray in class AbstractBsonWriter
    • doWriteEndArray

      protected void doWriteEndArray()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing the end of an array
      Specified by:
      doWriteEndArray in class AbstractBsonWriter
    • doWriteBinaryData

      protected void doWriteBinaryData(BsonBinary value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a BsonBinary value
      Specified by:
      doWriteBinaryData in class AbstractBsonWriter
      Parameters:
      value - the BsonBinary value to write
    • doWriteBoolean

      public void doWriteBoolean(boolean value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a boolean value
      Specified by:
      doWriteBoolean in class AbstractBsonWriter
      Parameters:
      value - the boolean value to write
    • doWriteDateTime

      protected void doWriteDateTime(long value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a date time value
      Specified by:
      doWriteDateTime in class AbstractBsonWriter
      Parameters:
      value - the long value to write
    • doWriteDBPointer

      protected void doWriteDBPointer(BsonDbPointer value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a DbPointer value
      Specified by:
      doWriteDBPointer in class AbstractBsonWriter
      Parameters:
      value - the BsonDbPointer value to write
    • doWriteDouble

      protected void doWriteDouble(double value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Double value
      Specified by:
      doWriteDouble in class AbstractBsonWriter
      Parameters:
      value - the double value to write
    • doWriteInt32

      protected void doWriteInt32(int value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing an int32 value
      Specified by:
      doWriteInt32 in class AbstractBsonWriter
      Parameters:
      value - the int value to write
    • doWriteInt64

      protected void doWriteInt64(long value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing an int64 value
      Specified by:
      doWriteInt64 in class AbstractBsonWriter
      Parameters:
      value - the long value to write
    • doWriteDecimal128

      protected void doWriteDecimal128(Decimal128 value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Decimal128 value
      Specified by:
      doWriteDecimal128 in class AbstractBsonWriter
      Parameters:
      value - the Decimal128 value to write
    • doWriteJavaScript

      protected void doWriteJavaScript(String value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a JavaScript function
      Specified by:
      doWriteJavaScript in class AbstractBsonWriter
      Parameters:
      value - the String value to write
    • doWriteJavaScriptWithScope

      protected void doWriteJavaScriptWithScope(String value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a scoped JavaScript function
      Specified by:
      doWriteJavaScriptWithScope in class AbstractBsonWriter
      Parameters:
      value - the boolean value to write
    • doWriteMaxKey

      protected void doWriteMaxKey()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Max key
      Specified by:
      doWriteMaxKey in class AbstractBsonWriter
    • doWriteMinKey

      protected void doWriteMinKey()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Min key
      Specified by:
      doWriteMinKey in class AbstractBsonWriter
    • doWriteNull

      public void doWriteNull()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Null value
      Specified by:
      doWriteNull in class AbstractBsonWriter
    • doWriteObjectId

      public void doWriteObjectId(ObjectId value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing an ObjectId
      Specified by:
      doWriteObjectId in class AbstractBsonWriter
      Parameters:
      value - the ObjectId value to write
    • doWriteRegularExpression

      public void doWriteRegularExpression(BsonRegularExpression value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a regular expression
      Specified by:
      doWriteRegularExpression in class AbstractBsonWriter
      Parameters:
      value - the BsonRegularExpression value to write
    • doWriteString

      public void doWriteString(String value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a String
      Specified by:
      doWriteString in class AbstractBsonWriter
      Parameters:
      value - the String value to write
    • doWriteSymbol

      public void doWriteSymbol(String value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a Symbol
      Specified by:
      doWriteSymbol in class AbstractBsonWriter
      Parameters:
      value - the boolean value to write
    • doWriteTimestamp

      public void doWriteTimestamp(BsonTimestamp value)
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing a timestamp
      Specified by:
      doWriteTimestamp in class AbstractBsonWriter
      Parameters:
      value - the BsonTimestamp value to write
    • doWriteUndefined

      public void doWriteUndefined()
      Description copied from class: AbstractBsonWriter
      Handles the logic of writing an Undefined value
      Specified by:
      doWriteUndefined in class AbstractBsonWriter
    • pipe

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

      public void pipe(byte[] bytes, int offset, int length)
      Pipes an encoded BSON document from the given byte array to this writer.
      Parameters:
      bytes - the byte array containing the encoded BSON document
      offset - the offset into the byte array
      length - the length of the encoded BSON document
      Since:
      5.8
    • pipe

      public void pipe(BsonReader reader, List<BsonElement> extraElements)
      Description copied from class: AbstractBsonWriter
      Reads a single document from the given BsonReader and writes it to this, appending the given extra elements to the document.
      Overrides:
      pipe in class AbstractBsonWriter
      Parameters:
      reader - the source of the document
      extraElements - the extra elements to append to the document
    • pushMaxDocumentSize

      public void pushMaxDocumentSize(int maxDocumentSize)
      Sets a maximum size for documents from this point.
      Parameters:
      maxDocumentSize - the maximum document size.
    • popMaxDocumentSize

      public void popMaxDocumentSize()
      Reset the maximum document size to its previous value.
    • mark

      public void mark()
      Create a snapshot of this writer's context at a point in time.
    • reset

      public void reset()
      Resets this writer to the last mark() saved.
      Throws:
      IllegalStateException - if mark() was not called prior to reset.