Class ByteArray


  • class ByteArray
    extends java.lang.Object
    Expandable byte array with byte-basis and bit-basis operations.
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteArray​(byte[] data)
      Constructor with initial data.
      ByteArray​(int capacity)
      Constructor with initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      void clearBit​(int bitIndex)  
      private void expandBuffer​(int newBufferSize)
      Expand the size of the internal buffer.
      byte get​(int index)
      Get a byte at the index.
      boolean getBit​(int bitIndex)  
      int getBits​(int bitIndex, int nBits)  
      int getHuffmanBits​(int bitIndex, int nBits)  
      int length()
      The length of the data.
      void put​(byte[] source)
      Add data at the current position.
      void put​(byte[] source, int index, int length)
      Add data at the current position.
      void put​(int data)
      Add a byte at the current position.
      void put​(ByteArray source, int index, int length)
      Add data at the current position.
      boolean readBit​(int[] bitIndex)  
      int readBits​(int[] bitIndex, int nBits)  
      void setBit​(int bitIndex, boolean bit)  
      void shrink​(int size)  
      byte[] toBytes()
      Convert to a byte array (byte[]).
      byte[] toBytes​(int beginIndex)  
      byte[] toBytes​(int beginIndex, int endIndex)  
      • Methods inherited from class java.lang.Object

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

      • ADDITIONAL_BUFFER_SIZE

        private static final int ADDITIONAL_BUFFER_SIZE
        See Also:
        Constant Field Values
      • mBuffer

        private java.nio.ByteBuffer mBuffer
      • mLength

        private int mLength
    • Constructor Detail

      • ByteArray

        public ByteArray​(int capacity)
        Constructor with initial capacity.
        Parameters:
        capacity - Initial capacity for the internal buffer.
      • ByteArray

        public ByteArray​(byte[] data)
        Constructor with initial data. The length of the data is used as the initial capacity of the internal buffer.
        Parameters:
        data - Initial data.
    • Method Detail

      • length

        public int length()
        The length of the data.
      • get

        public byte get​(int index)
                 throws java.lang.IndexOutOfBoundsException
        Get a byte at the index.
        Throws:
        java.lang.IndexOutOfBoundsException
      • expandBuffer

        private void expandBuffer​(int newBufferSize)
        Expand the size of the internal buffer.
      • put

        public void put​(int data)
        Add a byte at the current position.
      • put

        public void put​(byte[] source)
        Add data at the current position.
        Parameters:
        source - Source data.
      • put

        public void put​(byte[] source,
                        int index,
                        int length)
        Add data at the current position.
        Parameters:
        source - Source data.
        index - The index in the source data. Data from the index is copied.
        length - The length of data to copy.
      • put

        public void put​(ByteArray source,
                        int index,
                        int length)
        Add data at the current position.
        Parameters:
        source - Source data.
        index - The index in the source data. Data from the index is copied.
        length - The length of data to copy.
      • toBytes

        public byte[] toBytes()
        Convert to a byte array (byte[]).
      • toBytes

        public byte[] toBytes​(int beginIndex)
      • toBytes

        public byte[] toBytes​(int beginIndex,
                              int endIndex)
      • clear

        public void clear()
      • shrink

        public void shrink​(int size)
      • getBit

        public boolean getBit​(int bitIndex)
      • getBits

        public int getBits​(int bitIndex,
                           int nBits)
      • getHuffmanBits

        public int getHuffmanBits​(int bitIndex,
                                  int nBits)
      • readBit

        public boolean readBit​(int[] bitIndex)
      • readBits

        public int readBits​(int[] bitIndex,
                            int nBits)
      • setBit

        public void setBit​(int bitIndex,
                           boolean bit)
      • clearBit

        public void clearBit​(int bitIndex)