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 |
---|---|
static ByteString |
EMPTY
An empty byte string.
|
Constructor and Description |
---|
ByteString(byte[] bytes)
Creates a ByteString.
|
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.
|
boolean |
endsWith(ByteString suffix)
Returns whether this ByteString ends with the specified suffix.
|
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 |
indexOf(ByteString seek,
int start)
Returns the position at which
seek first occurs in this byte
string, starting at the specified index, 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.
|
boolean |
startsWith(ByteString prefix)
Returns whether this ByteString starts with the specified prefix.
|
boolean |
startsWith(ByteString prefix,
int offset)
Returns whether the substring of this ByteString beginning at the
specified index starts with the specified prefix.
|
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.
|
public static final ByteString EMPTY
public ByteString(byte[] bytes)
bytes
- Bytespublic 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)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.public int indexOf(ByteString seek, int start)
seek
first occurs in this byte
string, starting at the specified index, or -1 if it does not occur.public boolean startsWith(ByteString prefix, int offset)
prefix
- The prefixoffset
- Where to begin looking in this stringpublic boolean startsWith(ByteString prefix)
public boolean endsWith(ByteString suffix)
Copyright © 2012-2025 Apache Software Foundation. All Rights Reserved.