public class BsonOutputStream extends Object
OutputStream
to handle writing BSON primitives.Modifier and Type | Field and Description |
---|---|
protected IOException |
myError
Any thrown exceptions.
|
protected OutputStream |
myOutput
Output buffer for spooling the written document.
|
protected StringEncoder |
myStringEncoder
The encoder for strings.
|
protected com.allanbank.mongodb.bson.io.WriteVisitor |
myWriteVisitor
The visitor for writing BSON documents.
|
static Charset |
UTF8
UTF-8 Character set for encoding strings.
|
Constructor and Description |
---|
BsonOutputStream(OutputStream output)
Creates a new
BsonOutputStream . |
BsonOutputStream(OutputStream output,
StringEncoderCache cache)
Creates a new
BsonOutputStream . |
Modifier and Type | Method and Description |
---|---|
IOException |
getError()
Returns the I/O exception encountered by the visitor.
|
int |
getMaxCachedStringEntries()
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
int |
getMaxCachedStringLength()
Deprecated.
The cache
StringDecoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
StringEncoder |
getStringEncoder()
Returns the encoder value.
|
boolean |
hasError()
Returns true if the visitor had an I/O error.
|
void |
reset()
Clears any errors.
|
void |
setMaxCachedStringEntries(int maxCacheEntries)
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
void |
setMaxCachedStringLength(int maxlength)
Deprecated.
The cache
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
int |
sizeOf(Document document)
Deprecated.
Replaced with
Document.size() . This method will be
removed after the 2.2.0 release. |
int |
sizeOfCString(String... strings)
Returns the size of the writing the strings as a c-string.
|
int |
sizeOfString(String string)
Returns the size of the writing the string as a string.
|
void |
writeByte(byte b)
Writes a single byte to the stream.
|
void |
writeBytes(byte[] data)
Writes a sequence of bytes to the under lying stream.
|
protected void |
writeBytes(byte[] data,
int offset,
int length)
Writes a sequence of bytes to the under lying stream.
|
void |
writeCString(String... strings)
Writes a "Cstring" to the stream.
|
void |
writeDocument(Document document)
Writes a BSON
Document to the stream. |
void |
writeInt(int value)
Write the integer value in little-endian byte order.
|
void |
writeLong(long value)
Write the long value in little-endian byte order.
|
void |
writeString(String string)
Writes a "string" to the stream.
|
protected void |
writeUtf8(String string)
Writes the string as a UTF-8 string.
|
public static final Charset UTF8
protected IOException myError
protected final OutputStream myOutput
protected final StringEncoder myStringEncoder
protected final com.allanbank.mongodb.bson.io.WriteVisitor myWriteVisitor
public BsonOutputStream(OutputStream output)
BsonOutputStream
.output
- The underlying Stream to write to.public BsonOutputStream(OutputStream output, StringEncoderCache cache)
BsonOutputStream
.output
- The underlying Stream to write to.cache
- The cache for encoding string.public IOException getError()
@Deprecated public int getMaxCachedStringEntries()
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.@Deprecated public int getMaxCachedStringLength()
StringDecoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.public StringEncoder getStringEncoder()
public boolean hasError()
public void reset()
@Deprecated public void setMaxCachedStringEntries(int maxCacheEntries)
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.maxCacheEntries
- The new value for the maximum number of strings that may have
their encoded form cached.@Deprecated public void setMaxCachedStringLength(int maxlength)
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.maxlength
- The new value for the length for a string that the encoder is
allowed to cache.@Deprecated public int sizeOf(Document document)
Document.size()
. This method will be
removed after the 2.2.0 release.Document
as a BSON document.document
- The document to determine the size of.Document
as a BSON document.public int sizeOfCString(String... strings)
strings
- The 'C' strings to determine the size of.public int sizeOfString(String string)
string
- The 'UTF8' string to determine the size of.public void writeByte(byte b)
b
- The byte to write.public void writeBytes(byte[] data)
data
- The bytes to write.public void writeCString(String... strings)
strings
- The CString to write. The strings are concatenated into a
single CString value.public void writeDocument(Document document) throws IOException
Document
to the stream.document
- The Document
to write.IOException
- On a failure writing the document.public void writeInt(int value)
value
- The integer to write.public void writeLong(long value)
value
- The long to write.public void writeString(String string)
string
- The String to write.protected void writeBytes(byte[] data, int offset, int length)
data
- The bytes to write.offset
- The offset into the buffer to start writing data from.length
- The number of bytes to write.protected void writeUtf8(String string)
string
- The string to encode.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.