Package: primitives-and-primitive-arrays

## Class byte[]

- - ### Methods Summary

    Methods
    Return type | Name and parameters
    --- | ---
    `boolean` | `asBoolean()` Coerces a byte array to a boolean value.
    `BigDecimal` | `average()` Calculates the average of the bytes in the array.
    `boolean` | `contains(Object value)` Checks whether the array contains the given value.
    `Number` | `count(Object value)` Counts the number of occurrences of the given value inside this array.
    `String` | `digest(String algorithm)` digest the byte array
    `void` | `eachByte(Closure closure)` Traverse through each byte of this byte array.
    `Writable` | `encodeBase64()` Produce a Writable object which writes the Base64 encoding of the byte array.
    `Writable` | `encodeBase64(boolean chunked)` Produce a Writable object which writes the Base64 encoding of the byte array.
    `Writable` | `encodeBase64Url()` Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.
    `Writable` | `encodeBase64Url(boolean pad)` Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.
    `Writable` | `encodeHex()` Produces a Writable that writes the hex encoding of the byte[].
    `Collection` | `flatten()` Flatten an array.
    `List` | `getAt(IntRange range)` Support the subscript operator with an IntRange for a byte array
    `List` | `getAt(ObjectRange range)` Support the subscript operator with an ObjectRange for a byte array
    `List` | `getAt(Range range)` Support the subscript operator with a range for a byte array
    `List` | `getAt(Collection indices)` Support the subscript operator with a collection for a byte array
    `IntRange` | `getIndices()` Returns indices of the byte array.
    `String` | `join(String separator)` Concatenates the string representation of each item in this array, with the given String as a separator between each item.
    `String` | `md5()` Calculate md5 of the byte array
    `String` | `sha256()` Calculate SHA-256 of the byte array
    `int` | `size()` Allows arrays to behave similar to collections.
    `Stream` | `stream()` Returns a sequential Stream with the specified array as its source.
    `byte` | `sum()` Sums the items in an array.
    `byte` | `sum(byte initialValue)` Sums the items in an array, adding the result to some initial value.
    `byte[]` | `swap(int i, int j)` Swaps two elements at the specified positions.
    `List` | `toList()` Converts this array to a List of the same size, with each element added to the list.
    `Set` | `toSet()` Converts this array to a Set, with each unique element added to the set.
    `String` | `toString()` Returns the string representation of the given array.

- - ### Methods Detail

    - #### public boolean asBoolean()

      Coerces a byte array to a boolean value. A byte array is false if the array is of length 0, and true otherwise.

      Returns:
        the array's boolean value
      Since:
        1.7.4

    - #### public BigDecimal average()

      Calculates the average of the bytes in the array.

          assert 5.0G == ([2,4,6,8] as byte[]).average()

      Returns:
        The average of the items
      Since:
        3.0.0

    - #### public boolean contains(Object value)

      Checks whether the array contains the given value.

      Parameters:
        `value` - the value being searched for
      Returns:
        true if the array contains the value
      Since:
        1.8.6

    - #### public Number count(Object value)

      Counts the number of occurrences of the given value inside this array. Comparison is done using Groovy's == operator (using `compareTo(value) == 0` or `equals(value)` ).

      Parameters:
        `value` - the value being searched for
      Returns:
        the number of occurrences
      Since:
        1.6.4

    - #### public String digest(String algorithm)

      digest the byte array

      Parameters:
      Returns:
        digested value
      Since:
        2.5.0
      See Also:
        MessageDigest#getInstance(java.lang.String)

    - #### public void eachByte(Closure closure)

      Traverse through each byte of this byte array. Alias for each.

      Parameters:
        `closure` - a closure
      Since:
        1.5.5
      See Also:
        Object#each(groovy.lang.Closure)

    - #### public Writable encodeBase64()

      Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see `RFC 4648`.

      Returns:
        object which will write the Base64 encoding of the byte array
      Since:
        1.0

    - #### public Writable encodeBase64(boolean chunked)

      Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see `RFC 4648`.

      Parameters:
        `chunked` - whether or not the Base64 encoded data should be MIME chunked
      Returns:
        object which will write the Base64 encoding of the byte array
      Since:
        1.5.7

    - #### public Writable encodeBase64Url()

      Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see `RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet`.

      The method omits padding and is equivalent to calling EncodingGroovyMethods#encodeBase64Url(byte[], boolean) with a value of `false`.

      Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
      Since:
        2.5.0
      See Also:
        EncodingGroovyMethods#encodeBase64Url(byte[], boolean)

    - #### public Writable encodeBase64Url(boolean pad)

      Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see `RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet`.

      Parameters:
        `pad` - whether or not the encoded data should be padded
      Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
      Since:
        2.5.0

    - #### public Writable encodeHex()

      Produces a Writable that writes the hex encoding of the byte[]. Calling toString() on this Writable returns the hex encoding as a String. The hex encoding includes two characters for each byte and all letters are lower case.

      Returns:
        object which will write the hex encoding of the byte array
      See Also:
        Integer#toHexString(int)

    - #### public Collection flatten()

      Flatten an array. This array and any nested arrays or collections have their contents (recursively) added to the new collection.

      Returns:
        a flattened Collection
      Since:
        1.6.0

    - #### public List getAt(IntRange range)

      Support the subscript operator with an IntRange for a byte array

      Parameters:
        `range` - an IntRange indicating the indices for the items to retrieve
      Returns:
        list of the retrieved bytes
      Since:
        1.0

    - #### public List getAt(ObjectRange range)

      Support the subscript operator with an ObjectRange for a byte array

      Parameters:
        `range` - an ObjectRange indicating the indices for the items to retrieve
      Returns:
        list of the retrieved bytes
      Since:
        1.0

    - #### public List getAt(Range range)

      Support the subscript operator with a range for a byte array

      Parameters:
        `range` - a range indicating the indices for the items to retrieve
      Returns:
        list of the retrieved bytes
      Since:
        1.0

    - #### public List getAt(Collection indices)

      Support the subscript operator with a collection for a byte array

      Parameters:
        `indices` - a collection of indices for the items to retrieve
      Returns:
        list of the bytes at the given indices
      Since:
        1.0

    - #### public IntRange getIndices()

      Returns indices of the byte array.

      Since:
        3.0.8
      See Also:
        Object[]#getIndices()

    - #### public String join(String separator)

      Concatenates the string representation of each item in this array, with the given String as a separator between each item.

      Parameters:
        `separator` - a String separator
      Returns:
        the joined String
      Since:
        2.4.1

    - #### public String md5()

      Calculate md5 of the byte array

      Returns:
        md5 value
      Since:
        2.5.0

    - #### public String sha256()

      Calculate SHA-256 of the byte array

      Returns:
        SHA-256 value
      Since:
        2.5.3

    - #### public int size()

      Allows arrays to behave similar to collections.

      Returns:
        the length of the array
      Since:
        1.0
      See Also:
        Array#getLength(java.lang.Object)

    - #### public Stream stream()

      Returns a sequential Stream with the specified array as its source.

      Returns:
        a `Stream` for the array
      Since:
        2.5.0

    - #### public byte sum()

      Sums the items in an array.

          assert (1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum()

      Returns:
        The sum of all the items
      Since:
        2.4.2

    - #### public byte sum(byte initialValue)

      Sums the items in an array, adding the result to some initial value.

          assert (5+1+2+3+4 as byte) == ([1,2,3,4] as byte[]).sum(5 as byte)

      Parameters:
        `initialValue` - the items in the array will be summed to this initial value
      Returns:
        The sum of all the items.
      Since:
        2.4.2

    - #### public byte[] swap(int i, int j)

      Swaps two elements at the specified positions.

      Example:

          assert ([1, 3, 2, 4] as byte[]) == ([1, 2, 3, 4] as byte[]).swap(1, 2)

      Parameters:
        `i` - a position
        `j` - a position
      Returns:
        self
      Since:
        2.4.0

    - #### public List toList()

      Converts this array to a List of the same size, with each element added to the list.

      Returns:
        a list containing the contents of this array.
      Since:
        1.0

    - #### public Set toSet()

      Converts this array to a Set, with each unique element added to the set.

      Returns:
        a set containing the unique contents of this array.
      Since:
        1.8.0

    - #### public String toString()

      Returns the string representation of the given array.

      Returns:
        the string representation
      Since:
        1.6.0