public final class ByteString extends Object
Full disclosure: this class provides untrusted input and output streams with raw access to the underlying byte array. A hostile stream implementation could keep a reference to the mutable byte string, violating the immutable guarantee of this class. For this reason a byte string's immutability guarantee cannot be relied upon for security in applets and other environments that run both trusted and untrusted code in the same process.
| Modifier and Type | Field and Description |
|---|---|
static ByteString |
EMPTY
A singleton empty
ByteString. |
| Modifier and Type | Method and Description |
|---|---|
byte |
byteAt(int index) |
boolean |
equals(Object o) |
int |
hashCode() |
static ByteString |
of(byte... data)
Returns a new byte string containing the bytes of
data. |
static ByteString |
of(byte[] data,
int offset,
int count)
Returns a new byte string containing the bytes of
data
from offset to offset + count - 1, inclusive. |
static ByteString |
of(String data)
Returns a new byte string containing the bytes of
data, interpreted
as Base64. |
static ByteString |
read(InputStream in,
int count)
Reads
count bytes from in and returns the result. |
int |
size()
Returns the number of bytes in this ByteString.
|
byte[] |
toByteArray()
Returns a byte array containing a copy of the bytes in this
ByteString. |
String |
toString()
Returns a string containing the contents of this ByteString in Base64 format.
|
void |
write(OutputStream out)
Writes the contents of this byte string to
out. |
void |
write(OutputStream out,
int offset,
int count)
Writes a subsequence of this byte string to
out. |
public static final ByteString EMPTY
ByteString.public static ByteString of(byte... data)
data.public static ByteString of(byte[] data, int offset, int count)
data
from offset to offset + count - 1, inclusive.public static ByteString of(String data)
data, interpreted
as Base64.public static ByteString read(InputStream in, int count) throws IOException
count bytes from in and returns the result.EOFException - if in has fewer than count bytes to
read.IOExceptionpublic byte byteAt(int index)
public int size()
public byte[] toByteArray()
ByteString.public void write(OutputStream out) throws IOException
out.IOExceptionpublic void write(OutputStream out, int offset, int count) throws IOException
out.IOExceptionCopyright © 2013 Square, Inc.. All Rights Reserved.