Class WritableByteBuffer


  • public class WritableByteBuffer
    extends Object
    A byte buffer provides convenient methods to manipulate a byte array.
    • Constructor Detail

      • WritableByteBuffer

        public WritableByteBuffer​(int capacity)
        Constructs a new byte buffer. It will use a byte array with the specified capacity. The capacity will automatically grow if more space is needed.
        Parameters:
        capacity - the initial capacity
      • WritableByteBuffer

        public WritableByteBuffer​(WritableByteBuffer other)
        Constructs a new byte buffer and copies the content from another byte buffer.
        Parameters:
        other - the other byte buffer
    • Method Detail

      • get

        public byte get​(int index)
        Returns the byte at the specified index.
        Parameters:
        index - the index
        Returns:
        the byte
      • size

        public int size()
        Returns the size of this buffer. This is not the capacity.
        Returns:
        the size
      • clear

        public void clear()
        Removes all bytes from the buffer.
      • append

        public void append​(byte b)
        Appends the specified byte to the end of the buffer.
        Parameters:
        b - the byte
      • append

        public void append​(byte[] bs,
                           int off,
                           int len)
        Appends bytes from the specified byte array to the end of this buffer.
        Parameters:
        bs - the byte array
        off - the index of the first byte to append
        len - the number of bytes to append
      • append

        public void append​(WritableByteBuffer other,
                           int off,
                           int len)
        Appends bytes from the specified byte buffer to the end of this buffer.
        Parameters:
        other - the byte buffer
        off - the index of the first byte to append
        len - the number of bytes to append
      • removeHead

        public void removeHead​(int n)
        Removes the first n bytes from this buffer.
        Parameters:
        n - the number of bytes to remove
      • removeFirst

        public byte removeFirst()
        Removes the first byte from this buffer and returns it.
        Returns:
        the removed byte
      • toByteArray

        public byte[] toByteArray()
        Returns a byte array with the contents of this buffer.
        Returns:
        the byte array