2.73.0 (latest) 2.72.0 2.71.0 2.70.0 2.69.0 2.66.0 2.65.0 2.64.1 2.63.1 2.62.2 2.61.0 2.60.3 2.59.0 2.58.2 2.57.0 2.56.0 2.55.0 2.53.1 2.52.0 2.51.0 2.50.0 2.49.1 2.48.0 2.47.0 2.45.0 2.44.1 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.1 2.37.0 2.36.1 2.35.0 2.33.0 2.32.0 2.31.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.0 2.24.1 2.23.0 2.22.1 2.21.1 2.20.1 2.13.0 2.12.0 2.11.0 2.9.4 2.8.27 2.7.1 2.6.1 2.5.11 2.4.0 2.3.5

> [!WARNING]
> **Beta**
>
>
> This library is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1)
> of the Terms of Service. Pre-GA libraries might have limited support,
> and changes to pre-GA libraries might not be compatible with other pre-GA versions.
> For more information, see the
> [launch stage descriptions](https://docs.cloud.google.com/products#product-launch-stages).

    public class ByteArray implements Iterable<Byte>, Serializable

An immutable byte array holder.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> ByteArray

## Implements

[Iterable\<Byte\>](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable<java/lang/Byte>.html), [Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### copyFrom(byte\[\] bytes)

    public static final ByteArray copyFrom(byte[] bytes)

Creates a `ByteArray` object given an array of bytes. The bytes are copied.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `byte[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray` |   |

### copyFrom(InputStream input)

    public static final ByteArray copyFrom(InputStream input)

Creates a `ByteArray` object given an [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html). The stream is read into the
created object.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### copyFrom(String string)

    public static final ByteArray copyFrom(String string)

Creates a `ByteArray` object given a string. The string is encoded in `UTF-8`. The
bytes are copied.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `string` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray` |   |

### copyFrom(ByteBuffer bytes)

    public static final ByteArray copyFrom(ByteBuffer bytes)

Creates a `ByteArray` object given a [ByteBuffer](https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html). The bytes are copied.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray` |   |

### fromBase64(String data)

    public static ByteArray fromBase64(String data)

Creates a `ByteArray` from a base64 representation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `data` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray` |   |

## Methods

### asInputStream()

    public final InputStream asInputStream()

Returns an [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html) for this `ByteArray` content.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` |   |

### asReadOnlyByteBuffer()

    public final ByteBuffer asReadOnlyByteBuffer()

Returns the content of this `ByteArray` as a read-only [ByteBuffer](https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |   |

### copyTo(byte\[\] target)

    public final void copyTo(byte[] target)

Copies the content of this `ByteArray` into an array of bytes.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `target` | `byte[]` |

### copyTo(ByteBuffer target)

    public final void copyTo(ByteBuffer target)

Copies the content of this `ByteArray` into an existing `ByteBuffer`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `target` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

### equals(Object obj)

    public final boolean equals(Object obj)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### hashCode()

    public final int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### iterator()

    public final Iterator<Byte> iterator()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html<https://docs.oracle.com/javase/8/docs/api/java/lang/Byte.html>` |   |

### length()

    public final int length()

Returns the number of bytes in this `ByteArray`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### toBase64()

    public final String toBase64()

Converts this byte array to its base64 representation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### toByteArray()

    public final byte[] toByteArray()

Returns a copy of this `ByteArray` as an array of bytes.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `byte[]` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)

### toStringUtf8()

    public final String toStringUtf8()

Returns a copy of this `ByteArray` as an `UTF-8` string.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |