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 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. | 
| Modifier and Type | Method and Description | 
|---|---|
IOException | 
getError()
Returns the I/O exception encountered by the visitor. 
 | 
boolean | 
hasError()
Returns true if the visitor had an I/O error. 
 | 
void | 
reset()
Clears any errors. 
 | 
int | 
sizeOf(Document document)
Returns the size of the writing the  
Document as a BSON document. | 
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. 
 | 
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 com.allanbank.mongodb.bson.io.WriteVisitor myWriteVisitor
public BsonOutputStream(OutputStream output)
BsonOutputStream.output - The underlying Stream to write to.public IOException getError()
public boolean hasError()
public void reset()
public int sizeOf(Document document)
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 writeUtf8(String string)
string - The string to encode.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.