Package org.bson.io

Class OutputBuffer

    • Constructor Summary

      Constructors 
      Constructor Description
      OutputBuffer()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      abstract <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  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.
      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  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  str)
      Writes a BSON String to the stream.
      • Methods inherited from class java.io.

        ,
      • Methods inherited from class java.lang.

        , , , , , , , , ,
    • Constructor Detail

      • OutputBuffer

        public OutputBuffer()
    • Method Detail

      • write

        public void write​(byte[] b)
        Overrides:
         in class 
      • close

        public void close()
        Specified by:
         in interface 
        Specified by:
        close in interface BsonOutput
        Specified by:
         in interface 
        Overrides:
         in class 
      • write

        public void write​(byte[] bytes,
                          int offset,
                          int length)
        Overrides:
         in class 
      • writeBytes

        public void writeBytes​(byte[] bytes)
        Description copied from interface: BsonOutput
        Writes all the bytes in the byte array to the stream.
        Specified by:
        writeBytes in interface BsonOutput
        Parameters:
        bytes - the non-null byte array
      • writeInt32

        public void writeInt32​(int value)
        Description copied from interface: BsonOutput
        Writes a 32-bit BSON integer to the stream.
        Specified by:
        writeInt32 in interface BsonOutput
        Parameters:
        value - the value
      • writeInt32

        public void writeInt32​(int position,
                               int value)
        Description copied from interface: BsonOutput
        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.
        Specified by:
        writeInt32 in interface BsonOutput
        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

        public void writeInt64​(long value)
        Description copied from interface: BsonOutput
        Writes a 64-bit BSON integer to the stream.
        Specified by:
        writeInt64 in interface BsonOutput
        Parameters:
        value - the value
      • writeDouble

        public void writeDouble​(double x)
        Description copied from interface: BsonOutput
        Writes a BSON double to the stream.
        Specified by:
        writeDouble in interface BsonOutput
        Parameters:
        x - the value
      • writeString

        public void writeString​( str)
        Description copied from interface: BsonOutput
        Writes a BSON String to the stream.
        Specified by:
        writeString in interface BsonOutput
        Parameters:
        str - the value
      • writeCString

        public void writeCString​( value)
        Description copied from interface: BsonOutput
        Writes a BSON CString to the stream.
        Specified by:
        writeCString in interface BsonOutput
        Parameters:
        value - the value
      • writeObjectId

        public void writeObjectId​(ObjectId value)
        Description copied from interface: BsonOutput
        Writes a BSON ObjectId to the stream.
        Specified by:
        writeObjectId in interface BsonOutput
        Parameters:
        value - the value
      • size

        public int size()
        Gets the output size in bytes.
        Returns:
        the size
      • pipe

        public abstract int pipe​( out)
                          throws 
        Pipe the contents of this output buffer into the given output stream
        Parameters:
        out - the stream to pipe to
        Returns:
        number of bytes written to the stream
        Throws:
        - if the stream throws an exception
      • getByteBuffers

        public abstract <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.

        Note that the byte buffers may be read-only.

        Returns:
        the non-null list of byte buffers, in LITTLE_ENDIAN order
      • truncateToPosition

        public abstract void truncateToPosition​(int newPosition)
        Description copied from interface: BsonOutput
        Truncates this stream to the new position. After this call, both size and position will equal the new position.
        Specified by:
        truncateToPosition in interface BsonOutput
        Parameters:
        newPosition - the new position, which must be greater than or equal to 0 and less than the current size.
      • toByteArray

        public byte[] toByteArray()
        Gets a copy of the buffered bytes.
        Returns:
        the byte array
        See Also:
        pipe(java.io.OutputStream)
      • write

        public void write​(int value)
        Specified by:
         in class 
      • writeInt

        public void writeInt​(int value)
        Writes the given integer value to the buffer.
        Parameters:
        value - the value to write
        See Also:
        writeInt32(int)
      • toString

        public  toString()
        Overrides:
         in class 
      • write

        protected abstract void write​(int position,
                                      int value)
        Write the specified byte at the specified position.
        Parameters:
        position - the position, which must be greater than equal to 0 and at least 4 less than the stream size
        value - the value to write. The 24 high-order bits of the value are ignored.
      • writeLong

        public void writeLong​(long value)
        Writes the given long value to the buffer.
        Parameters:
        value - the value to write
        See Also:
        writeInt64(long)