Package org.bson
Class BsonBinaryWriter
- java.lang.Object
-
- org.bson.AbstractBsonWriter
-
- org.bson.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBsonBinaryWriter.Contextprotected classBsonBinaryWriter.Mark-
Nested classes/interfaces inherited from class org.bson.AbstractBsonWriter
AbstractBsonWriter.State
-
-
Constructor Summary
Constructors Constructor Description BsonBinaryWriter(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voiddoWriteBinaryData(BsonBinary value)Handles the logic of writing aBsonBinaryvaluevoiddoWriteBoolean(boolean value)Handles the logic of writing a boolean valueprotected voiddoWriteDateTime(long value)Handles the logic of writing a date time valueprotected voiddoWriteDBPointer(BsonDbPointer value)Handles the logic of writing a DbPointer valueprotected voiddoWriteDecimal128(Decimal128 value)Handles the logic of writing a Decimal128 valueprotected voiddoWriteDouble(double value)Handles the logic of writing a Double valueprotected voiddoWriteEndArray()Handles the logic of writing the end of an arrayprotected voiddoWriteEndDocument()Handles the logic of writing the end of a documentprotected voiddoWriteInt32(int value)Handles the logic of writing an int32 valueprotected voiddoWriteInt64(long value)Handles the logic of writing an int64 valueprotected voiddoWriteJavaScript(String value)Handles the logic of writing a JavaScript functionprotected voiddoWriteJavaScriptWithScope(String value)Handles the logic of writing a scoped JavaScript functionprotected voiddoWriteMaxKey()Handles the logic of writing a Max keyprotected voiddoWriteMinKey()Handles the logic of writing a Min keyvoiddoWriteNull()Handles the logic of writing a Null valuevoiddoWriteObjectId(ObjectId value)Handles the logic of writing an ObjectIdvoiddoWriteRegularExpression(BsonRegularExpression value)Handles the logic of writing a regular expressionprotected voiddoWriteStartArray()Handles the logic to start writing an arrayprotected voiddoWriteStartDocument()Handles the logic to start writing a documentvoiddoWriteString(String value)Handles the logic of writing a StringvoiddoWriteSymbol(String value)Handles the logic of writing a SymbolvoiddoWriteTimestamp(BsonTimestamp value)Handles the logic of writing a timestampvoiddoWriteUndefined()Handles the logic of writing an Undefined valuevoidflush()Flushes any pending data to the output destination.BsonBinaryWriterSettingsgetBinaryWriterSettings()BsonOutputgetBsonOutput()Gets the BSON output backing this instance.protected BsonBinaryWriter.ContextgetContext()Get the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.voidmark()Create a snapshot of this writer's context at a point in time.voidpipe(BsonReader reader)Reads a single document from a BsonReader and writes it to this.voidpipe(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.voidpopMaxDocumentSize()Reset the maximum document size to its previous value.voidpushMaxDocumentSize(int maxDocumentSize)Sets a maximum size for documents from this point.voidreset()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 Detail
-
BsonBinaryWriter
public BsonBinaryWriter(BsonOutput bsonOutput, FieldNameValidator validator)
Construct an instance.- Parameters:
bsonOutput- the output to write tovalidator- 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 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 Detail
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAbstractBsonWriter
-
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
-
flush
public void flush()
Description copied from interface:BsonWriterFlushes any pending data to the output destination.
-
getContext
protected BsonBinaryWriter.Context getContext()
Description copied from class:AbstractBsonWriterGet the context, which will indicate which state the writer is in, for example which part of a document it's currently writing.- Overrides:
getContextin classAbstractBsonWriter- Returns:
- the current context.
-
doWriteStartDocument
protected void doWriteStartDocument()
Description copied from class:AbstractBsonWriterHandles the logic to start writing a document- Specified by:
doWriteStartDocumentin classAbstractBsonWriter
-
doWriteEndDocument
protected void doWriteEndDocument()
Description copied from class:AbstractBsonWriterHandles the logic of writing the end of a document- Specified by:
doWriteEndDocumentin classAbstractBsonWriter
-
doWriteStartArray
protected void doWriteStartArray()
Description copied from class:AbstractBsonWriterHandles the logic to start writing an array- Specified by:
doWriteStartArrayin classAbstractBsonWriter
-
doWriteEndArray
protected void doWriteEndArray()
Description copied from class:AbstractBsonWriterHandles the logic of writing the end of an array- Specified by:
doWriteEndArrayin classAbstractBsonWriter
-
doWriteBinaryData
protected void doWriteBinaryData(BsonBinary value)
Description copied from class:AbstractBsonWriterHandles the logic of writing aBsonBinaryvalue- Specified by:
doWriteBinaryDatain classAbstractBsonWriter- Parameters:
value- theBsonBinaryvalue to write
-
doWriteBoolean
public void doWriteBoolean(boolean value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a boolean value- Specified by:
doWriteBooleanin classAbstractBsonWriter- Parameters:
value- thebooleanvalue to write
-
doWriteDateTime
protected void doWriteDateTime(long value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a date time value- Specified by:
doWriteDateTimein classAbstractBsonWriter- Parameters:
value- thelongvalue to write
-
doWriteDBPointer
protected void doWriteDBPointer(BsonDbPointer value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a DbPointer value- Specified by:
doWriteDBPointerin classAbstractBsonWriter- Parameters:
value- theBsonDbPointervalue to write
-
doWriteDouble
protected void doWriteDouble(double value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a Double value- Specified by:
doWriteDoublein classAbstractBsonWriter- Parameters:
value- thedoublevalue to write
-
doWriteInt32
protected void doWriteInt32(int value)
Description copied from class:AbstractBsonWriterHandles the logic of writing an int32 value- Specified by:
doWriteInt32in classAbstractBsonWriter- Parameters:
value- theintvalue to write
-
doWriteInt64
protected void doWriteInt64(long value)
Description copied from class:AbstractBsonWriterHandles the logic of writing an int64 value- Specified by:
doWriteInt64in classAbstractBsonWriter- Parameters:
value- thelongvalue to write
-
doWriteDecimal128
protected void doWriteDecimal128(Decimal128 value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a Decimal128 value- Specified by:
doWriteDecimal128in classAbstractBsonWriter- Parameters:
value- theDecimal128value to write
-
doWriteJavaScript
protected void doWriteJavaScript(String value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a JavaScript function- Specified by:
doWriteJavaScriptin classAbstractBsonWriter- Parameters:
value- theStringvalue to write
-
doWriteJavaScriptWithScope
protected void doWriteJavaScriptWithScope(String value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a scoped JavaScript function- Specified by:
doWriteJavaScriptWithScopein classAbstractBsonWriter- Parameters:
value- thebooleanvalue to write
-
doWriteMaxKey
protected void doWriteMaxKey()
Description copied from class:AbstractBsonWriterHandles the logic of writing a Max key- Specified by:
doWriteMaxKeyin classAbstractBsonWriter
-
doWriteMinKey
protected void doWriteMinKey()
Description copied from class:AbstractBsonWriterHandles the logic of writing a Min key- Specified by:
doWriteMinKeyin classAbstractBsonWriter
-
doWriteNull
public void doWriteNull()
Description copied from class:AbstractBsonWriterHandles the logic of writing a Null value- Specified by:
doWriteNullin classAbstractBsonWriter
-
doWriteObjectId
public void doWriteObjectId(ObjectId value)
Description copied from class:AbstractBsonWriterHandles the logic of writing an ObjectId- Specified by:
doWriteObjectIdin classAbstractBsonWriter- Parameters:
value- theObjectIdvalue to write
-
doWriteRegularExpression
public void doWriteRegularExpression(BsonRegularExpression value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a regular expression- Specified by:
doWriteRegularExpressionin classAbstractBsonWriter- Parameters:
value- theBsonRegularExpressionvalue to write
-
doWriteString
public void doWriteString(String value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a String- Specified by:
doWriteStringin classAbstractBsonWriter- Parameters:
value- theStringvalue to write
-
doWriteSymbol
public void doWriteSymbol(String value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a Symbol- Specified by:
doWriteSymbolin classAbstractBsonWriter- Parameters:
value- thebooleanvalue to write
-
doWriteTimestamp
public void doWriteTimestamp(BsonTimestamp value)
Description copied from class:AbstractBsonWriterHandles the logic of writing a timestamp- Specified by:
doWriteTimestampin classAbstractBsonWriter- Parameters:
value- theBsonTimestampvalue to write
-
doWriteUndefined
public void doWriteUndefined()
Description copied from class:AbstractBsonWriterHandles the logic of writing an Undefined value- Specified by:
doWriteUndefinedin classAbstractBsonWriter
-
pipe
public void pipe(BsonReader reader)
Description copied from interface:BsonWriterReads a single document from a BsonReader and writes it to this.- Specified by:
pipein interfaceBsonWriter- Overrides:
pipein classAbstractBsonWriter- Parameters:
reader- The source.
-
pipe
public void pipe(BsonReader reader, List<BsonElement> extraElements)
Description copied from class:AbstractBsonWriterReads a single document from the given BsonReader and writes it to this, appending the given extra elements to the document.- Overrides:
pipein 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.
-
-