Class ExpandableBufferWriter

  • Direct Known Subclasses:
    Grizzly2ExpandableBufferWriter

    public abstract class ExpandableBufferWriter
    extends java.lang.Object
    Expandable Buffer writer, which adopts its size during while getting more data.
    Author:
    Alexey Stashok
    • Constructor Detail

      • ExpandableBufferWriter

        public ExpandableBufferWriter()
    • Method Detail

      • getBuffer

        public abstract Buffer getBuffer()
      • toBuffer

        public abstract Buffer toBuffer()
      • position

        public abstract int position()
      • position

        public abstract void position​(int pos)
      • ensureCapacity

        protected abstract void ensureCapacity​(int delta)
      • reserve

        public void reserve​(int size)
      • put

        public ExpandableBufferWriter put​(byte b)
        Relative put method  (optional operation).

        Writes the given byte into this buffer at the current position, and then increments the position.

        Parameters:
        b - The byte to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If this buffer's current position is not smaller than its limit
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • put

        public ExpandableBufferWriter put​(int index,
                                          byte b)
        Absolute put method  (optional operation).

        Writes the given byte into this buffer at the given index.

        Parameters:
        index - The index at which the byte will be written
        b - The byte value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • put

        public ExpandableBufferWriter put​(byte[] src)
        Relative bulk put method  (optional operation).

        This method transfers the entire content of the given source byte array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation

         dst.put(a, 0, a.length)
         
        Parameters:
        src - the source byte array
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there is insufficient space in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • put

        public ExpandableBufferWriter put​(byte[] src,
                                          int offset,
                                          int length)
        Relative bulk put method  (optional operation).

        This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length > remaining(), then no bytes are transferred and a BufferOverflowException is thrown.

        Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

        In other words, an invocation of this method of the form dst.put(src, off, len) has exactly the same effect as the loop

         for (int i = off; i < off + len; i++)
             dst.put(a[i]);
         
        except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.

        Parameters:
        src - The array from which bytes are to be read
        offset - The offset within the array of the first byte to be read; must be non-negative and no larger than array.length
        length - The number of bytes to be read from the given array; must be non-negative and no larger than array.length - offset
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there is insufficient space in this buffer
        java.lang.IndexOutOfBoundsException - If the preconditions on the offset and length parameters do not hold
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putChar

        public ExpandableBufferWriter putChar​(char value)
        Relative put method for writing a char value  (optional operation).

        Writes two bytes containing the given char value, in the current byte order, into this buffer at the current position, and then increments the position by two.

        Parameters:
        value - The char value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than two bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putChar

        public ExpandableBufferWriter putChar​(int index,
                                              char value)
        Absolute put method for writing a char value  (optional operation).

        Writes two bytes containing the given char value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The char value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus one
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putShort

        public ExpandableBufferWriter putShort​(short value)
        Relative put method for writing a short value  (optional operation).

        Writes two bytes containing the given short value, in the current byte order, into this buffer at the current position, and then increments the position by two.

        Parameters:
        value - The short value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than two bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putShort

        public ExpandableBufferWriter putShort​(int index,
                                               short value)
        Absolute put method for writing a short value  (optional operation).

        Writes two bytes containing the given short value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The short value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus one
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putInt

        public ExpandableBufferWriter putInt​(int value)
        Relative put method for writing an int value  (optional operation).

        Writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.

        Parameters:
        value - The int value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than four bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putInt

        public ExpandableBufferWriter putInt​(int index,
                                             int value)
        Absolute put method for writing an int value  (optional operation).

        Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The int value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus three
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putLong

        public ExpandableBufferWriter putLong​(long value)
        Relative put method for writing a long value  (optional operation).

        Writes eight bytes containing the given long value, in the current byte order, into this buffer at the current position, and then increments the position by eight.

        Parameters:
        value - The long value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than eight bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putLong

        public ExpandableBufferWriter putLong​(int index,
                                              long value)
        Absolute put method for writing a long value  (optional operation).

        Writes eight bytes containing the given long value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The long value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus seven
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putFloat

        public ExpandableBufferWriter putFloat​(float value)
        Relative put method for writing a float value  (optional operation).

        Writes four bytes containing the given float value, in the current byte order, into this buffer at the current position, and then increments the position by four.

        Parameters:
        value - The float value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than four bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putFloat

        public ExpandableBufferWriter putFloat​(int index,
                                               float value)
        Absolute put method for writing a float value  (optional operation).

        Writes four bytes containing the given float value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The float value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus three
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putDouble

        public ExpandableBufferWriter putDouble​(double value)
        Relative put method for writing a double value  (optional operation).

        Writes eight bytes containing the given double value, in the current byte order, into this buffer at the current position, and then increments the position by eight.

        Parameters:
        value - The double value to be written
        Returns:
        This buffer writer
        Throws:
        java.nio.BufferOverflowException - If there are fewer than eight bytes remaining in this buffer
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • putDouble

        public ExpandableBufferWriter putDouble​(int index,
                                                double value)
        Absolute put method for writing a double value  (optional operation).

        Writes eight bytes containing the given double value, in the current byte order, into this buffer at the given index.

        Parameters:
        index - The index at which the bytes will be written
        value - The double value to be written
        Returns:
        This buffer writer
        Throws:
        java.lang.IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit, minus seven
        java.nio.ReadOnlyBufferException - If this buffer is read-only
      • asOutputStream

        public java.io.OutputStream asOutputStream()