abstract class BSONWriter
extends java.lang.Object
implements java.io.Closeable
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
BSONWriter.Context |
(package private) class |
BSONWriter.Mark |
(package private) static class |
BSONWriter.State |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
closed |
private BSONWriter.Context |
context |
private java.lang.String |
currentName |
private int |
serializationDepth |
private BSONWriterSettings |
settings |
private BSONWriter.State |
state |
| Modifier | Constructor and Description |
|---|---|
protected |
BSONWriter(BSONWriterSettings settings)
Initializes a new instance of the BSONWriter class.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkPreconditions(java.lang.String methodName,
BSONWriter.State... validStates) |
protected boolean |
checkState(BSONWriter.State[] validStates) |
void |
close()
Closes the writer.
|
abstract void |
flush()
Flushes any pending data to the output destination.
|
protected BSONWriter.Context |
getContext() |
protected java.lang.String |
getName() |
protected BSONWriter.State |
getNextState() |
protected BSONWriter.State |
getState() |
protected boolean |
isClosed() |
protected void |
setContext(BSONWriter.Context context) |
protected void |
setState(BSONWriter.State state) |
protected void |
throwInvalidContextType(java.lang.String methodName,
BSONContextType actualContextType,
BSONContextType... validContextTypes)
Throws an InvalidOperationException when the method called is not valid for the current ContextType.
|
protected void |
throwInvalidState(java.lang.String methodName,
BSONWriter.State... validStates)
Throws an InvalidOperationException when the method called is not valid for the current state.
|
abstract void |
writeBinaryData(Binary binary)
Writes a BSON Binary data element to the writer.
|
void |
writeBinaryData(java.lang.String name,
Binary binary)
Writes a BSON Binary data element to the writer.
|
abstract void |
writeBoolean(boolean value)
Writes a BSON Boolean to the writer.
|
void |
writeBoolean(java.lang.String name,
boolean value)
Writes a BSON Boolean element to the writer.
|
abstract void |
writeDateTime(long value)
Writes a BSON DateTime to the writer.
|
void |
writeDateTime(java.lang.String name,
long value)
Writes a BSON DateTime element to the writer.
|
abstract void |
writeDouble(double value)
Writes a BSON Double to the writer.
|
void |
writeDouble(java.lang.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.
|
abstract void |
writeInt32(int value)
Writes a BSON Int32 to the writer.
|
void |
writeInt32(java.lang.String name,
int value)
Writes a BSON Int32 element to the writer.
|
abstract void |
writeInt64(long value)
Writes a BSON Int64 to the writer.
|
void |
writeInt64(java.lang.String name,
long value)
Writes a BSON Int64 element to the writer.
|
abstract void |
writeJavaScript(java.lang.String code)
Writes a BSON JavaScript to the writer.
|
void |
writeJavaScript(java.lang.String name,
java.lang.String code)
Writes a BSON JavaScript element to the writer.
|
abstract void |
writeJavaScriptWithScope(java.lang.String code)
Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).
|
void |
writeJavaScriptWithScope(java.lang.String name,
java.lang.String code)
Writes a BSON JavaScript element to the writer (call WriteStartDocument to start writing the scope).
|
abstract void |
writeMaxKey()
Writes a BSON MaxKey to the writer.
|
void |
writeMaxKey(java.lang.String name)
Writes a BSON MaxKey element to the writer.
|
abstract void |
writeMinKey()
Writes a BSON MinKey to the writer.
|
void |
writeMinKey(java.lang.String name)
Writes a BSON MinKey element to the writer.
|
void |
writeName(java.lang.String name)
Writes the name of an element to the writer.
|
abstract void |
writeNull()
Writes a BSON null to the writer.
|
void |
writeNull(java.lang.String name)
Writes a BSON null element to the writer.
|
abstract void |
writeObjectId(ObjectId objectId)
Writes a BSON ObjectId to the writer.
|
void |
writeObjectId(java.lang.String name,
ObjectId objectId)
Writes a BSON ObjectId element to the writer.
|
void |
writeStartArray()
Writes the start of a BSON array to the writer.
|
void |
writeStartArray(java.lang.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(java.lang.String name)
Writes the start of a BSON document element to the writer.
|
abstract void |
writeString(java.lang.String value)
Writes a BSON String to the writer.
|
void |
writeString(java.lang.String name,
java.lang.String value)
Writes a BSON String element to the writer.
|
abstract void |
writeSymbol(java.lang.String value)
Writes a BSON Symbol to the writer.
|
void |
writeSymbol(java.lang.String name,
java.lang.String value)
Writes a BSON Symbol element to the writer.
|
abstract void |
writeTimestamp(BSONTimestamp value)
Writes a BSON Timestamp to the writer.
|
void |
writeTimestamp(java.lang.String name,
BSONTimestamp value)
Writes a BSON Timestamp element to the writer.
|
abstract void |
writeUndefined()
Writes a BSON undefined to the writer.
|
void |
writeUndefined(java.lang.String name)
Writes a BSON undefined element to the writer.
|
private final BSONWriterSettings settings
private BSONWriter.State state
private BSONWriter.Context context
private java.lang.String currentName
private int serializationDepth
private boolean closed
protected BSONWriter(BSONWriterSettings settings)
settings - The writer settings.protected java.lang.String getName()
protected boolean isClosed()
protected void setState(BSONWriter.State state)
protected BSONWriter.State getState()
protected BSONWriter.Context getContext()
protected void setContext(BSONWriter.Context context)
public abstract void flush()
public abstract void writeBinaryData(Binary binary)
binary - The Binary data.public void writeBinaryData(java.lang.String name,
Binary binary)
name - The name of the element.binary - The Binary data value.public abstract void writeBoolean(boolean value)
value - The Boolean value.public void writeBoolean(java.lang.String name,
boolean value)
name - The name of the element.value - The Boolean value.public abstract void writeDateTime(long value)
value - The number of milliseconds since the Unix epoch.public void writeDateTime(java.lang.String name,
long value)
name - The name of the element.value - The number of milliseconds since the Unix epoch.public abstract void writeDouble(double value)
value - The Double value.public void writeDouble(java.lang.String name,
double value)
name - The name of the element.value - The Double value.public void writeEndArray()
public void writeEndDocument()
public abstract void writeInt32(int value)
value - The Int32 value.public void writeInt32(java.lang.String name,
int value)
name - The name of the element.value - The Int32 value.public abstract void writeInt64(long value)
value - The Int64 value.public void writeInt64(java.lang.String name,
long value)
name - The name of the element.value - The Int64 value.public abstract void writeJavaScript(java.lang.String code)
code - The JavaScript code.public void writeJavaScript(java.lang.String name,
java.lang.String code)
name - The name of the element.code - The JavaScript code.public abstract void writeJavaScriptWithScope(java.lang.String code)
code - The JavaScript code.public void writeJavaScriptWithScope(java.lang.String name,
java.lang.String code)
name - The name of the element.code - The JavaScript code.public abstract void writeMaxKey()
public void writeMaxKey(java.lang.String name)
name - The name of the element.public abstract void writeMinKey()
public void writeMinKey(java.lang.String name)
name - The name of the element.public void writeName(java.lang.String name)
name - The name of the element.public abstract void writeNull()
public void writeNull(java.lang.String name)
name - The name of the element.public abstract void writeObjectId(ObjectId objectId)
objectId - The ObjectId value.public void writeObjectId(java.lang.String name,
ObjectId objectId)
name - The name of the element.objectId - The ObjectId value.public void writeStartArray()
BSONException - if maximum serialization depth exceeded.public void writeStartArray(java.lang.String name)
name - The name of the element.public void writeStartDocument()
BSONException - if maximum serialization depth exceeded.public void writeStartDocument(java.lang.String name)
name - The name of the element.public abstract void writeString(java.lang.String value)
value - The String value.public void writeString(java.lang.String name,
java.lang.String value)
name - The name of the element.value - The String value.public abstract void writeSymbol(java.lang.String value)
value - The symbol.public void writeSymbol(java.lang.String name,
java.lang.String value)
name - The name of the element.value - The symbol.public abstract void writeTimestamp(BSONTimestamp value)
value - The combined timestamp/increment value.public void writeTimestamp(java.lang.String name,
BSONTimestamp value)
name - The name of the element.value - The combined timestamp/increment value.public abstract void writeUndefined()
public void writeUndefined(java.lang.String name)
name - The name of the element.protected BSONWriter.State getNextState()
protected boolean checkState(BSONWriter.State[] validStates)
protected void checkPreconditions(java.lang.String methodName,
BSONWriter.State... validStates)
protected void throwInvalidContextType(java.lang.String methodName,
BSONContextType actualContextType,
BSONContextType... validContextTypes)
methodName - The name of the method.actualContextType - The actual ContextType.validContextTypes - The valid ContextTypes.BSONExceptionprotected void throwInvalidState(java.lang.String methodName,
BSONWriter.State... validStates)
methodName - The name of the method.validStates - The valid states.BSONExceptionpublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable