public class BufferingBsonOutputStream extends FilterOutputStream
BufferingBsonOutputStream
provides a class to write BSON documents
based on the BSON specification.
Users of this class must make sure that the flushBuffer()
method is
called after calling any of the writeXXX()
methods.
out
Constructor and Description |
---|
BufferingBsonOutputStream(OutputStream output)
Creates a new
BufferingBsonOutputStream . |
BufferingBsonOutputStream(OutputStream output,
StringEncoderCache cache)
Creates a new
BufferingBsonOutputStream . |
BufferingBsonOutputStream(RandomAccessOutputStream output)
Creates a new
BufferingBsonOutputStream . |
Modifier and Type | Method and Description |
---|---|
void |
flushBuffer()
Writes any pending data to the underlying stream.
|
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
StringEncoderCache should be controlled
directory. This method will be removed after the 2.1.0
release. |
RandomAccessOutputStream |
getOutput()
Returns the output buffer.
|
long |
getPosition()
Returns the current position in the stream.
|
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. |
void |
write(byte[] b)
Writes
b.length bytes to this output stream. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to this output stream. |
long |
write(Document doc)
Writes the Document in BSON format to the underlying stream.
|
void |
writeByte(byte b)
Writes a single byte to the output buffer.
|
void |
writeBytes(byte[] data)
Writes a sequence of bytes to the output buffer.
|
void |
writeCString(String... strings)
Writes a "Cstring" to the output buffer.
|
void |
writeDocument(Document doc)
Writes the Document in BSON format to the underlying stream.
|
void |
writeInt(int value)
Writes the integer value in little-endian byte order to the output
buffer.
|
void |
writeIntAt(long position,
int value)
Similar to
writeInt(int) but allows a portion of the already
written buffer to be re-written. |
void |
writeLong(long value)
Write the long value in little-endian byte order to the output buffer.
|
void |
writeString(String string)
Writes a "string" to the output buffer.
|
close, flush, write
public BufferingBsonOutputStream(OutputStream output)
BufferingBsonOutputStream
.output
- The stream to write to.public BufferingBsonOutputStream(OutputStream output, StringEncoderCache cache)
BufferingBsonOutputStream
.output
- The stream to write to.cache
- The cache for encoding strings.public BufferingBsonOutputStream(RandomAccessOutputStream output)
BufferingBsonOutputStream
.output
- The stream to write to.public void flushBuffer() throws IOException
Users should call this method after calling any of the
writeXXX(...)
methods.
IOException
- On a failure to write to the underlying document.@Deprecated public int getMaxCachedStringEntries()
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.@Deprecated public int getMaxCachedStringLength()
StringEncoderCache
should be controlled
directory. This method will be removed after the 2.1.0
release.public RandomAccessOutputStream getOutput()
public long getPosition()
@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.public void write(byte[] b) throws IOException
b.length
bytes to this output stream.
Calls the write(byte[]) of the underlying stream.
write
in class FilterOutputStream
b
- the data to be written.IOException
- if an I/O error occurs.FilterOutputStream.write(byte[], int, int)
public void write(byte[] b, int off, int len) throws IOException
len
bytes from the specified byte
array
starting at offset off
to this output stream.
Calls the write(byte[],int,int) of the underlying stream.
write
in class FilterOutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.IOException
- if an I/O error occurs.FilterOutputStream.write(int)
public long write(Document doc) throws IOException
This method automatically calls flushBuffer()
.
doc
- The document to write.IOException
- On a failure to write to the underlying document.public void writeByte(byte b)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
b
- The byte to write.public void writeBytes(byte[] data)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
data
- The bytes to write.public void writeCString(String... strings)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
strings
- The CString to write. The strings are concatenated into a
single CString value.public void writeDocument(Document doc) throws IOException
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
doc
- The document to write.IOException
- On a failure to write to the underlying document.public void writeInt(int value)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
value
- The value to write.public void writeIntAt(long position, int value)
writeInt(int)
but allows a portion of the already
written buffer to be re-written.
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
position
- The position to write at. This location should have already
been written.value
- The integer value to write.public void writeLong(long value)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
value
- The long to write.public void writeString(String string)
Users of this method must call flushBuffer()
or the contents
will not be written to the wrapped stream.
string
- The String to write.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.