Package org.bson.io

Interface BsonOutput

    • 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)
      Writes length bytes from the byte array, starting at offset.
      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)
        Writes length bytes from the byte array, starting at offset.
        Parameters:
        bytes - the non-null byte array
        offset - the offset to start writing from
        length - 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 size
        value - 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