Class ByteArray


  • final class ByteArray
    extends java.lang.Object
    This class implements an array of unsigned bytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] bytes  
      private static int INITIAL_SIZE  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteArray()
      Creates a new ByteArray instance with size 0.
      ByteArray​(byte[] byteArray)
      Creates a new ByteArray instance based on an existing byte[].
      ByteArray​(int size)
      Creates a new ByteArray instance of the specified size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendByte​(int value)
      Append a byte to the end of the array.
      int at​(int index)
      Access an unsigned byte at location index.
      boolean isEmpty()  
      void reserve​(int capacity)
      Increase the capacity of the array to "capacity" if the current capacity is smaller
      void set​(byte[] source, int offset, int count)
      Copy count bytes from array source starting at offset.
      void set​(int index, int value)
      Set the value at "index" to "value"
      int size()  
      • Methods inherited from class java.lang.Object

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

      • bytes

        private byte[] bytes
      • size

        private int size
    • Constructor Detail

      • ByteArray

        public ByteArray()
        Creates a new ByteArray instance with size 0.
      • ByteArray

        public ByteArray​(int size)
        Creates a new ByteArray instance of the specified size.
        Parameters:
        size - size of the array
      • ByteArray

        public ByteArray​(byte[] byteArray)
        Creates a new ByteArray instance based on an existing byte[].
        Parameters:
        byteArray - the byte[]
    • Method Detail

      • at

        public int at​(int index)
        Access an unsigned byte at location index.
        Parameters:
        index - The index in the array to access.
        Returns:
        The unsigned value of the byte as an int.
      • set

        public void set​(int index,
                        int value)
        Set the value at "index" to "value"
        Parameters:
        index - position in the byte-array
        value - new value
      • size

        public int size()
        Returns:
        size of the array
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if size is equal to 0, false otherwise
      • appendByte

        public void appendByte​(int value)
        Append a byte to the end of the array. If the array is too small, it's capacity is doubled.
        Parameters:
        value - byte to append.
      • reserve

        public void reserve​(int capacity)
        Increase the capacity of the array to "capacity" if the current capacity is smaller
        Parameters:
        capacity - the new capacity
      • set

        public void set​(byte[] source,
                        int offset,
                        int count)
        Copy count bytes from array source starting at offset.
        Parameters:
        source - source of the copied bytes
        offset - offset to start at
        count - number of bytes to copy