Package org.bson.io
Interface BsonOutput
-
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
BasicOutputBuffer
,OutputBuffer
public interface BsonOutput extends Closeable
An output stream that is optimized for writing BSON values directly to the underlying stream.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
int
getPosition()
Gets the current position in the stream.int
getSize()
Gets the current size of the stream in number of bytes.void
truncateToPosition(int newPosition)
Truncates this stream to the new position.void
writeByte(int value)
Write a single byte to the stream.void
writeBytes(byte[] bytes)
Writes all the bytes in the byte array to the stream.void
writeBytes(byte[] bytes, int offset, int length)
Writeslength
bytes from the byte array, starting atoffset
.void
writeCString(String value)
Writes a BSON CString to the stream.void
writeDouble(double value)
Writes a BSON double to the stream.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
writeObjectId(ObjectId value)
Writes a BSON ObjectId to the stream.void
writeString(String value)
Writes a BSON String to the stream.
-
-
-
Method Detail
-
getPosition
int getPosition()
Gets the current position in the stream.- Returns:
- the current position
-
getSize
int getSize()
Gets the current size of the stream in number of bytes.- Returns:
- the size of the stream
-
truncateToPosition
void truncateToPosition(int newPosition)
Truncates this stream to the new position. After this call, both size and position will equal the new position.- Parameters:
newPosition
- the new position, which must be greater than or equal to 0 and less than the current size.
-
writeBytes
void writeBytes(byte[] bytes)
Writes all the bytes in the byte array to the stream.- Parameters:
bytes
- the non-null byte array
-
writeBytes
void writeBytes(byte[] bytes, int offset, int length)
Writeslength
bytes from the byte array, starting atoffset
.- Parameters:
bytes
- the non-null byte arrayoffset
- the offset to start writing fromlength
- the number of bytes to write
-
writeByte
void writeByte(int value)
Write a single byte to the stream. The byte to be written is the eight low-order bits of the specified value. The 24 high-order bits of the value are ignored.- Parameters:
value
- the value
-
writeCString
void writeCString(String value)
Writes a BSON CString to the stream.- Parameters:
value
- the value
-
writeString
void writeString(String value)
Writes a BSON String to the stream.- Parameters:
value
- the value
-
writeDouble
void writeDouble(double value)
Writes a BSON double to the stream.- Parameters:
value
- the value
-
writeInt32
void writeInt32(int value)
Writes a 32-bit BSON integer to the stream.- Parameters:
value
- the value
-
writeInt32
void writeInt32(int position, int value)
Writes a 32-bit BSON integer to the stream at the given position. This is useful for patching in the size of a document once the last byte of it has been encoded and its size it known.- Parameters:
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 value
-
writeInt64
void writeInt64(long value)
Writes a 64-bit BSON integer to the stream.- Parameters:
value
- the value
-
writeObjectId
void writeObjectId(ObjectId value)
Writes a BSON ObjectId to the stream.- Parameters:
value
- the value
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-