public class BsonGenerator
extends com.fasterxml.jackson.core.base.GeneratorBase
| Modifier and Type | Class and Description |
|---|---|
protected static class |
BsonGenerator.DocumentInfo
A structure describing the document currently being generated
|
static class |
BsonGenerator.Feature
Defines toggable features
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
_bsonFeatures
Bit flag composed of bits that indicate which
BsonGenerator.Features are enabled. |
protected DynamicOutputBuffer |
_buffer
Since a BSON document's header must include the size of the whole document
in bytes, we have to buffer the whole document first, before we can
write it to the output stream.
|
protected com.fasterxml.jackson.core.io.CharacterEscapes |
_characterEscapes
Custom character escapes to use when writing strings (field names and string values)
|
protected BsonGenerator.DocumentInfo |
_currentDocument
Saves information about documents (the main document and embedded ones)
|
protected java.io.OutputStream |
_out
The output stream to write to
|
protected int[] |
_outputEscapes
Escape codes to use when writing strings (only valid of
_characterEscapes is not null,
see setCharacterEscapes(CharacterEscapes)) |
protected int |
_typeMarker
Saves the position of the type marker for the object currently begin written
|
protected boolean |
nextObjectIsEmbeddedInValue
Indicates that the next object to be encountered is actually embedded inside a value, and not a complete value
itself.
|
_cfgNumbersAsStrings, _closed, _features, _objectCodec, _writeContext, DERIVED_FEATURES_MASK, MAX_BIG_DECIMAL_SCALE, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST, WRITE_BINARY, WRITE_BOOLEAN, WRITE_NULL, WRITE_NUMBER, WRITE_RAW, WRITE_STRING| Constructor and Description |
|---|
BsonGenerator(int jsonFeatures,
int bsonFeatures,
java.io.OutputStream out)
Creates a new generator
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
_releaseBuffers() |
protected void |
_verifyValueWrite(java.lang.String typeMsg) |
protected void |
_writeArrayFieldNameIfNeeded()
If the generator is currently processing an array, this method writes
the field name of the current element (which is just the position of the
element in the array)
|
protected int |
_writeCString(java.lang.String string)
Write a BSON cstring structure (a null terminated string)
|
protected void |
_writeFieldName(java.lang.String name) |
protected void |
_writeStartObject(boolean array)
Creates a new embedded document or array
|
protected int |
_writeString(java.lang.String string)
Write a BSON string structure (a null terminated string prependend by the length of the string)
|
void |
close() |
protected java.lang.String |
escapeCharacters(java.lang.String string)
Escapes the given string according to
_characterEscapes. |
protected java.lang.String |
flagsToRegexOptions(int flags)
Converts a a Java flags word into a BSON options pattern
|
void |
flush() |
protected void |
flushBuffer()
Tries to flush the output buffer if streaming is enabled.
|
protected int |
getAndIncCurrentArrayPos()
Retrieves and then increases the current position in the array
currently being generated
|
com.fasterxml.jackson.core.io.CharacterEscapes |
getCharacterEscapes() |
protected boolean |
isArray() |
protected boolean |
isEnabled(BsonGenerator.Feature f)
Checks if a generator feature is enabled
|
protected void |
putHeader(int pos)
Writes the BSON document header to the output buffer at the
given position.
|
protected void |
reserveHeader()
Reserves bytes for the BSON document header
|
com.fasterxml.jackson.core.JsonGenerator |
setCharacterEscapes(com.fasterxml.jackson.core.io.CharacterEscapes esc) |
void |
writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant,
byte[] data,
int offset,
int len) |
void |
writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant,
byte subType,
byte[] data,
int offset,
int len)
Similar to
writeBinary(Base64Variant, byte, byte[], int, int),
but with the possibility to specify a binary subtype (see
BsonConstants). |
void |
writeBoolean(boolean state) |
void |
writeDateTime(java.util.Date date)
Write a BSON date time
|
void |
writeEndArray() |
void |
writeEndObject() |
protected void |
writeEndObjectInternal() |
void |
writeFieldName(java.lang.String name) |
void |
writeJavaScript(JavaScript javaScript,
com.fasterxml.jackson.databind.SerializerProvider provider)
Write a BSON JavaScript object
|
void |
writeNull() |
void |
writeNumber(java.math.BigDecimal dec) |
void |
writeNumber(java.math.BigInteger v) |
void |
writeNumber(double d) |
void |
writeNumber(float f) |
void |
writeNumber(int v) |
void |
writeNumber(long v) |
void |
writeNumber(java.lang.String encodedValue) |
void |
writeObjectId(ObjectId objectId)
Write a BSON ObjectId
|
void |
writeRaw(char c) |
void |
writeRaw(char[] text,
int offset,
int len) |
void |
writeRaw(java.lang.String text) |
void |
writeRaw(java.lang.String text,
int offset,
int len) |
void |
writeRawUTF8String(byte[] text,
int offset,
int length) |
void |
writeRegex(java.util.regex.Pattern pattern)
Write a BSON regex
|
void |
writeStartArray() |
void |
writeStartObject() |
void |
writeString(char[] text,
int offset,
int len) |
void |
writeString(java.lang.String text) |
void |
writeSymbol(Symbol symbol)
Write a BSON Symbol object
|
void |
writeTimestamp(Timestamp timestamp)
Write a MongoDB timestamp
|
void |
writeUTF8String(byte[] text,
int offset,
int length) |
_asString, _checkStdFeatureChanges, _constructDefaultPrettyPrinter, _decodeSurrogate, disable, enable, getCodec, getCurrentValue, getFeatureMask, getOutputContext, isClosed, isEnabled, overrideStdFeatures, setCodec, setCurrentValue, setFeatureMask, useDefaultPrettyPrinter, version, writeBinary, writeFieldName, writeObject, writeRawValue, writeRawValue, writeRawValue, writeRawValue, writeStartObject, writeString, writeTree_reportError, _reportUnsupportedOperation, _throwInternal, _verifyOffsets, _writeSimpleObject, canOmitFields, canUseSchema, canWriteBinaryNatively, canWriteFormattedNumbers, canWriteObjectId, canWriteTypeId, configure, copyCurrentEvent, copyCurrentStructure, getFormatFeatures, getHighestEscapedChar, getOutputBuffered, getOutputTarget, getPrettyPrinter, getSchema, overrideFormatFeatures, setHighestNonEscapedChar, setPrettyPrinter, setRootValueSeparator, setSchema, writeArray, writeArray, writeArray, writeArrayFieldStart, writeBinary, writeBinary, writeBinary, writeBinaryField, writeBooleanField, writeEmbeddedObject, writeFieldId, writeNullField, writeNumber, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeNumberField, writeObjectField, writeObjectFieldStart, writeObjectId, writeObjectRef, writeOmittedField, writeRaw, writeStartArray, writeString, writeStringField, writeTypeId, writeTypePrefix, writeTypeSuffixprotected final int _bsonFeatures
BsonGenerator.Features are enabled.protected final java.io.OutputStream _out
protected final DynamicOutputBuffer _buffer
protected int _typeMarker
protected BsonGenerator.DocumentInfo _currentDocument
protected boolean nextObjectIsEmbeddedInValue
protected com.fasterxml.jackson.core.io.CharacterEscapes _characterEscapes
protected int[] _outputEscapes
_characterEscapes is not null,
see setCharacterEscapes(CharacterEscapes))public BsonGenerator(int jsonFeatures,
int bsonFeatures,
java.io.OutputStream out)
jsonFeatures - bit flag composed of bits that indicate which
JsonGenerator.Features are enabled.bsonFeatures - bit flag composed of bits that indicate which
BsonGenerator.Features are enabled.out - the output stream to write topublic com.fasterxml.jackson.core.JsonGenerator setCharacterEscapes(com.fasterxml.jackson.core.io.CharacterEscapes esc)
setCharacterEscapes in class com.fasterxml.jackson.core.JsonGeneratorpublic com.fasterxml.jackson.core.io.CharacterEscapes getCharacterEscapes()
getCharacterEscapes in class com.fasterxml.jackson.core.JsonGeneratorprotected boolean isEnabled(BsonGenerator.Feature f)
f - the featureprotected boolean isArray()
protected int getAndIncCurrentArrayPos()
protected void reserveHeader()
protected void putHeader(int pos)
pos - the position where to write the headerpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class com.fasterxml.jackson.core.base.GeneratorBasejava.io.IOExceptionprotected void _releaseBuffers()
_releaseBuffers in class com.fasterxml.jackson.core.base.GeneratorBasepublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class com.fasterxml.jackson.core.base.GeneratorBasejava.io.IOExceptionpublic void writeStartArray()
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeStartArray in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeEndArray()
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeEndArray in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeStartObject()
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeStartObject in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionprotected void _writeStartObject(boolean array)
throws java.io.IOException
array - true if the embedded object is an arrayjava.io.IOException - if the document could not be createdpublic void writeEndObject()
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeEndObject in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionprotected void writeEndObjectInternal()
protected void _writeArrayFieldNameIfNeeded()
throws java.io.IOException
java.io.IOException - if the field name could not be writtenpublic void writeFieldName(java.lang.String name)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeFieldName in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionprotected void _writeFieldName(java.lang.String name)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
java.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionprotected void _verifyValueWrite(java.lang.String typeMsg)
throws java.io.IOException
_verifyValueWrite in class com.fasterxml.jackson.core.base.GeneratorBasejava.io.IOExceptionprotected void flushBuffer()
throws java.io.IOException
java.io.IOException - if flushing failedpublic void writeString(java.lang.String text)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeString in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeString(char[] text,
int offset,
int len)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeString in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeRaw(java.lang.String text)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeRaw in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeRaw(java.lang.String text,
int offset,
int len)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeRaw in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeRaw(char[] text,
int offset,
int len)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeRaw in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeRaw(char c)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeRaw in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant,
byte[] data,
int offset,
int len)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeBinary in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeBinary(com.fasterxml.jackson.core.Base64Variant b64variant,
byte subType,
byte[] data,
int offset,
int len)
throws java.io.IOException
writeBinary(Base64Variant, byte, byte[], int, int),
but with the possibility to specify a binary subtype (see
BsonConstants).b64variant - base64 variant to use (will be ignored for BSON)subType - the binary subtypedata - the binary data to writeoffset - the offset of the first byte to writelen - the number of bytes to writejava.io.IOException - if the binary data could not be writtenpublic void writeNumber(int v)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(long v)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(java.math.BigInteger v)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(double d)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(float f)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(java.math.BigDecimal dec)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNumber(java.lang.String encodedValue)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException,
java.lang.UnsupportedOperationException
writeNumber in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionjava.lang.UnsupportedOperationExceptionpublic void writeBoolean(boolean state)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeBoolean in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeNull()
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeNull in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeRawUTF8String(byte[] text,
int offset,
int length)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeRawUTF8String in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeUTF8String(byte[] text,
int offset,
int length)
throws java.io.IOException,
com.fasterxml.jackson.core.JsonGenerationException
writeUTF8String in class com.fasterxml.jackson.core.JsonGeneratorjava.io.IOExceptioncom.fasterxml.jackson.core.JsonGenerationExceptionpublic void writeDateTime(java.util.Date date)
throws java.io.IOException
date - The date to writejava.io.IOException - If an error occurred in the stream while writingpublic void writeObjectId(ObjectId objectId) throws java.io.IOException
objectId - The objectId to writejava.io.IOException - If an error occurred in the stream while writingprotected java.lang.String flagsToRegexOptions(int flags)
flags - the Java flagspublic void writeRegex(java.util.regex.Pattern pattern)
throws java.io.IOException
pattern - The regex to writejava.io.IOException - If an error occurred in the stream while writingpublic void writeTimestamp(Timestamp timestamp) throws java.io.IOException
timestamp - The timestamp to writejava.io.IOException - If an error occurred in the stream while writingpublic void writeJavaScript(JavaScript javaScript, com.fasterxml.jackson.databind.SerializerProvider provider) throws java.io.IOException
javaScript - The javaScript to writeprovider - The serializer provider, for serializing the scopejava.io.IOException - If an error occurred in the stream while writingpublic void writeSymbol(Symbol symbol) throws java.io.IOException
symbol - The symbol to writejava.io.IOException - If an error occurred in the stream while writingprotected int _writeString(java.lang.String string)
throws java.io.IOException
string - The string to writejava.io.IOException - If an error occurred in the stream while writingprotected int _writeCString(java.lang.String string)
throws java.io.IOException
string - The string to writejava.io.IOException - If an error occurred in the stream while writingprotected java.lang.String escapeCharacters(java.lang.String string)
throws java.io.IOException
_characterEscapes. If
there are no character escapes returns the original string.string - the string to escapejava.io.IOException - if an escape sequence could not be retrieved