public abstract class OutputBuffer extends OutputStream implements BsonOutput
BsonOutput
.Constructor and Description |
---|
OutputBuffer() |
Modifier and Type | Method and Description |
---|---|
void |
close() |
abstract 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.
|
abstract int |
pipe(OutputStream out)
Pipe the contents of this output buffer into the given output stream
|
int |
size()
Gets the output size in bytes.
|
byte[] |
toByteArray()
Gets a copy of the buffered bytes.
|
String |
toString() |
abstract void |
truncateToPosition(int newPosition)
Truncates this stream to the new position.
|
void |
write(byte[] b) |
void |
write(byte[] bytes,
int offset,
int length) |
void |
write(int value) |
protected abstract void |
write(int position,
int value)
Write the specified byte at the specified position.
|
void |
writeBytes(byte[] bytes)
Writes all the bytes in the byte array to the stream.
|
void |
writeCString(String value)
Writes a BSON CString to the stream.
|
void |
writeDouble(double x)
Writes a BSON double to the stream.
|
void |
writeInt(int value)
Writes the given integer value to the buffer.
|
void |
writeInt32(int value)
Writes a 32-bit BSON integer to the stream.
|
void |
writeInt32(int position,
int value)
Writes a 32-bit BSON integer to the stream at the given position.
|
void |
writeInt64(long value)
Writes a 64-bit BSON integer to the stream.
|
void |
writeLong(long value)
Writes the given long value to the buffer.
|
void |
writeObjectId(ObjectId value)
Writes a BSON ObjectId to the stream.
|
void |
writeString(String str)
Writes a BSON String to the stream.
|
flush
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getPosition, getSize, writeByte, writeBytes
public void write(byte[] b)
write
in class OutputStream
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface BsonOutput
close
in class OutputStream
public void write(byte[] bytes, int offset, int length)
write
in class OutputStream
public void writeBytes(byte[] bytes)
BsonOutput
writeBytes
in interface BsonOutput
bytes
- the non-null byte arraypublic void writeInt32(int value)
BsonOutput
writeInt32
in interface BsonOutput
value
- the valuepublic void writeInt32(int position, int value)
BsonOutput
writeInt32
in interface BsonOutput
position
- the position to write the value, which must be greater than or equal to 0 and less than or equal to the current sizevalue
- the valuepublic void writeInt64(long value)
BsonOutput
writeInt64
in interface BsonOutput
value
- the valuepublic void writeDouble(double x)
BsonOutput
writeDouble
in interface BsonOutput
x
- the valuepublic void writeString(String str)
BsonOutput
writeString
in interface BsonOutput
str
- the valuepublic void writeCString(String value)
BsonOutput
writeCString
in interface BsonOutput
value
- the valuepublic void writeObjectId(ObjectId value)
BsonOutput
writeObjectId
in interface BsonOutput
value
- the valuepublic int size()
public abstract int pipe(OutputStream out) throws IOException
out
- the stream to pipe toIOException
- if the stream throws an exceptionpublic abstract List<ByteBuf> getByteBuffers()
Note that the byte buffers may be read-only.
public abstract void truncateToPosition(int newPosition)
BsonOutput
truncateToPosition
in interface BsonOutput
newPosition
- the new position, which must be greater than or equal to 0 and less than the current size.public byte[] toByteArray()
pipe(java.io.OutputStream)
public void write(int value)
write
in class OutputStream
public void writeInt(int value)
value
- the value to writewriteInt32(int)
protected abstract void write(int position, int value)
position
- 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 void writeLong(long value)
value
- the value to writewriteInt64(long)