public class ByteString extends Object implements Serializable, 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.
| Modifier and Type | Field and Description | 
|---|---|
| static ByteString | EMPTYA singleton empty  ByteString. | 
| Modifier and Type | Method and Description | 
|---|---|
| ByteBuffer | asByteBuffer()Returns a  ByteBufferview of the bytes in thisByteString. | 
| String | base64()Returns this byte string encoded as Base64. | 
| String | base64Url()Returns this byte string encoded as URL-safe
 Base64. | 
| int | compareTo(ByteString byteString) | 
| 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 | encodeString(String s,
            Charset charset)Returns a new byte string containing the  charset-encoded bytes ofs. | 
| static ByteString | encodeUtf8(String s)Returns a new byte string containing the  UTF-8bytes ofs. | 
| boolean | endsWith(byte[] suffix) | 
| boolean | endsWith(ByteString suffix) | 
| boolean | equals(Object o) | 
| byte | getByte(int pos)Returns the byte at  pos. | 
| int | hashCode() | 
| String | hex()Returns this byte string encoded in hexadecimal. | 
| ByteString | hmacSha1(ByteString key)Returns the 160-bit SHA-1 HMAC of this byte string. | 
| ByteString | hmacSha256(ByteString key)Returns the 256-bit SHA-256 HMAC of this byte string. | 
| ByteString | hmacSha512(ByteString key)Returns the 512-bit SHA-512 HMAC of this byte string. | 
| int | indexOf(byte[] other) | 
| int | indexOf(byte[] other,
       int fromIndex) | 
| int | indexOf(ByteString other) | 
| int | indexOf(ByteString other,
       int fromIndex) | 
| int | lastIndexOf(byte[] other) | 
| int | lastIndexOf(byte[] other,
           int fromIndex) | 
| int | lastIndexOf(ByteString other) | 
| int | lastIndexOf(ByteString other,
           int fromIndex) | 
| ByteString | md5()Returns the 128-bit 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  byteCountbytes ofdatastarting
 atoffset. | 
| static ByteString | of(ByteBuffer data) | 
| boolean | rangeEquals(int offset,
           byte[] other,
           int otherOffset,
           int byteCount)Returns true if the bytes of this in  [offset..offset+byteCount)equal the bytes ofotherin[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 ofotherin[otherOffset..otherOffset+byteCount). | 
| static ByteString | read(InputStream in,
    int byteCount)Reads  countbytes frominand returns the result. | 
| ByteString | sha1()Returns the 160-bit SHA-1 hash of this byte string. | 
| ByteString | sha256()Returns the 256-bit SHA-256 hash of this byte string. | 
| ByteString | sha512()Returns the 512-bit SHA-512 hash of this byte string. | 
| int | size()Returns the number of bytes in this ByteString. | 
| boolean | startsWith(byte[] prefix) | 
| boolean | startsWith(ByteString prefix) | 
| String | string(Charset charset)Constructs a new  Stringby decoding the bytes usingcharset. | 
| 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
  beginIndexand ends at the specifiedendIndex. | 
| 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()Returns a human-readable string that describes the contents of this byte string. | 
| String | utf8()Constructs a new  Stringby decoding the bytes asUTF-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 of(ByteBuffer data)
public static ByteString encodeUtf8(String s)
UTF-8 bytes of s.public static ByteString encodeString(String s, Charset charset)
charset-encoded bytes of s.public String utf8()
String by decoding the bytes as UTF-8.public String string(Charset charset)
String by decoding the bytes using charset.public String base64()
public ByteString md5()
public ByteString sha1()
public ByteString sha256()
public ByteString sha512()
public ByteString hmacSha1(ByteString key)
public ByteString hmacSha256(ByteString key)
public ByteString hmacSha512(ByteString key)
public String base64Url()
@Nullable 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 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 ByteBuffer asByteBuffer()
ByteBuffer view of the bytes in this ByteString.public void write(OutputStream out) throws IOException
out.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 final boolean startsWith(ByteString prefix)
public final boolean startsWith(byte[] prefix)
public final boolean endsWith(ByteString suffix)
public final boolean endsWith(byte[] suffix)
public final int indexOf(ByteString other)
public final int indexOf(ByteString other, int fromIndex)
public final int indexOf(byte[] other)
public int indexOf(byte[] other,
                   int fromIndex)
public final int lastIndexOf(ByteString other)
public final int lastIndexOf(ByteString other, int fromIndex)
public final int lastIndexOf(byte[] other)
public int lastIndexOf(byte[] other,
                       int fromIndex)
public int compareTo(ByteString byteString)
compareTo in interface Comparable<ByteString>Copyright © 2017. All rights reserved.