Package org.bson.io
Interface BsonOutput
- All Superinterfaces:
- AutoCloseable,- Closeable
- All Known Implementing Classes:
- BasicOutputBuffer,- OutputBuffer
An output stream that is optimized for writing BSON values directly to the underlying stream.
- Since:
- 3.0
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()intGets the current position in the stream.intgetSize()Gets the current size of the stream in number of bytes.voidtruncateToPosition(int newPosition) Truncates this stream to the new position.voidwriteByte(int value) Write a single byte to the stream.voidwriteBytes(byte[] bytes) Writes all the bytes in the byte array to the stream.voidwriteBytes(byte[] bytes, int offset, int length) Writeslengthbytes from the byte array, starting atoffset.voidwriteCString(String value) Writes a BSON CString to the stream.voidwriteDouble(double value) Writes a BSON double to the stream.voidwriteInt32(int value) Writes a 32-bit BSON integer to the stream.voidwriteInt32(int position, int value) Writes a 32-bit BSON integer to the stream at the given position.voidwriteInt64(long value) Writes a 64-bit BSON integer to the stream.voidwriteObjectId(ObjectId value) Writes a BSON ObjectId to the stream.voidwriteString(String value) Writes a BSON String to the stream.
- 
Method Details- 
getPositionint getPosition()Gets the current position in the stream.- Returns:
- the current position
 
- 
getSizeint getSize()Gets the current size of the stream in number of bytes.- Returns:
- the size of the stream
 
- 
truncateToPositionvoid 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.
 
- 
writeBytesvoid writeBytes(byte[] bytes) Writes all the bytes in the byte array to the stream.- Parameters:
- bytes- the non-null byte array
 
- 
writeBytesvoid writeBytes(byte[] bytes, int offset, int length) Writeslengthbytes from the byte array, starting atoffset.- Parameters:
- bytes- the non-null byte array
- offset- the offset to start writing from
- length- the number of bytes to write
 
- 
writeBytevoid 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
 
- 
writeCStringWrites a BSON CString to the stream.- Parameters:
- value- the value
 
- 
writeStringWrites a BSON String to the stream.- Parameters:
- value- the value
 
- 
writeDoublevoid writeDouble(double value) Writes a BSON double to the stream.- Parameters:
- value- the value
 
- 
writeInt32void writeInt32(int value) Writes a 32-bit BSON integer to the stream.- Parameters:
- value- the value
 
- 
writeInt32void 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 size
- value- the value
 
- 
writeInt64void writeInt64(long value) Writes a 64-bit BSON integer to the stream.- Parameters:
- value- the value
 
- 
writeObjectIdWrites a BSON ObjectId to the stream.- Parameters:
- value- the value
 
- 
closevoid close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 
-