public class ByteString extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<ByteString>
Byte strings compare lexicographically as a sequence of unsigned bytes. That
is, the byte string ff sorts after 00. This is counter to the sort order of the
corresponding bytes, where -1 sorts before 0.
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.
| 限定符和类型 | 字段和说明 |
|---|---|
static ByteString |
EMPTY
A singleton empty
ByteString. |
| 限定符和类型 | 方法和说明 |
|---|---|
java.lang.String |
base64()
Returns this byte string encoded as Base64.
|
java.lang.String |
base64Url()
Returns this byte string encoded as URL-safe
Base64.
|
int |
compareTo(ByteString byteString) |
static ByteString |
decodeBase64(java.lang.String base64)
Decodes the Base64-encoded bytes and returns their value as a byte string.
|
static ByteString |
decodeHex(java.lang.String hex)
Decodes the hex-encoded bytes and returns their value a byte string.
|
static ByteString |
encodeUtf8(java.lang.String s)
Returns a new byte string containing the
UTF-8 bytes of s. |
boolean |
equals(java.lang.Object o) |
byte |
getByte(int pos)
Returns the byte at
pos. |
int |
hashCode() |
java.lang.String |
hex()
Returns this byte string encoded in hexadecimal.
|
ByteString |
md5()
Returns the MD5 hash of this byte string.
|
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. |
boolean |
rangeEquals(int offset,
byte[] other,
int otherOffset,
int byteCount)
Returns true if the bytes of this in
[offset..offset+byteCount) equal the bytes of
other in [otherOffset..otherOffset+byteCount). |
boolean |
rangeEquals(int offset,
ByteString other,
int otherOffset,
int byteCount)
Returns true if the bytes of this in
[offset..offset+byteCount) equal the bytes of
other in [otherOffset..otherOffset+byteCount). |
static ByteString |
read(java.io.InputStream in,
int byteCount)
Reads
count bytes from in and returns the result. |
ByteString |
sha256()
Returns the SHA-256 hash of this byte string.
|
int |
size()
Returns the number of bytes in this ByteString.
|
ByteString |
substring(int beginIndex)
Returns a byte string that is a substring of this byte string, beginning at the specified
index until the end of this string.
|
ByteString |
substring(int beginIndex,
int endIndex)
Returns a byte string that is a substring of this byte string, beginning at the specified
beginIndex and ends at the specified endIndex. |
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. |
java.lang.String |
toString() |
java.lang.String |
utf8()
Constructs a new
String by decoding the bytes as UTF-8. |
void |
write(java.io.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(java.lang.String s)
UTF-8 bytes of s.public java.lang.String utf8()
String by decoding the bytes as UTF-8.public java.lang.String base64()
public ByteString md5()
public ByteString sha256()
public java.lang.String base64Url()
public static ByteString decodeBase64(java.lang.String base64)
base64 is not a Base64-encoded sequence of bytes.public java.lang.String hex()
public static ByteString decodeHex(java.lang.String hex)
public static ByteString read(java.io.InputStream in, int byteCount) throws java.io.IOException
count bytes from in and returns the result.java.io.EOFException - if in has fewer than count
bytes to read.java.io.IOExceptionpublic ByteString toAsciiLowercase()
public ByteString toAsciiUppercase()
public ByteString substring(int beginIndex)
beginIndex is 0.public ByteString substring(int beginIndex, int endIndex)
beginIndex and ends at the specified endIndex. Returns this byte string if
beginIndex is 0 and endIndex is the length of this byte string.public byte getByte(int pos)
pos.public int size()
public byte[] toByteArray()
ByteString.public void write(java.io.OutputStream out)
throws java.io.IOException
out.java.io.IOExceptionpublic boolean rangeEquals(int offset,
ByteString other,
int otherOffset,
int byteCount)
[offset..offset+byteCount) equal the bytes of
other in [otherOffset..otherOffset+byteCount). Returns false if either range is
out of bounds.public boolean rangeEquals(int offset,
byte[] other,
int otherOffset,
int byteCount)
[offset..offset+byteCount) equal the bytes of
other in [otherOffset..otherOffset+byteCount). Returns false if either range is
out of bounds.public boolean equals(java.lang.Object o)
equals 在类中 java.lang.Objectpublic int hashCode()
hashCode 在类中 java.lang.Objectpublic int compareTo(ByteString byteString)
compareTo 在接口中 java.lang.Comparable<ByteString>public java.lang.String toString()
toString 在类中 java.lang.Object