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:
  • Method Details

    • iterator

      public final Iterator<Byte> iterator()
      Specified by:
      iterator in interface Iterable<Byte>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • length

      public final int length()
      Returns the number of bytes in this ByteArray.
    • toByteArray

      public final byte[] toByteArray()
      Returns a copy of this ByteArray as an array of bytes.
    • toStringUtf8

      public final String toStringUtf8()
      Returns a copy of this ByteArray as an UTF-8 string.
    • toBase64

      public final String toBase64()
      Converts this byte array to its base64 representation.
    • asReadOnlyByteBuffer

      public final ByteBuffer asReadOnlyByteBuffer()
      Returns the content of this ByteArray as a read-only ByteBuffer.
    • asInputStream

      public final InputStream asInputStream()
      Returns an InputStream for this ByteArray content.
    • copyTo

      public final void copyTo(ByteBuffer target)
      Copies the content of this ByteArray into an existing ByteBuffer.
      Throws:
      ReadOnlyBufferException - if the target is read-only
      BufferOverflowException - if the target's Buffer.remaining() space is not large enough to hold the data
    • copyTo

      public final void copyTo(byte[] target)
      Copies the content of this ByteArray 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 a ByteArray object given an array of bytes. The bytes are copied.
    • copyFrom

      public static final ByteArray copyFrom(String string)
      Creates a ByteArray object given a string. The string is encoded in UTF-8. The bytes are copied.
    • copyFrom

      public static final ByteArray copyFrom(ByteBuffer bytes)
      Creates a ByteArray object given a ByteBuffer. The bytes are copied.
    • copyFrom

      public static final ByteArray copyFrom(InputStream input) throws IOException
      Creates a ByteArray object given an InputStream. The stream is read into the created object.
      Throws:
      IOException
    • fromBase64

      public static ByteArray fromBase64(String data)
      Creates a ByteArray from a base64 representation.