@BetaApi public class ByteArray extends Object implements Iterable<Byte>, Serializable
Modifier and Type | Method and Description |
---|---|
InputStream |
asInputStream()
Returns an
InputStream for this ByteArray content. |
ByteBuffer |
asReadOnlyByteBuffer()
Returns the content of this
ByteArray as a read-only ByteBuffer . |
static ByteArray |
copyFrom(byte[] bytes)
Creates a
ByteArray object given an array of bytes. |
static ByteArray |
copyFrom(ByteBuffer bytes)
Creates a
ByteArray object given a ByteBuffer . |
static ByteArray |
copyFrom(InputStream input)
Creates a
ByteArray object given an InputStream . |
static ByteArray |
copyFrom(String string)
Creates a
ByteArray object given a string. |
void |
copyTo(byte[] target)
Copies the content of this
ByteArray into an array of bytes. |
void |
copyTo(ByteBuffer target)
Copies the content of this
ByteArray into an existing ByteBuffer . |
boolean |
equals(Object obj) |
static ByteArray |
fromBase64(String data)
Creates a
ByteArray from a base64 representation. |
int |
hashCode() |
Iterator<Byte> |
iterator() |
int |
length()
Returns the number of bytes in this
ByteArray . |
String |
toBase64()
Converts this byte array to its base64 representation.
|
byte[] |
toByteArray()
Returns a copy of this
ByteArray as an array of bytes. |
String |
toString() |
String |
toStringUtf8()
Returns a copy of this
ByteArray as an UTF-8 string. |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public final int length()
ByteArray
.public final byte[] toByteArray()
ByteArray
as an array of bytes.public final String toStringUtf8()
ByteArray
as an UTF-8
string.public final String toBase64()
public final ByteBuffer asReadOnlyByteBuffer()
ByteArray
as a read-only ByteBuffer
.public final InputStream asInputStream()
InputStream
for this ByteArray
content.public final void copyTo(ByteBuffer target)
ByteArray
into an existing ByteBuffer
.ReadOnlyBufferException
- if the target is read-onlyBufferOverflowException
- if the target's Buffer.remaining()
space
is not large enough to hold the datapublic final void copyTo(byte[] target)
ByteArray
into an array of bytes.IndexOutOfBoundsException
- if the target is not large enough to hold the datapublic static final ByteArray copyFrom(byte[] bytes)
ByteArray
object given an array of bytes. The bytes are copied.public static final ByteArray copyFrom(String string)
ByteArray
object given a string. The string is encoded in UTF-8
. The
bytes are copied.public static final ByteArray copyFrom(ByteBuffer bytes)
ByteArray
object given a ByteBuffer
. The bytes are copied.public static final ByteArray copyFrom(InputStream input) throws IOException
ByteArray
object given an InputStream
. The stream is read into the
created object.IOException
Copyright © 2019 Google LLC. All rights reserved.