uk.ac.starlink.util

## Class ByteList

- java.lang.Object
- - uk.ac.starlink.util.PrimitiveList
  - - uk.ac.starlink.util.ByteList

-     public class ByteList
      extends PrimitiveList

  Extendable array of bytes.

  The `decodeString(java.nio.charset.Charset)` and `decodeUtf8()` convenience methods provide an efficient and Unicode-compliant way to build a String from bytes.

  Since:
    12 Oct 2006

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ByteList()` Constructs a new list.
    `ByteList(byte[] array)` Constructs a new list initialised to the contents of a given array.
    `ByteList(int size)` Constructs a new list with a given initial capacity.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(byte value)` Appends a value to the end of this list.
    `boolean` | `addAll(byte[] array)` Appends all the elements of a primitive array to this list.
    `boolean` | `addAll(ByteList other)` Appends all the elements of a second list to this list.
    `java.lang.String` | `decodeString(java.nio.charset.Charset charset)` Returns a string with the current byte content of this byte list, decoded using the supplied encoding.
    `java.lang.String` | `decodeUtf8()` Returns a string with the current byte content of this byte list, decoded using the UTF-8 encoding.
    `byte` | `get(int i)` Returns the element at a given position.
    `byte[]` | `getByteBuffer()` Returns the array currently used to store the contents of this list.
    `void` | `set(int i, byte value)` Sets the element at a given position.
    `byte[]` | `toByteArray()` Returns the contents of this list as an array.

    - ### Methods inherited from class uk.ac.starlink.util.PrimitiveList

      `clear, nextCapacity, size, toArray`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ByteList

          public ByteList()

      Constructs a new list.

    - #### ByteList

          public ByteList(int size)

      Constructs a new list with a given initial capacity.
      Parameters:
        `size` - initial capacity

    - #### ByteList

          public ByteList(byte[] array)

      Constructs a new list initialised to the contents of a given array.
      Parameters:
        `array` - array whose contents form initial contents of list

  - ### Method Detail

    - #### get

          public byte get(int i)

      Returns the element at a given position.
      Parameters:
        `i` - index
      Returns:
        element at `i`

    - #### set

          public void set(int i,
                          byte value)

      Sets the element at a given position.
      Parameters:
        `i` - index
        `value` - new value for element `i`

    - #### add

          public void add(byte value)

      Appends a value to the end of this list.
      Parameters:
        `value` - value to append

    - #### addAll

          public boolean addAll(ByteList other)

      Appends all the elements of a second list to this list.
      Parameters:
        `other` - other list
      Returns:
        true iff this collection changed as a result of the call

    - #### addAll

          public boolean addAll(byte[] array)

      Appends all the elements of a primitive array to this list.
      Parameters:
        `array` - array to append
      Returns:
        true iff this collection changed as a result of the call

    - #### toByteArray

          public byte[] toByteArray()

      Returns the contents of this list as an array.
      Returns:
        copy of list contents

    - #### getByteBuffer

          public byte[] getByteBuffer()

      Returns the array currently used to store the contents of this list. Its length will be greater than or equal to the length of this list. The identity of the returned array may change as this list is mutated.
      Returns:
        storage array

    - #### decodeString

          public java.lang.String decodeString(java.nio.charset.Charset charset)

      Returns a string with the current byte content of this byte list, decoded using the supplied encoding.
      Parameters:
        `charset` - character set
      Returns:
        new string

    - #### decodeUtf8

          public java.lang.String decodeUtf8()

      Returns a string with the current byte content of this byte list, decoded using the UTF-8 encoding.
      Returns:
        new string