public final class ByteString extends Object implements Serializable
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 |
|---|---|
String |
base64()
Returns this byte string encoded as Base64.
|
static ByteString |
decodeBase64(String base64)
Decodes the Base64-encoded bytes and returns their value as a byte string.
|
static ByteString |
decodeHex(String hex)
Decodes the hex-encoded bytes and returns their value a byte string.
|
static ByteString |
encodeUtf8(String s)
Returns a new byte string containing the
UTF-8 bytes of s. |
boolean |
equals(Object o) |
byte |
getByte(int pos)
Returns the byte at
pos. |
int |
hashCode() |
String |
hex()
Returns this byte string encoded in hexadecimal.
|
static ByteString |
of(byte... data)
Returns a new byte string containing a clone of the bytes of
data. |
static ByteString |
of(byte[] data,
int offset,
int byteCount)
Returns a new byte string containing a copy of
byteCount bytes of data starting
at offset. |
static ByteString |
read(InputStream in,
int byteCount)
Reads
count bytes from in and returns the result. |
int |
size()
Returns the number of bytes in this ByteString.
|
ByteString |
toAsciiLowercase()
Returns a byte string equal to this byte string, but with the bytes 'A'
through 'Z' replaced with the corresponding byte in 'a' through 'z'.
|
ByteString |
toAsciiUppercase()
Returns a byte string equal to this byte string, but with the bytes 'a'
through 'z' replaced with the corresponding byte in 'A' through 'Z'.
|
byte[] |
toByteArray()
Returns a byte array containing a copy of the bytes in this
ByteString. |
String |
toString() |
String |
utf8()
Constructs a new
String by decoding the bytes as UTF-8. |
void |
write(OutputStream out)
Writes the contents 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 byteCount)
byteCount bytes of data starting
at offset.public static ByteString encodeUtf8(String s)
UTF-8 bytes of s.public String utf8()
String by decoding the bytes as UTF-8.public String base64()
public static ByteString decodeBase64(String base64)
base64 is not a Base64-encoded sequence of bytes.public String hex()
public static ByteString decodeHex(String hex)
public static ByteString read(InputStream in, int byteCount) throws IOException
count bytes from in and returns the result.EOFException - if in has fewer than count
bytes to read.IOExceptionpublic ByteString toAsciiLowercase()
public ByteString toAsciiUppercase()
public byte getByte(int pos)
pos.public int size()
public byte[] toByteArray()
ByteString.public void write(OutputStream out) throws IOException
out.IOExceptionCopyright © 2015. All rights reserved.