Package org.bson
Class BsonBinaryWriter
java.lang.Object
org.bson.AbstractBsonWriter
org.bson.BsonBinaryWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BsonWriter
A BsonWriter implementation that writes to a binary stream of data. This is the most commonly used implementation.
- Since:
- 3.0
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
An implementation ofAbstractBsonWriter.Context
.protected class
An implementation ofAbstractBsonWriter.Mark
.Nested classes/interfaces inherited from class org.bson.AbstractBsonWriter
AbstractBsonWriter.State
-
Constructor Summary
ConstructorDescriptionBsonBinaryWriter
(BsonWriterSettings settings, BsonBinaryWriterSettings binaryWriterSettings, BsonOutput bsonOutput) Construct an instance.BsonBinaryWriter
(BsonWriterSettings settings, BsonBinaryWriterSettings binaryWriterSettings, BsonOutput bsonOutput, FieldNameValidator validator) Construct an instance.BsonBinaryWriter
(BsonOutput bsonOutput) Construct an instance.BsonBinaryWriter
(BsonOutput bsonOutput, FieldNameValidator validator) Construct an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
doWriteBinaryData
(BsonBinary value) Handles the logic of writing aBsonBinary
valuevoid
doWriteBoolean
(boolean value) Handles the logic of writing a boolean valueprotected void
doWriteDateTime
(long value) Handles the logic of writing a date time valueprotected void
doWriteDBPointer
(BsonDbPointer value) Handles the logic of writing a DbPointer valueprotected void
doWriteDecimal128
(Decimal128 value) Handles the logic of writing a Decimal128 valueprotected void
doWriteDouble
(double value) Handles the logic of writing a Double valueprotected void
Handles the logic of writing the end of an arrayprotected void
Handles the logic of writing the end of a documentprotected void
doWriteInt32
(int value) Handles the logic of writing an int32 valueprotected void
doWriteInt64
(long value) Handles the logic of writing an int64 valueprotected void
doWriteJavaScript
(String value) Handles the logic of writing a JavaScript functionprotected void
doWriteJavaScriptWithScope
(String value) Handles the logic of writing a scoped JavaScript functionprotected void
Handles the logic of writing a Max keyprotected void
Handles the logic of writing a Min keyvoid
Handles the logic of writing a Null valuevoid
doWriteObjectId
(ObjectId value) Handles the logic of writing an ObjectIdvoid
Handles the logic of writing a regular expressionprotected void
Handles the logic to start writing an arrayprotected void
Handles the logic to start writing a documentvoid
doWriteString
(String value) Handles the logic of writing a Stringvoid
doWriteSymbol
(String value) Handles the logic of writing a Symbolvoid
doWriteTimestamp
(BsonTimestamp value) Handles the logic of writing a timestampvoid
Handles the logic of writing an Undefined valuevoid
flush()
Flushes any pending data to the output destination.Gets the BSON output backing this instance.protected BsonBinaryWriter.Context
Get the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.void
mark()
Create a snapshot of this writer's context at a point in time.void
pipe
(BsonReader reader) Reads a single document from a BsonReader and writes it to this.void
pipe
(BsonReader reader, List<BsonElement> extraElements) Reads a single document from the given BsonReader and writes it to this, appending the given extra elements to the document.void
Reset the maximum document size to its previous value.void
pushMaxDocumentSize
(int maxDocumentSize) Sets a maximum size for documents from this point.void
reset()
Resets this writer to the lastmark()
saved.Methods inherited from class org.bson.AbstractBsonWriter
abortPipe, checkPreconditions, checkState, doWriteName, getName, getNextState, getState, isClosed, pipeExtraElements, setContext, setState, throwInvalidContextType, throwInvalidState, writeBinaryData, writeBinaryData, writeBoolean, writeBoolean, writeDateTime, writeDateTime, writeDBPointer, writeDBPointer, writeDecimal128, writeDecimal128, writeDouble, writeDouble, writeEndArray, writeEndDocument, writeInt32, writeInt32, writeInt64, writeInt64, writeJavaScript, writeJavaScript, writeJavaScriptWithScope, writeJavaScriptWithScope, writeMaxKey, writeMaxKey, writeMinKey, writeMinKey, writeName, writeNull, writeNull, writeObjectId, writeObjectId, writeRegularExpression, writeRegularExpression, writeStartArray, writeStartArray, writeStartDocument, writeStartDocument, writeString, writeString, writeSymbol, writeSymbol, writeTimestamp, writeTimestamp, writeUndefined, writeUndefined
-
Constructor Details
-
BsonBinaryWriter
Construct an instance.- Parameters:
bsonOutput
- the output to write tovalidator
- the field name validator to apply
-
BsonBinaryWriter
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 settingsbinaryWriterSettings
- the settings specific to a BsonBinaryWriterbsonOutput
- the output to write to
-
BsonBinaryWriter
public BsonBinaryWriter(BsonWriterSettings settings, BsonBinaryWriterSettings binaryWriterSettings, BsonOutput bsonOutput, FieldNameValidator validator) Construct an instance.- Parameters:
settings
- the generic BsonWriter settingsbinaryWriterSettings
- the settings specific to a BsonBinaryWriterbsonOutput
- the output to write tovalidator
- the field name validator to apply
-
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classAbstractBsonWriter
-
getBsonOutput
Gets the BSON output backing this instance.- Returns:
- the BSON output
-
getBinaryWriterSettings
- Returns:
- the BsonBinaryWriterSettings
- Since:
- 3.6
-
flush
public void flush()Description copied from interface:BsonWriter
Flushes any pending data to the output destination. -
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 classAbstractBsonWriter
- 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 classAbstractBsonWriter
-
doWriteEndDocument
protected void doWriteEndDocument()Description copied from class:AbstractBsonWriter
Handles the logic of writing the end of a document- Specified by:
doWriteEndDocument
in classAbstractBsonWriter
-
doWriteStartArray
protected void doWriteStartArray()Description copied from class:AbstractBsonWriter
Handles the logic to start writing an array- Specified by:
doWriteStartArray
in classAbstractBsonWriter
-
doWriteEndArray
protected void doWriteEndArray()Description copied from class:AbstractBsonWriter
Handles the logic of writing the end of an array- Specified by:
doWriteEndArray
in classAbstractBsonWriter
-
doWriteBinaryData
Description copied from class:AbstractBsonWriter
Handles the logic of writing aBsonBinary
value- Specified by:
doWriteBinaryData
in classAbstractBsonWriter
- Parameters:
value
- theBsonBinary
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 classAbstractBsonWriter
- Parameters:
value
- theboolean
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 classAbstractBsonWriter
- Parameters:
value
- thelong
value to write
-
doWriteDBPointer
Description copied from class:AbstractBsonWriter
Handles the logic of writing a DbPointer value- Specified by:
doWriteDBPointer
in classAbstractBsonWriter
- Parameters:
value
- theBsonDbPointer
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 classAbstractBsonWriter
- Parameters:
value
- thedouble
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 classAbstractBsonWriter
- Parameters:
value
- theint
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 classAbstractBsonWriter
- Parameters:
value
- thelong
value to write
-
doWriteDecimal128
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Decimal128 value- Specified by:
doWriteDecimal128
in classAbstractBsonWriter
- Parameters:
value
- theDecimal128
value to write
-
doWriteJavaScript
Description copied from class:AbstractBsonWriter
Handles the logic of writing a JavaScript function- Specified by:
doWriteJavaScript
in classAbstractBsonWriter
- Parameters:
value
- theString
value to write
-
doWriteJavaScriptWithScope
Description copied from class:AbstractBsonWriter
Handles the logic of writing a scoped JavaScript function- Specified by:
doWriteJavaScriptWithScope
in classAbstractBsonWriter
- Parameters:
value
- theboolean
value to write
-
doWriteMaxKey
protected void doWriteMaxKey()Description copied from class:AbstractBsonWriter
Handles the logic of writing a Max key- Specified by:
doWriteMaxKey
in classAbstractBsonWriter
-
doWriteMinKey
protected void doWriteMinKey()Description copied from class:AbstractBsonWriter
Handles the logic of writing a Min key- Specified by:
doWriteMinKey
in classAbstractBsonWriter
-
doWriteNull
public void doWriteNull()Description copied from class:AbstractBsonWriter
Handles the logic of writing a Null value- Specified by:
doWriteNull
in classAbstractBsonWriter
-
doWriteObjectId
Description copied from class:AbstractBsonWriter
Handles the logic of writing an ObjectId- Specified by:
doWriteObjectId
in classAbstractBsonWriter
- Parameters:
value
- theObjectId
value to write
-
doWriteRegularExpression
Description copied from class:AbstractBsonWriter
Handles the logic of writing a regular expression- Specified by:
doWriteRegularExpression
in classAbstractBsonWriter
- Parameters:
value
- theBsonRegularExpression
value to write
-
doWriteString
Description copied from class:AbstractBsonWriter
Handles the logic of writing a String- Specified by:
doWriteString
in classAbstractBsonWriter
- Parameters:
value
- theString
value to write
-
doWriteSymbol
Description copied from class:AbstractBsonWriter
Handles the logic of writing a Symbol- Specified by:
doWriteSymbol
in classAbstractBsonWriter
- Parameters:
value
- theboolean
value to write
-
doWriteTimestamp
Description copied from class:AbstractBsonWriter
Handles the logic of writing a timestamp- Specified by:
doWriteTimestamp
in classAbstractBsonWriter
- Parameters:
value
- theBsonTimestamp
value to write
-
doWriteUndefined
public void doWriteUndefined()Description copied from class:AbstractBsonWriter
Handles the logic of writing an Undefined value- Specified by:
doWriteUndefined
in classAbstractBsonWriter
-
pipe
Description copied from interface:BsonWriter
Reads a single document from a BsonReader and writes it to this.- Specified by:
pipe
in interfaceBsonWriter
- Overrides:
pipe
in classAbstractBsonWriter
- Parameters:
reader
- The source.
-
pipe
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 classAbstractBsonWriter
- Parameters:
reader
- the source of the documentextraElements
- 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 lastmark()
saved.- Throws:
IllegalStateException
- ifmark()
was not called prior to reset.
-