Class ByteArrayBuffer

  • All Implemented Interfaces:
    ByteSequence

    public final class ByteArrayBuffer
    extends java.lang.Object
    implements ByteSequence
    A resizable byte array.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer  
      private int len  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(byte[] b, int off, int len)  
      void append​(int b)  
      byte[] buffer()  
      byte byteAt​(int i)
      Returns the byte value at the specified index.
      int capacity()  
      void clear()  
      private void expand​(int newlen)  
      int indexOf​(byte b)  
      int indexOf​(byte b, int beginIndex, int endIndex)  
      boolean isEmpty()  
      boolean isFull()  
      int length()
      Returns the length of this byte sequence.
      void remove​(int off, int len)  
      void setLength​(int len)  
      byte[] toByteArray()
      Copies the contents of this byte sequence into a newly allocated byte array and returns that array.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • buffer

        private byte[] buffer
      • len

        private int len
    • Constructor Detail

      • ByteArrayBuffer

        public ByteArrayBuffer​(int capacity)
      • ByteArrayBuffer

        public ByteArrayBuffer​(byte[] bytes,
                               boolean dontCopy)
      • ByteArrayBuffer

        public ByteArrayBuffer​(byte[] bytes,
                               int len,
                               boolean dontCopy)
    • Method Detail

      • expand

        private void expand​(int newlen)
      • append

        public void append​(byte[] b,
                           int off,
                           int len)
      • append

        public void append​(int b)
      • clear

        public void clear()
      • toByteArray

        public byte[] toByteArray()
        Description copied from interface: ByteSequence
        Copies the contents of this byte sequence into a newly allocated byte array and returns that array.
        Specified by:
        toByteArray in interface ByteSequence
        Returns:
        a byte array holding a copy of this byte sequence.
      • byteAt

        public byte byteAt​(int i)
        Description copied from interface: ByteSequence
        Returns the byte value at the specified index.
        Specified by:
        byteAt in interface ByteSequence
        Parameters:
        i - the index of the byte value to be returned.
        Returns:
        the corresponding byte value
      • capacity

        public int capacity()
      • length

        public int length()
        Description copied from interface: ByteSequence
        Returns the length of this byte sequence.
        Specified by:
        length in interface ByteSequence
        Returns:
        the number of bytes in this sequence.
      • buffer

        public byte[] buffer()
      • indexOf

        public int indexOf​(byte b)
      • indexOf

        public int indexOf​(byte b,
                           int beginIndex,
                           int endIndex)
      • setLength

        public void setLength​(int len)
      • remove

        public void remove​(int off,
                           int len)
      • isEmpty

        public boolean isEmpty()
      • isFull

        public boolean isFull()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object