Class ByteArray (2.4.0)

publicclassByteArrayimplementsIterable<Byte>,Serializable

An immutable byte array holder.

Static Methods

copyFrom(byte[] bytes)

publicstaticfinalByteArraycopyFrom(byte[]bytes)

Creates aByteArray object given an array of bytes. The bytes are copied.

Parameter
NameDescription
bytesbyte[]
Returns
TypeDescription
ByteArray

copyFrom(InputStream input)

publicstaticfinalByteArraycopyFrom(InputStreaminput)

Creates aByteArray object given anInputStream. The stream is read into the created object.

Parameter
NameDescription
inputInputStream
Returns
TypeDescription
ByteArray
Exceptions
TypeDescription
IOException

copyFrom(String string)

publicstaticfinalByteArraycopyFrom(Stringstring)

Creates aByteArray object given a string. The string is encoded inUTF-8. The bytes are copied.

Parameter
NameDescription
stringString
Returns
TypeDescription
ByteArray

copyFrom(ByteBuffer bytes)

publicstaticfinalByteArraycopyFrom(ByteBufferbytes)

Creates aByteArray object given aByteBuffer. The bytes are copied.

Parameter
NameDescription
bytesByteBuffer
Returns
TypeDescription
ByteArray

fromBase64(String data)

publicstaticByteArrayfromBase64(Stringdata)

Creates aByteArray from a base64 representation.

Parameter
NameDescription
dataString
Returns
TypeDescription
ByteArray

Methods

asInputStream()

publicfinalInputStreamasInputStream()

Returns anInputStream for thisByteArray content.

Returns
TypeDescription
InputStream

asReadOnlyByteBuffer()

publicfinalByteBufferasReadOnlyByteBuffer()

Returns the content of thisByteArray as a read-onlyByteBuffer.

Returns
TypeDescription
ByteBuffer

copyTo(byte[] target)

publicfinalvoidcopyTo(byte[]target)

Copies the content of thisByteArray into an array of bytes.

Parameter
NameDescription
targetbyte[]

copyTo(ByteBuffer target)

publicfinalvoidcopyTo(ByteBuffertarget)

Copies the content of thisByteArray into an existingByteBuffer.

Parameter
NameDescription
targetByteBuffer

equals(Object obj)

publicfinalbooleanequals(Objectobj)
Parameter
NameDescription
objObject
Returns
TypeDescription
boolean
Overrides

hashCode()

publicfinalinthashCode()
Returns
TypeDescription
int
Overrides

iterator()

publicfinalIterator<Byte>iterator()
Returns
TypeDescription
Iterator<Byte>

length()

publicfinalintlength()

Returns the number of bytes in thisByteArray.

Returns
TypeDescription
int

toBase64()

publicfinalStringtoBase64()

Converts this byte array to its base64 representation.

Returns
TypeDescription
String

toByteArray()

publicfinalbyte[]toByteArray()

Returns a copy of thisByteArray as an array of bytes.

Returns
TypeDescription
byte[]

toString()

publicStringtoString()
Returns
TypeDescription
String
Overrides

toStringUtf8()

publicfinalStringtoStringUtf8()

Returns a copy of thisByteArray as anUTF-8 string.

Returns
TypeDescription
String

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-31 UTC.