[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-15 UTC."],[],[],null,["# Class ByteArray (2.59.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.59.0 (latest)](/java/docs/reference/google-cloud-core/latest/com.google.cloud.ByteArray)\n- [2.58.2](/java/docs/reference/google-cloud-core/2.58.2/com.google.cloud.ByteArray)\n- [2.57.0](/java/docs/reference/google-cloud-core/2.57.0/com.google.cloud.ByteArray)\n- [2.56.0](/java/docs/reference/google-cloud-core/2.56.0/com.google.cloud.ByteArray)\n- [2.55.0](/java/docs/reference/google-cloud-core/2.55.0/com.google.cloud.ByteArray)\n- [2.53.1](/java/docs/reference/google-cloud-core/2.53.1/com.google.cloud.ByteArray)\n- [2.52.0](/java/docs/reference/google-cloud-core/2.52.0/com.google.cloud.ByteArray)\n- [2.51.0](/java/docs/reference/google-cloud-core/2.51.0/com.google.cloud.ByteArray)\n- [2.50.0](/java/docs/reference/google-cloud-core/2.50.0/com.google.cloud.ByteArray)\n- [2.49.1](/java/docs/reference/google-cloud-core/2.49.1/com.google.cloud.ByteArray)\n- [2.48.0](/java/docs/reference/google-cloud-core/2.48.0/com.google.cloud.ByteArray)\n- [2.47.0](/java/docs/reference/google-cloud-core/2.47.0/com.google.cloud.ByteArray)\n- [2.45.0](/java/docs/reference/google-cloud-core/2.45.0/com.google.cloud.ByteArray)\n- [2.44.1](/java/docs/reference/google-cloud-core/2.44.1/com.google.cloud.ByteArray)\n- [2.43.0](/java/docs/reference/google-cloud-core/2.43.0/com.google.cloud.ByteArray)\n- [2.42.0](/java/docs/reference/google-cloud-core/2.42.0/com.google.cloud.ByteArray)\n- [2.41.0](/java/docs/reference/google-cloud-core/2.41.0/com.google.cloud.ByteArray)\n- [2.40.0](/java/docs/reference/google-cloud-core/2.40.0/com.google.cloud.ByteArray)\n- [2.39.0](/java/docs/reference/google-cloud-core/2.39.0/com.google.cloud.ByteArray)\n- [2.38.1](/java/docs/reference/google-cloud-core/2.38.1/com.google.cloud.ByteArray)\n- [2.37.0](/java/docs/reference/google-cloud-core/2.37.0/com.google.cloud.ByteArray)\n- [2.36.1](/java/docs/reference/google-cloud-core/2.36.1/com.google.cloud.ByteArray)\n- [2.35.0](/java/docs/reference/google-cloud-core/2.35.0/com.google.cloud.ByteArray)\n- [2.33.0](/java/docs/reference/google-cloud-core/2.33.0/com.google.cloud.ByteArray)\n- [2.32.0](/java/docs/reference/google-cloud-core/2.32.0/com.google.cloud.ByteArray)\n- [2.31.0](/java/docs/reference/google-cloud-core/2.31.0/com.google.cloud.ByteArray)\n- [2.29.0](/java/docs/reference/google-cloud-core/2.29.0/com.google.cloud.ByteArray)\n- [2.28.0](/java/docs/reference/google-cloud-core/2.28.0/com.google.cloud.ByteArray)\n- [2.27.0](/java/docs/reference/google-cloud-core/2.27.0/com.google.cloud.ByteArray)\n- [2.26.0](/java/docs/reference/google-cloud-core/2.26.0/com.google.cloud.ByteArray)\n- [2.25.0](/java/docs/reference/google-cloud-core/2.25.0/com.google.cloud.ByteArray)\n- [2.24.1](/java/docs/reference/google-cloud-core/2.24.1/com.google.cloud.ByteArray)\n- [2.23.0](/java/docs/reference/google-cloud-core/2.23.0/com.google.cloud.ByteArray)\n- [2.22.1](/java/docs/reference/google-cloud-core/2.22.1/com.google.cloud.ByteArray)\n- [2.21.1](/java/docs/reference/google-cloud-core/2.21.1/com.google.cloud.ByteArray)\n- [2.20.1](/java/docs/reference/google-cloud-core/2.20.1/com.google.cloud.ByteArray)\n- [2.13.0](/java/docs/reference/google-cloud-core/2.13.0/com.google.cloud.ByteArray)\n- [2.12.0](/java/docs/reference/google-cloud-core/2.12.0/com.google.cloud.ByteArray)\n- [2.11.0](/java/docs/reference/google-cloud-core/2.11.0/com.google.cloud.ByteArray)\n- [2.9.4](/java/docs/reference/google-cloud-core/2.9.4/com.google.cloud.ByteArray)\n- [2.8.27](/java/docs/reference/google-cloud-core/2.8.27/com.google.cloud.ByteArray)\n- [2.7.1](/java/docs/reference/google-cloud-core/2.7.1/com.google.cloud.ByteArray)\n- [2.6.1](/java/docs/reference/google-cloud-core/2.6.1/com.google.cloud.ByteArray)\n- [2.5.11](/java/docs/reference/google-cloud-core/2.5.11/com.google.cloud.ByteArray)\n- [2.4.0](/java/docs/reference/google-cloud-core/2.4.0/com.google.cloud.ByteArray)\n- [2.3.5](/java/docs/reference/google-cloud-core/2.3.5/com.google.cloud.ByteArray) \n| **Beta**\n|\n|\n| This library is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1)\n| of the Terms of Service. Pre-GA libraries might have limited support,\n| and changes to pre-GA libraries might not be compatible with other pre-GA versions.\n| For more information, see the\n[launch stage descriptions](/products#product-launch-stages). \n\n public class ByteArray implements Iterable\u003cByte\u003e, Serializable\n\nAn immutable byte array holder. \n\nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e ByteArray \n\nImplements\n----------\n\n[Iterable\\\u003cByte\\\u003e](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable\u003cjava/lang/Byte\u003e.html), [Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### copyFrom(byte\\[\\] bytes)\n\n public static final ByteArray copyFrom(byte[] bytes)\n\nCreates a `ByteArray` object given an array of bytes. The bytes are copied.\n\n### copyFrom(InputStream input)\n\n public static final ByteArray copyFrom(InputStream input)\n\nCreates a `ByteArray` object given an [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html). The stream is read into the\ncreated object.\n\n### copyFrom(String string)\n\n public static final ByteArray copyFrom(String string)\n\nCreates a `ByteArray` object given a string. The string is encoded in `UTF-8`. The\nbytes are copied.\n\n### copyFrom(ByteBuffer bytes)\n\n public static final ByteArray copyFrom(ByteBuffer bytes)\n\nCreates a `ByteArray` object given a [ByteBuffer](https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html). The bytes are copied.\n\n### fromBase64(String data)\n\n public static ByteArray fromBase64(String data)\n\nCreates a `ByteArray` from a base64 representation.\n\nMethods\n-------\n\n### asInputStream()\n\n public final InputStream asInputStream()\n\nReturns an [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html) for this `ByteArray` content.\n\n### asReadOnlyByteBuffer()\n\n public final ByteBuffer asReadOnlyByteBuffer()\n\nReturns the content of this `ByteArray` as a read-only [ByteBuffer](https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html).\n\n### copyTo(byte\\[\\] target)\n\n public final void copyTo(byte[] target)\n\nCopies the content of this `ByteArray` into an array of bytes.\n\n### copyTo(ByteBuffer target)\n\n public final void copyTo(ByteBuffer target)\n\nCopies the content of this `ByteArray` into an existing `ByteBuffer`.\n\n### equals(Object obj)\n\n public final boolean equals(Object obj)\n\n**Overrides** \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)\n\n### hashCode()\n\n public final int hashCode()\n\n**Overrides** \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)\n\n### iterator()\n\n public final Iterator\u003cByte\u003e iterator()\n\n### length()\n\n public final int length()\n\nReturns the number of bytes in this `ByteArray`.\n\n### toBase64()\n\n public final String toBase64()\n\nConverts this byte array to its base64 representation.\n\n### toByteArray()\n\n public final byte[] toByteArray()\n\nReturns a copy of this `ByteArray` as an array of bytes.\n\n### toString()\n\n public String toString()\n\n**Overrides** \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)\n\n### toStringUtf8()\n\n public final String toStringUtf8()\n\nReturns a copy of this `ByteArray` as an `UTF-8` string."]]