Package ints

Class UnsignedByteArray

java.lang.Object
ints.UnsignedByteArray
All Implemented Interfaces:
IntArray

public final class UnsignedByteArray extends Object implements IntArray

Class UnsignedByteIndexArray represents an immutable array of integer values between 0 and 255 inclusive that is stored as a byte[] array. A 0xff mask is used to convert int values to byte values.

Instances of UnsignedByteArray are immutable.

  • Constructor Details

    • UnsignedByteArray

      public UnsignedByteArray(byte[] ba)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      ba - an array of bytes which are interpreted as unsigned byte values between 0 and 255
      Throws:
      NullPointerException - if ba == null
    • UnsignedByteArray

      public UnsignedByteArray(byte[] ba, int from, int to)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      ba - an array of bytes which are interpreted as unsigned byte values between 0 and 255
      from - the first element to be included (inclusive)
      to - the last element to be included (exclusive)
      Throws:
      IndexOutOfBoundsException - if (from < 0 || to > ia.length)
      NegativeArraySizeException - if to > from
      NullPointerException - if ba == null
    • UnsignedByteArray

      public UnsignedByteArray(int[] ia)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      ia - an array of integer values between 0 and 255 inclusive
      Throws:
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > 255) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • UnsignedByteArray

      public UnsignedByteArray(IntList il)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      il - an list of integer values between 0 and 255 inclusive
      Throws:
      IllegalArgumentException - if (il.get(j) < 0 || il.get(j) > 255) for any index j satisfying (j >= 0 && j < il.size())
      NullPointerException - if il == null
    • UnsignedByteArray

      public UnsignedByteArray(int[] ia, int valueSize)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      ia - an array of nonnegative integer values
      valueSize - the exclusive end of the range of non-negative array values
      Throws:
      IllegalArgumentException - if valueSize < 1 || valueSize > 256
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • UnsignedByteArray

      public UnsignedByteArray(IntList il, int valueSize)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      il - an list of nonnegative integers between 0 and 255 inclusive
      valueSize - the exclusive end of the range of non-negative array values
      Throws:
      IllegalArgumentException - if (valueSize < 1) || (valueSize > 256)
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if il == null
    • UnsignedByteArray

      public UnsignedByteArray(int[] ia, int from, int to)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      ia - an array of integer values between 0 and 255 inclusive
      from - the first element to be included (inclusive)
      to - the last element to be included (exclusive)
      Throws:
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > 255) for any index j satisfying (j >= from && j < to)
      IndexOutOfBoundsException - if (from < 0 || to > ia.length)
      NegativeArraySizeException - if to > from
      NullPointerException - if ia == null
    • UnsignedByteArray

      public UnsignedByteArray(IntList il, int from, int to)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      il - an list of integer values between 0 and 255 inclusive
      from - the first element to be included (inclusive)
      to - the last element to be included (exclusive)
      Throws:
      IllegalArgumentException - if (il.get(j) < 0 || il.get(j) > 255) for any index j satisfying (j >= from && j < to)
      IndexOutOfBoundsException - if from < 0 || to > il.length
      NegativeArraySizeException - if to > from
      NullPointerException - if il == null
    • UnsignedByteArray

      public UnsignedByteArray(ByteArrayOutputStream baos)
      Constructs a new UnsignedByteArray instance from the specified data.
      Parameters:
      baos - a byte array output stream whose elements are interpreted as unsigned byte values between 0 and 255
      Throws:
      NullPointerException - if baos == null
  • Method Details

    • size

      public int size()
      Description copied from interface: IntArray
      Returns the number of elements in this IntArray.
      Specified by:
      size in interface IntArray
      Returns:
      the number of elements in this IntArray
    • get

      public int get(int index)
      Description copied from interface: IntArray
      Returns the specified array element.
      Specified by:
      get in interface IntArray
      Parameters:
      index - an array index
      Returns:
      the specified array element
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • write

      public void write(OutputStream os) throws IOException
      Write this byte array to the specified output stream.
      Parameters:
      os - an output stream
      Throws:
      IOException - if an I/O error occurs