Package com.google.cloud
Class ByteArray
- java.lang.Object
-
- com.google.cloud.ByteArray
-
- All Implemented Interfaces:
Serializable
,Iterable<Byte>
@BetaApi public class ByteArray extends Object implements Iterable<Byte>, Serializable
An immutable byte array holder.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStream
asInputStream()
Returns anInputStream
for thisByteArray
content.ByteBuffer
asReadOnlyByteBuffer()
Returns the content of thisByteArray
as a read-onlyByteBuffer
.static ByteArray
copyFrom(byte[] bytes)
Creates aByteArray
object given an array of bytes.static ByteArray
copyFrom(InputStream input)
Creates aByteArray
object given anInputStream
.static ByteArray
copyFrom(String string)
Creates aByteArray
object given a string.static ByteArray
copyFrom(ByteBuffer bytes)
Creates aByteArray
object given aByteBuffer
.void
copyTo(byte[] target)
Copies the content of thisByteArray
into an array of bytes.void
copyTo(ByteBuffer target)
Copies the content of thisByteArray
into an existingByteBuffer
.boolean
equals(Object obj)
static ByteArray
fromBase64(String data)
Creates aByteArray
from a base64 representation.int
hashCode()
Iterator<Byte>
iterator()
int
length()
Returns the number of bytes in thisByteArray
.String
toBase64()
Converts this byte array to its base64 representation.byte[]
toByteArray()
Returns a copy of thisByteArray
as an array of bytes.String
toString()
String
toStringUtf8()
Returns a copy of thisByteArray
as anUTF-8
string.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
length
public final int length()
Returns the number of bytes in thisByteArray
.
-
toByteArray
public final byte[] toByteArray()
Returns a copy of thisByteArray
as an array of bytes.
-
toStringUtf8
public final String toStringUtf8()
Returns a copy of thisByteArray
as anUTF-8
string.
-
toBase64
public final String toBase64()
Converts this byte array to its base64 representation.
-
asReadOnlyByteBuffer
public final ByteBuffer asReadOnlyByteBuffer()
Returns the content of thisByteArray
as a read-onlyByteBuffer
.
-
asInputStream
public final InputStream asInputStream()
Returns anInputStream
for thisByteArray
content.
-
copyTo
public final void copyTo(ByteBuffer target)
Copies the content of thisByteArray
into an existingByteBuffer
.- Throws:
ReadOnlyBufferException
- if the target is read-onlyBufferOverflowException
- if the target'sBuffer.remaining()
space is not large enough to hold the data
-
copyTo
public final void copyTo(byte[] target)
Copies the content of thisByteArray
into an array of bytes.- Throws:
IndexOutOfBoundsException
- if the target is not large enough to hold the data
-
copyFrom
public static final ByteArray copyFrom(byte[] bytes)
Creates aByteArray
object given an array of bytes. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(String string)
Creates aByteArray
object given a string. The string is encoded inUTF-8
. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(ByteBuffer bytes)
Creates aByteArray
object given aByteBuffer
. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(InputStream input) throws IOException
Creates aByteArray
object given anInputStream
. The stream is read into the created object.- Throws:
IOException
-
-