public class ByteString extends Object implements Comparable<ByteString>, Serializable
ByteString is to bytes what String is to chars: It is immutable,
implements equality (hashCode() and equals(java.lang.Object)),
comparison (compareTo(org.apache.calcite.avatica.util.ByteString)) and
serialization correctly.
| Modifier and Type | Field and Description |
|---|---|
private byte[] |
bytes |
private static char[] |
DIGITS |
static ByteString |
EMPTY
An empty byte string.
|
| Modifier | Constructor and Description |
|---|---|
|
ByteString(byte[] bytes)
Creates a ByteString.
|
private |
ByteString(byte[] bytes,
boolean dummy) |
| Modifier and Type | Method and Description |
|---|---|
byte |
byteAt(int i)
Returns the byte at a given position in the byte string.
|
Object |
clone() |
int |
compareTo(ByteString that) |
ByteString |
concat(ByteString other)
Returns a ByteString consisting of the concatenation of this and another
string.
|
private static byte |
decodeHex(char c) |
boolean |
equals(Object obj) |
byte[] |
getBytes()
Returns a copy of the byte array.
|
int |
hashCode() |
int |
indexOf(ByteString seek)
Returns the position at which
seek first occurs in this byte
string, or -1 if it does not occur. |
int |
length()
Returns the number of bytes in this byte string.
|
static ByteString |
of(String string,
int base)
Creates a byte string from a hexadecimal or binary string.
|
static ByteString |
ofBase64(String string)
Creates a byte string from a Base64 string.
|
static byte[] |
parse(String string,
int base)
Parses a hexadecimal or binary string to a byte array.
|
static byte[] |
parseBase64(String string)
Parses a Base64 to a byte array.
|
ByteString |
substring(int start)
Returns a ByteString that starts at a given position.
|
ByteString |
substring(int start,
int end)
Returns a ByteString that consists of a given range.
|
String |
toBase64String()
Returns this byte string in Base64 format.
|
String |
toString()
Returns this byte string in hexadecimal format.
|
static String |
toString(byte[] bytes,
int base)
Returns the given byte array in hexadecimal format.
|
String |
toString(int base)
Returns this byte string in a given base.
|
private final byte[] bytes
public static final ByteString EMPTY
private static final char[] DIGITS
public ByteString(byte[] bytes)
bytes - Bytesprivate ByteString(byte[] bytes,
boolean dummy)
public int compareTo(ByteString that)
compareTo in interface Comparable<ByteString>public String toString()
public String toString(int base)
public static String toString(byte[] bytes, int base)
For example, toString(new byte[] {0xDE, 0xAD})
returns "DEAD".
bytes - Array of bytesbase - Base (2 or 16)public String toBase64String()
public static ByteString of(String string, int base)
For example, of("DEAD", 16)
returns the same as ByteString(new byte[] {0xDE, 0xAD}).
string - Array of bytesbase - Base (2 or 16)public static byte[] parse(String string, int base)
string - Hexadecimal or binary stringbase - Base (2 or 16)private static byte decodeHex(char c)
public static ByteString ofBase64(String string)
string - Base64 stringpublic static byte[] parseBase64(String string)
string - Base64 stringpublic int length()
public byte byteAt(int i)
i - IndexIndexOutOfBoundsException - if the index argument is negative or not less than
length()public ByteString substring(int start, int end)
start - Start of rangeend - Position after end of rangepublic ByteString substring(int start)
start - Start of rangepublic byte[] getBytes()
public ByteString concat(ByteString other)
other - Byte string to concatenatepublic int indexOf(ByteString seek)
seek first occurs in this byte
string, or -1 if it does not occur.Copyright © 2012–2016 The Apache Software Foundation. All rights reserved.