public class ByteArray extends Object implements Iterable<Byte>, Serializable
Modifier | Constructor and Description |
---|---|
protected |
ByteArray(ByteArray byteArray) |
protected |
ByteArray(com.google.protobuf.ByteString byteString) |
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 . |
protected com.google.protobuf.ByteString |
byteString() |
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) |
int |
hashCode() |
Iterator<Byte> |
iterator() |
int |
length()
Returns the number of bytes in this
ByteArray . |
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. |
protected ByteArray(com.google.protobuf.ByteString byteString)
protected ByteArray(ByteArray byteArray)
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 ByteBuffer asReadOnlyByteBuffer()
ByteArray
as a read-only ByteBuffer
.public final InputStream asInputStream()
InputStream
for this ByteArray
content.protected com.google.protobuf.ByteString byteString()
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 © 2016 Google. All rights reserved.