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 InputStreamasInputStream()Returns anInputStreamfor thisByteArraycontent.ByteBufferasReadOnlyByteBuffer()Returns the content of thisByteArrayas a read-onlyByteBuffer.static ByteArraycopyFrom(byte[] bytes)Creates aByteArrayobject given an array of bytes.static ByteArraycopyFrom(InputStream input)Creates aByteArrayobject given anInputStream.static ByteArraycopyFrom(String string)Creates aByteArrayobject given a string.static ByteArraycopyFrom(ByteBuffer bytes)Creates aByteArrayobject given aByteBuffer.voidcopyTo(byte[] target)Copies the content of thisByteArrayinto an array of bytes.voidcopyTo(ByteBuffer target)Copies the content of thisByteArrayinto an existingByteBuffer.booleanequals(Object obj)static ByteArrayfromBase64(String data)Creates aByteArrayfrom a base64 representation.inthashCode()Iterator<Byte>iterator()intlength()Returns the number of bytes in thisByteArray.StringtoBase64()Converts this byte array to its base64 representation.byte[]toByteArray()Returns a copy of thisByteArrayas an array of bytes.StringtoString()StringtoStringUtf8()Returns a copy of thisByteArrayas anUTF-8string.-
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 thisByteArrayas an array of bytes.
-
toStringUtf8
public final String toStringUtf8()
Returns a copy of thisByteArrayas anUTF-8string.
-
toBase64
public final String toBase64()
Converts this byte array to its base64 representation.
-
asReadOnlyByteBuffer
public final ByteBuffer asReadOnlyByteBuffer()
Returns the content of thisByteArrayas a read-onlyByteBuffer.
-
asInputStream
public final InputStream asInputStream()
Returns anInputStreamfor thisByteArraycontent.
-
copyTo
public final void copyTo(ByteBuffer target)
Copies the content of thisByteArrayinto 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 thisByteArrayinto 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 aByteArrayobject given an array of bytes. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(String string)
Creates aByteArrayobject given a string. The string is encoded inUTF-8. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(ByteBuffer bytes)
Creates aByteArrayobject given aByteBuffer. The bytes are copied.
-
copyFrom
public static final ByteArray copyFrom(InputStream input) throws IOException
Creates aByteArrayobject given anInputStream. The stream is read into the created object.- Throws:
IOException
-
-