Package org.apache.calcite.avatica.util
Class ByteString
java.lang.Object
org.apache.calcite.avatica.util.ByteString
- All Implemented Interfaces:
Serializable,Comparable<ByteString>
Collection of bytes.
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.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbytebyteAt(int i) Returns the byte at a given position in the byte string.clone()intcompareTo(ByteString that) concat(ByteString other) Returns a ByteString consisting of the concatenation of this and another string.booleanbyte[]getBytes()Returns a copy of the byte array.inthashCode()intindexOf(ByteString seek) Returns the position at whichseekfirst occurs in this byte string, or -1 if it does not occur.intindexOf(ByteString seek, int start) Returns the position at whichseekfirst occurs in this byte string, starting at the specified index, or -1 if it does not occur.intlength()Returns the number of bytes in this byte string.static ByteStringCreates a byte string from a hexadecimal or binary string.static ByteStringCreates a byte string from a Base64 string.static byte[]Parses a hexadecimal or binary string to a byte array.static byte[]parseBase64(String string) Parses a Base64 to a byte array.substring(int start) Returns a ByteString that starts at a given position.substring(int start, int end) Returns a ByteString that consists of a given range.Returns this byte string in Base64 format.toString()Returns this byte string in hexadecimal format.static StringtoString(byte[] bytes, int base) Returns the given byte array in hexadecimal format.toString(int base) Returns this byte string in a given base.
-
Field Details
-
EMPTY
An empty byte string.
-
-
Constructor Details
-
ByteString
public ByteString(byte[] bytes) Creates a ByteString.- Parameters:
bytes- Bytes
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<ByteString>
-
toString
Returns this byte string in hexadecimal format. -
toString
Returns this byte string in a given base.- Returns:
- String in given base
-
toString
Returns the given byte array in hexadecimal format.For example,
toString(new byte[] {0xDE, 0xAD})returns"DEAD".- Parameters:
bytes- Array of bytesbase- Base (2 or 16)- Returns:
- String
-
toBase64String
Returns this byte string in Base64 format.- Returns:
- Base64 string
-
of
Creates a byte string from a hexadecimal or binary string.For example,
of("DEAD", 16)returns the same asByteString(new byte[] {0xDE, 0xAD}).- Parameters:
string- Array of bytesbase- Base (2 or 16)- Returns:
- String
-
parse
Parses a hexadecimal or binary string to a byte array.- Parameters:
string- Hexadecimal or binary stringbase- Base (2 or 16)- Returns:
- Byte array
-
ofBase64
Creates a byte string from a Base64 string.- Parameters:
string- Base64 string- Returns:
- Byte string
-
parseBase64
Parses a Base64 to a byte array.- Parameters:
string- Base64 string- Returns:
- Byte array
-
clone
-
length
public int length()Returns the number of bytes in this byte string.- Returns:
- Length of this byte string
-
byteAt
public byte byteAt(int i) Returns the byte at a given position in the byte string.- Parameters:
i- Index- Returns:
- Byte at given position
- Throws:
IndexOutOfBoundsException- if theindexargument is negative or not less thanlength()
-
substring
Returns a ByteString that consists of a given range.- Parameters:
start- Start of rangeend- Position after end of range- Returns:
- Substring
-
substring
Returns a ByteString that starts at a given position.- Parameters:
start- Start of range- Returns:
- Substring
-
getBytes
public byte[] getBytes()Returns a copy of the byte array. -
concat
Returns a ByteString consisting of the concatenation of this and another string.- Parameters:
other- Byte string to concatenate- Returns:
- Combined byte string
-
indexOf
Returns the position at whichseekfirst occurs in this byte string, or -1 if it does not occur. -
indexOf
Returns the position at whichseekfirst occurs in this byte string, starting at the specified index, or -1 if it does not occur.
-