public class ByteBufferBsonOutput extends OutputBuffer
Modifier and Type | Class and Description |
---|---|
private static class |
ByteBufferBsonOutput.BufferPositionPair |
Modifier and Type | Field and Description |
---|---|
private java.util.List<ByteBuf> |
bufferList |
private BufferProvider |
bufferProvider |
private boolean |
closed |
private int |
curBufferIndex |
static int |
INITIAL_BUFFER_SIZE |
private static int |
INITIAL_SHIFT |
static int |
MAX_BUFFER_SIZE |
private static int |
MAX_SHIFT |
private int |
position |
Constructor and Description |
---|
ByteBufferBsonOutput(BufferProvider bufferProvider)
Construct an instance that uses the given buffer provider to allocate byte buffers as needs as it grows.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
private void |
ensureOpen() |
private ByteBufferBsonOutput.BufferPositionPair |
getBufferPositionPair(int absolutePosition) |
private ByteBuf |
getByteBufferAtIndex(int index) |
java.util.List<ByteBuf> |
getByteBuffers()
Get a list of byte buffers that are prepared to be read from; in other words, whose position is 0 and whose limit is the number of
bytes that should read.
|
private ByteBuf |
getCurrentByteBuffer() |
int |
getPosition()
Gets the current position in the stream.
|
int |
getSize()
Gets the current size of the stream in number of bytes.
|
int |
pipe(java.io.OutputStream out)
Pipe the contents of this output buffer into the given output stream
|
void |
truncateToPosition(int newPosition)
Truncates this stream to the new position.
|
protected void |
write(int absolutePosition,
int value)
Write the specified byte at the specified position.
|
void |
writeByte(int value)
Write a single byte to the stream.
|
void |
writeBytes(byte[] bytes,
int offset,
int length)
Writes
length bytes from the byte array, starting at offset . |
size, toByteArray, toString, write, write, write, writeBytes, writeCString, writeDouble, writeInt, writeInt32, writeInt32, writeInt64, writeLong, writeObjectId, writeString
private static final int MAX_SHIFT
private static final int INITIAL_SHIFT
public static final int INITIAL_BUFFER_SIZE
public static final int MAX_BUFFER_SIZE
private final BufferProvider bufferProvider
private final java.util.List<ByteBuf> bufferList
private int curBufferIndex
private int position
private boolean closed
public ByteBufferBsonOutput(BufferProvider bufferProvider)
bufferProvider
- the non-null buffer providerpublic void writeBytes(byte[] bytes, int offset, int length)
BsonOutput
length
bytes from the byte array, starting at offset
.bytes
- the non-null byte arrayoffset
- the offset to start writing fromlength
- the number of bytes to writepublic void writeByte(int value)
BsonOutput
value
- the valueprivate ByteBuf getCurrentByteBuffer()
private ByteBuf getByteBufferAtIndex(int index)
public int getPosition()
BsonOutput
public int getSize()
BsonOutput
protected void write(int absolutePosition, int value)
OutputBuffer
write
in class OutputBuffer
absolutePosition
- the position, which must be greater than equal to 0 and at least 4 less than the stream sizevalue
- the value to write. The 24 high-order bits of the value are ignored.public java.util.List<ByteBuf> getByteBuffers()
OutputBuffer
Note that the byte buffers may be read-only.
getByteBuffers
in class OutputBuffer
public int pipe(java.io.OutputStream out) throws java.io.IOException
OutputBuffer
pipe
in class OutputBuffer
out
- the stream to pipe tojava.io.IOException
- if the stream throws an exceptionpublic void truncateToPosition(int newPosition)
BsonOutput
truncateToPosition
in interface BsonOutput
truncateToPosition
in class OutputBuffer
newPosition
- the new position, which must be greater than or equal to 0 and less than the current size.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface BsonOutput
close
in class OutputBuffer
private ByteBufferBsonOutput.BufferPositionPair getBufferPositionPair(int absolutePosition)
private void ensureOpen()