Package com.google.cloud
Class ByteArray
java.lang.Object
com.google.cloud.ByteArray
- All Implemented Interfaces:
Serializable,Iterable<Byte>
An immutable byte array holder.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfinal InputStreamReturns anInputStreamfor thisByteArraycontent.final ByteBufferReturns the content of thisByteArrayas a read-onlyByteBuffer.static final ByteArraycopyFrom(byte[] bytes) Creates aByteArrayobject given an array of bytes.static final ByteArraycopyFrom(InputStream input) Creates aByteArrayobject given anInputStream.static final ByteArrayCreates aByteArrayobject given a string.static final ByteArraycopyFrom(ByteBuffer bytes) Creates aByteArrayobject given aByteBuffer.final voidcopyTo(byte[] target) Copies the content of thisByteArrayinto an array of bytes.final voidcopyTo(ByteBuffer target) Copies the content of thisByteArrayinto an existingByteBuffer.final booleanstatic ByteArrayfromBase64(String data) Creates aByteArrayfrom a base64 representation.final inthashCode()iterator()final intlength()Returns the number of bytes in thisByteArray.final StringtoBase64()Converts this byte array to its base64 representation.final byte[]Returns a copy of thisByteArrayas an array of bytes.toString()final StringReturns a copy of thisByteArrayas anUTF-8string.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
iterator
-
toString
-
hashCode
public final int hashCode() -
equals
-
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
Returns a copy of thisByteArrayas anUTF-8string. -
toBase64
Converts this byte array to its base64 representation. -
asReadOnlyByteBuffer
Returns the content of thisByteArrayas a read-onlyByteBuffer. -
asInputStream
Returns anInputStreamfor thisByteArraycontent. -
copyTo
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
Creates aByteArrayobject given an array of bytes. The bytes are copied. -
copyFrom
Creates aByteArrayobject given a string. The string is encoded inUTF-8. The bytes are copied. -
copyFrom
Creates aByteArrayobject given aByteBuffer. The bytes are copied. -
copyFrom
Creates aByteArrayobject given anInputStream. The stream is read into the created object.- Throws:
IOException
-
fromBase64
Creates aByteArrayfrom a base64 representation.
-