Package org.bson
Class AbstractBsonWriter
- java.lang.Object
-
- org.bson.AbstractBsonWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BsonWriter
- Direct Known Subclasses:
BsonBinaryWriter
,BsonDocumentWriter
,JsonWriter
public abstract class AbstractBsonWriter extends Object implements BsonWriter, Closeable
Represents a BSON writer for some external format (see subclasses).- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractBsonWriter.Context
The context for the writer.static class
AbstractBsonWriter.State
The state of a writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
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
writeBinaryData(String name, BsonBinary binary)
Writes a BSON Binary data element to the writer.void
writeBinaryData(BsonBinary binary)
Writes a BSON Binary data element to the writer.void
writeBoolean(boolean value)
Writes a BSON Boolean to the writer.void
writeBoolean(String name, boolean value)
Writes a BSON Boolean element to the writer.void
writeDateTime(long value)
Writes a BSON DateTime to the writer.void
writeDateTime(String name, long value)
Writes a BSON DateTime element to the writer.void
writeDBPointer(String name, BsonDbPointer value)
Writes a BSON DBPointer element to the writer.void
writeDBPointer(BsonDbPointer value)
Writes a BSON DBPointer to the writer.void
writeDecimal128(String name, Decimal128 value)
Writes a BSON Decimal128 element to the writer.void
writeDecimal128(Decimal128 value)
Writes a BSON Decimal128 to the writer.void
writeDouble(double value)
Writes a BSON Double to the writer.void
writeDouble(String name, double value)
Writes a BSON Double element to the writer.void
writeEndArray()
Writes the end of a BSON array to the writer.void
writeEndDocument()
Writes the end of a BSON document to the writer.void
writeInt32(int value)
Writes a BSON Int32 to the writer.void
writeInt32(String name, int value)
Writes a BSON Int32 element to the writer.void
writeInt64(long value)
Writes a BSON Int64 to the writer.void
writeInt64(String name, long value)
Writes a BSON Int64 element to the writer.void
writeJavaScript(String code)
Writes a BSON JavaScript to the writer.void
writeJavaScript(String name, String code)
Writes a BSON JavaScript element to the writer.void
writeJavaScriptWithScope(String code)
Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).void
writeJavaScriptWithScope(String name, String code)
Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).void
writeMaxKey()
Writes a BSON MaxKey to the writer.void
writeMaxKey(String name)
Writes a BSON MaxKey element to the writer.void
writeMinKey()
Writes a BSON MinKey to the writer.void
writeMinKey(String name)
Writes a BSON MinKey element to the writer.void
writeName(String name)
Writes the name of an element to the writer.void
writeNull()
Writes a BSON null to the writer.void
writeNull(String name)
Writes a BSON null element to the writer.void
writeObjectId(String name, ObjectId objectId)
Writes a BSON ObjectId element to the writer.void
writeObjectId(ObjectId objectId)
Writes a BSON ObjectId to the writer.void
writeRegularExpression(String name, BsonRegularExpression regularExpression)
Writes a BSON regular expression element to the writer.void
writeRegularExpression(BsonRegularExpression regularExpression)
Writes a BSON regular expression to the writer.void
writeStartArray()
Writes the start of a BSON array to the writer.void
writeStartArray(String name)
Writes the start of a BSON array element to the writer.void
writeStartDocument()
Writes the start of a BSON document to the writer.void
writeStartDocument(String name)
Writes the start of a BSON document element to the writer.void
writeString(String value)
Writes a BSON String to the writer.void
writeString(String name, String value)
Writes a BSON String element to the writer.void
writeSymbol(String value)
Writes a BSON Symbol to the writer.void
writeSymbol(String name, String value)
Writes a BSON Symbol element to the writer.void
writeTimestamp(String name, BsonTimestamp value)
Writes a BSON Timestamp element to the writer.void
writeTimestamp(BsonTimestamp value)
Writes a BSON Timestamp to the writer.void
writeUndefined()
Writes a BSON undefined to the writer.void
writeUndefined(String name)
Writes a BSON undefined element to the writer.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bson.BsonWriter
flush
-
-
-
-
Method Detail
-
writeStartDocument
public void writeStartDocument(String name)
Description copied from interface:BsonWriter
Writes the start of a BSON document element to the writer.- Specified by:
writeStartDocument
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeStartDocument
public void writeStartDocument()
Description copied from interface:BsonWriter
Writes the start of a BSON document to the writer.- Specified by:
writeStartDocument
in interfaceBsonWriter
-
writeEndDocument
public void writeEndDocument()
Description copied from interface:BsonWriter
Writes the end of a BSON document to the writer.- Specified by:
writeEndDocument
in interfaceBsonWriter
-
writeStartArray
public void writeStartArray(String name)
Description copied from interface:BsonWriter
Writes the start of a BSON array element to the writer.- Specified by:
writeStartArray
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeStartArray
public void writeStartArray()
Description copied from interface:BsonWriter
Writes the start of a BSON array to the writer.- Specified by:
writeStartArray
in interfaceBsonWriter
-
writeEndArray
public void writeEndArray()
Description copied from interface:BsonWriter
Writes the end of a BSON array to the writer.- Specified by:
writeEndArray
in interfaceBsonWriter
-
writeBinaryData
public void writeBinaryData(String name, BsonBinary binary)
Description copied from interface:BsonWriter
Writes a BSON Binary data element to the writer.- Specified by:
writeBinaryData
in interfaceBsonWriter
- Parameters:
name
- The name of the element.binary
- The Binary data value.
-
writeBinaryData
public void writeBinaryData(BsonBinary binary)
Description copied from interface:BsonWriter
Writes a BSON Binary data element to the writer.- Specified by:
writeBinaryData
in interfaceBsonWriter
- Parameters:
binary
- The Binary data.
-
writeBoolean
public void writeBoolean(String name, boolean value)
Description copied from interface:BsonWriter
Writes a BSON Boolean element to the writer.- Specified by:
writeBoolean
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The Boolean value.
-
writeBoolean
public void writeBoolean(boolean value)
Description copied from interface:BsonWriter
Writes a BSON Boolean to the writer.- Specified by:
writeBoolean
in interfaceBsonWriter
- Parameters:
value
- The Boolean value.
-
writeDateTime
public void writeDateTime(String name, long value)
Description copied from interface:BsonWriter
Writes a BSON DateTime element to the writer.- Specified by:
writeDateTime
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The number of milliseconds since the Unix epoch.
-
writeDateTime
public void writeDateTime(long value)
Description copied from interface:BsonWriter
Writes a BSON DateTime to the writer.- Specified by:
writeDateTime
in interfaceBsonWriter
- Parameters:
value
- The number of milliseconds since the Unix epoch.
-
writeDBPointer
public void writeDBPointer(String name, BsonDbPointer value)
Description copied from interface:BsonWriter
Writes a BSON DBPointer element to the writer.- Specified by:
writeDBPointer
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The DBPointer to write
-
writeDBPointer
public void writeDBPointer(BsonDbPointer value)
Description copied from interface:BsonWriter
Writes a BSON DBPointer to the writer.- Specified by:
writeDBPointer
in interfaceBsonWriter
- Parameters:
value
- The DBPointer to write
-
writeDouble
public void writeDouble(String name, double value)
Description copied from interface:BsonWriter
Writes a BSON Double element to the writer.- Specified by:
writeDouble
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The Double value.
-
writeDouble
public void writeDouble(double value)
Description copied from interface:BsonWriter
Writes a BSON Double to the writer.- Specified by:
writeDouble
in interfaceBsonWriter
- Parameters:
value
- The Double value.
-
writeInt32
public void writeInt32(String name, int value)
Description copied from interface:BsonWriter
Writes a BSON Int32 element to the writer.- Specified by:
writeInt32
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The Int32 value.
-
writeInt32
public void writeInt32(int value)
Description copied from interface:BsonWriter
Writes a BSON Int32 to the writer.- Specified by:
writeInt32
in interfaceBsonWriter
- Parameters:
value
- The Int32 value.
-
writeInt64
public void writeInt64(String name, long value)
Description copied from interface:BsonWriter
Writes a BSON Int64 element to the writer.- Specified by:
writeInt64
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The Int64 value.
-
writeInt64
public void writeInt64(long value)
Description copied from interface:BsonWriter
Writes a BSON Int64 to the writer.- Specified by:
writeInt64
in interfaceBsonWriter
- Parameters:
value
- The Int64 value.
-
writeDecimal128
public void writeDecimal128(Decimal128 value)
Description copied from interface:BsonWriter
Writes a BSON Decimal128 to the writer.- Specified by:
writeDecimal128
in interfaceBsonWriter
- Parameters:
value
- The Decimal128 value.
-
writeDecimal128
public void writeDecimal128(String name, Decimal128 value)
Description copied from interface:BsonWriter
Writes a BSON Decimal128 element to the writer.- Specified by:
writeDecimal128
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The Decimal128 value.
-
writeJavaScript
public void writeJavaScript(String name, String code)
Description copied from interface:BsonWriter
Writes a BSON JavaScript element to the writer.- Specified by:
writeJavaScript
in interfaceBsonWriter
- Parameters:
name
- The name of the element.code
- The JavaScript code.
-
writeJavaScript
public void writeJavaScript(String code)
Description copied from interface:BsonWriter
Writes a BSON JavaScript to the writer.- Specified by:
writeJavaScript
in interfaceBsonWriter
- Parameters:
code
- The JavaScript code.
-
writeJavaScriptWithScope
public void writeJavaScriptWithScope(String name, String code)
Description copied from interface:BsonWriter
Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).- Specified by:
writeJavaScriptWithScope
in interfaceBsonWriter
- Parameters:
name
- The name of the element.code
- The JavaScript code.
-
writeJavaScriptWithScope
public void writeJavaScriptWithScope(String code)
Description copied from interface:BsonWriter
Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).- Specified by:
writeJavaScriptWithScope
in interfaceBsonWriter
- Parameters:
code
- The JavaScript code.
-
writeMaxKey
public void writeMaxKey(String name)
Description copied from interface:BsonWriter
Writes a BSON MaxKey element to the writer.- Specified by:
writeMaxKey
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeMaxKey
public void writeMaxKey()
Description copied from interface:BsonWriter
Writes a BSON MaxKey to the writer.- Specified by:
writeMaxKey
in interfaceBsonWriter
-
writeMinKey
public void writeMinKey(String name)
Description copied from interface:BsonWriter
Writes a BSON MinKey element to the writer.- Specified by:
writeMinKey
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeMinKey
public void writeMinKey()
Description copied from interface:BsonWriter
Writes a BSON MinKey to the writer.- Specified by:
writeMinKey
in interfaceBsonWriter
-
writeName
public void writeName(String name)
Description copied from interface:BsonWriter
Writes the name of an element to the writer.- Specified by:
writeName
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeNull
public void writeNull(String name)
Description copied from interface:BsonWriter
Writes a BSON null element to the writer.- Specified by:
writeNull
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeNull
public void writeNull()
Description copied from interface:BsonWriter
Writes a BSON null to the writer.- Specified by:
writeNull
in interfaceBsonWriter
-
writeObjectId
public void writeObjectId(String name, ObjectId objectId)
Description copied from interface:BsonWriter
Writes a BSON ObjectId element to the writer.- Specified by:
writeObjectId
in interfaceBsonWriter
- Parameters:
name
- The name of the element.objectId
- The ObjectId value.
-
writeObjectId
public void writeObjectId(ObjectId objectId)
Description copied from interface:BsonWriter
Writes a BSON ObjectId to the writer.- Specified by:
writeObjectId
in interfaceBsonWriter
- Parameters:
objectId
- The ObjectId value.
-
writeRegularExpression
public void writeRegularExpression(String name, BsonRegularExpression regularExpression)
Description copied from interface:BsonWriter
Writes a BSON regular expression element to the writer.- Specified by:
writeRegularExpression
in interfaceBsonWriter
- Parameters:
name
- The name of the element.regularExpression
- The RegularExpression value.
-
writeRegularExpression
public void writeRegularExpression(BsonRegularExpression regularExpression)
Description copied from interface:BsonWriter
Writes a BSON regular expression to the writer.- Specified by:
writeRegularExpression
in interfaceBsonWriter
- Parameters:
regularExpression
- the regular expression to write.
-
writeString
public void writeString(String name, String value)
Description copied from interface:BsonWriter
Writes a BSON String element to the writer.- Specified by:
writeString
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The String value.
-
writeString
public void writeString(String value)
Description copied from interface:BsonWriter
Writes a BSON String to the writer.- Specified by:
writeString
in interfaceBsonWriter
- Parameters:
value
- The String value.
-
writeSymbol
public void writeSymbol(String name, String value)
Description copied from interface:BsonWriter
Writes a BSON Symbol element to the writer.- Specified by:
writeSymbol
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The symbol.
-
writeSymbol
public void writeSymbol(String value)
Description copied from interface:BsonWriter
Writes a BSON Symbol to the writer.- Specified by:
writeSymbol
in interfaceBsonWriter
- Parameters:
value
- The symbol.
-
writeTimestamp
public void writeTimestamp(String name, BsonTimestamp value)
Description copied from interface:BsonWriter
Writes a BSON Timestamp element to the writer.- Specified by:
writeTimestamp
in interfaceBsonWriter
- Parameters:
name
- The name of the element.value
- The combined timestamp/increment value.
-
writeTimestamp
public void writeTimestamp(BsonTimestamp value)
Description copied from interface:BsonWriter
Writes a BSON Timestamp to the writer.- Specified by:
writeTimestamp
in interfaceBsonWriter
- Parameters:
value
- The combined timestamp/increment value.
-
writeUndefined
public void writeUndefined(String name)
Description copied from interface:BsonWriter
Writes a BSON undefined element to the writer.- Specified by:
writeUndefined
in interfaceBsonWriter
- Parameters:
name
- The name of the element.
-
writeUndefined
public void writeUndefined()
Description copied from interface:BsonWriter
Writes a BSON undefined to the writer.- Specified by:
writeUndefined
in interfaceBsonWriter
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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 interfaceBsonWriter
- Parameters:
reader
- The source.
-
pipe
public 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.- Parameters:
reader
- the source of the documentextraElements
- the extra elements to append to the document- Since:
- 3.6
-
-