Class BinaryWriteBuffer

  • All Implemented Interfaces:
    WriteBuffer

    public final class BinaryWriteBuffer
    extends ByteArrayWriteBuffer
    a WriteBuffer implementation whose primary purpose is to be used to create Binary objects.
    Author:
    cp 2005.06.02
    • Constructor Detail

      • BinaryWriteBuffer

        public BinaryWriteBuffer​(int cbCap)
        Construct an BinaryWriteBuffer with a certain initial capacity.
        Parameters:
        cbCap - initial capacity
        Throws:
        IllegalArgumentException - if cbCap is negative
      • BinaryWriteBuffer

        public BinaryWriteBuffer​(int cbCap,
                                 int cbMax)
        Construct an BinaryWriteBuffer with a certain initial capacity and a certain maximum capacity.
        Parameters:
        cbCap - initial capacity
        cbMax - maximum capacity
        Throws:
        IllegalArgumentException - if cbCap or cbMax is negative, or if cbCap is greater than cbMax
    • Method Detail

      • toBinary

        public Binary toBinary()
        Returns a new Binary object that holds the complete contents of this WriteBuffer.

        This method is functionally equivalent to the following code:

        
         return getUnsafeReadBuffer().toBinary();
         
        Specified by:
        toBinary in interface WriteBuffer
        Overrides:
        toBinary in class ByteArrayWriteBuffer
        Returns:
        the contents of this WriteBuffer as a Binary object
      • checkBounds

        protected void checkBounds​(int of,
                                   int cb)
        Validate the ranges for the passed bounds and make sure that the underlying array is big enough to handle them.

        Note: This method prevents all modifications from occurring once the BinaryWriteBuffer has supplied its byte array to a Binary object.

        Overrides:
        checkBounds in class ByteArrayWriteBuffer
        Parameters:
        of - the offset that data is about to be written to
        cb - the length of the data that is about to be written