Top Description Fields Constructors Methods
org.xnio

public final Class ByteString

extends Object
implements Comparable<ByteString>, Serializable, CharSequence
Class Inheritance
All Implemented Interfaces
java.lang.CharSequence, java.io.Serializable, java.lang.Comparable
Imports
java.io.IOException, .ObjectInputStream, .OutputStream, .UnsupportedEncodingException, .Serializable, java.nio.charset.StandardCharsets, .Charset, java.util.Arrays, java.nio.ByteBuffer

An immutable string of bytes. Since instances of this class are guaranteed to be immutable, they are safe to use as Option values and in an OptionMap. Some operations can treat this byte string as an ASCII- or ISO-8858-1-encoded character string.

Field Summary

Modifier and TypeField and Description
private final byte[]
private transient int
private transient int
private final int
private final int
private static final long
private static final ByteString

Constructor Summary

AccessConstructor and Description
private
ByteString(final byte[] bytes, final int offs, final int len)

private
ByteString(final byte[] bytes)

Method Summary

Modifier and TypeMethod and Description
public void
appendTo(ByteBuffer
the target buffer
dest
)

Append the bytes of this string into the given buffer.

private static int
arrayIndexOf(byte[] a, int aOffs, byte[] b, int bOffs, int bLen)

private static int
arrayIndexOf(byte[] a, int aOffs, String string)

private static int
arrayIndexOfIgnoreCase(byte[] a, int aOffs, byte[] b, int bOffs, int bLen)

private static int
arrayIndexOfIgnoreCase(byte[] a, int aOffs, String string)

private static int
arrayLastIndexOf(byte[] a, int aOffs, byte[] b, final int bOffs, final int bLen)

private static int
arrayLastIndexOf(byte[] a, int aOffs, String string)

private static int
arrayLastIndexOfIgnoreCase(byte[] a, int aOffs, byte[] b, final int bOffs, final int bLen)

private static int
arrayLastIndexOfIgnoreCase(byte[] a, int aOffs, String string)

public byte

Returns:

the byte at an index
byteAt
(int idx)

Get the byte at an index.

private static int
calcHashCode(final byte[] bytes, final int offs, final int len)

private static int
calcHashCodeIgnoreCase(final byte[] bytes, final int offs, final int len)

public char
charAt(final int
the index of the char value to be returned
index
)

Implements java.lang.CharSequence.charAt.

Returns the char value at the specified index.

public int

Returns:

-1, 0, or 1
compareTo
(final ByteString
the other string
other
)

Implements java.lang.Comparable.compareTo.

Compare this string to another in a case-sensitive manner.

public int

Returns:

-1, 0, or 1
compareToIgnoreCase
(final ByteString
the other string
other
)

Compare this string to another in a case-insensitive manner.

public ByteString
concat(byte[] suffixBytes)

public ByteString
concat(byte[] suffixBytes, int offs, int len)

public ByteString
public ByteString
concat(ByteString suffix, int offs, int len)

public ByteString
concat(String suffix)

public ByteString
concat(String suffix, int offs, int len)

public static ByteString
concat(String prefix, ByteString suffix)

public static ByteString
concat(String prefix, String suffix)

public boolean

Returns:

true if this string contains other, false otherwise
contains
(final ByteString
the string to test
other
)

Determine whether this string contains another string (case-sensitive).

public boolean

Returns:

true if this string contains other, false otherwise
contains
(final String
the string to test
other
)

Determine whether this string contains another string (case-sensitive).

public boolean

Returns:

true if this string contains other, false otherwise
containsIgnoreCase
(final ByteString
the string to test
other
)

Determine whether this string contains another string (case-insensitive).

public boolean

Returns:

true if this string contains other, false otherwise
containsIgnoreCase
(final String
the string to test
other
)

Determine whether this string contains another string (case-sensitive).

public static ByteString

Returns:

the new byte string
copyOf
(byte[]
the byte array
b
,
int
the offset into the array
offs
,
int
the number of bytes to copy
len
)

Create a byte string from the given array segment.

public void
copyTo(int
the source offset
srcOffs
,
byte[]
the destination
dst
,
int
the destination offset
offs
,
int
the number of bytes to copy
len
)

Copy len bytes from this string at offset srcOffs to the given array at the given offset.

public void
copyTo(byte[]
the destination
dst
,
int
the destination offset
offs
,
int
the number of bytes
len
)

Copy len bytes from this string to the given array at the given offset.

public void
copyTo(byte[]
the destination
dst
,
int
the destination offset
offs
)

Copy all the bytes from this string to the given array at the given offset.

public void
copyTo(byte[]
the destination
dst
)

Copy all the bytes from this string to the given array at the given offset.

private static int
decimalCount(int val)

private static int
decimalCount(long val)

public boolean
public boolean
endsWith(String suffix)

public boolean
endsWith(char suffix)

public boolean
public boolean
public boolean
endsWithIgnoreCase(char suffix)

private static boolean
equals(byte[] a, int aoff, byte[] b, int boff, int len)

public boolean

Returns:

true if they are equal
equals
(final Object
the other object
obj
)

Overrides java.lang.Object.equals.

Determine if this ByteString equals another ByteString.

public boolean

Returns:

true if they are equal
equals
(final ByteString
the other object
other
)

Determine if this ByteString equals another ByteString.

private static boolean
equals(final byte[] a, int aOffs, String string, int stringOffset, int length)

private static boolean
equalsIgnoreCase(byte[] a, int aoff, byte[] b, int boff, int len)

public boolean

Returns:

true if they are equal
equalsIgnoreCase
(final ByteString
the other object
other
)

Determine if this ByteString equals another ByteString, ignoring case (ASCII).

private static boolean
equalsIgnoreCase(final byte[] a, int aOffs, String string, int stringOffset, int length)

public boolean

Returns:

true if the given string is equal (case-sensitively) to this instance, false otherwise
equalToString
(String
the string to check
str
)

Determine whether this ByteString is equal (case-sensitively) to the given String.

public boolean

Returns:

true if the given string is equal (case-insensitively) to this instance, false otherwise
equalToStringIgnoreCase
(String
the string to check
str
)

Determine whether this ByteString is equal (case-insensitively) to the given String.

public static ByteString

Returns:

the string
fromInt
(int
the value
val
)

Get a string version of the given value.

public static ByteString

Returns:

the string
fromLong
(long
the value
val
)

Get a string version of the given value.

public static ByteString

Returns:

the byte string
getBytes
(String
the character string
str
,
String
the character set to use
charset
)

Get a byte string from the bytes of a character string.

public static ByteString

Returns:

the byte string
getBytes
(String
the character string
str
,
Charset
the character set to use
charset
)

Get a byte string from the bytes of a character string.

public static ByteString

Returns:

the byte string
getBytes
(String
the character string
str
)

Get a byte string from the bytes of the character string.

public static ByteString

Returns:

the byte string
getBytes
(ByteBuffer
the buffer
buffer
)

Get a byte string from all remaining bytes of a ByteBuffer.

public static ByteString

Returns:

the byte string
getBytes
(ByteBuffer
the buffer
buffer
,
int
the number of bytes to get
length
)

Get a byte string from a ByteBuffer.

public byte[]

Returns:

the copy
getBytes
()

Get a copy of the bytes of this ByteString.

public void
getBytes(byte[]
the destination array
dest
)
Deprecated Replaced by copyTo(byte[]).

Copy the bytes of this ByteString into the destination array.

public void
getBytes(byte[]
the destination array
dest
,
int
the offset into the destination array
offs
)
Deprecated Replaced by copyTo(byte[], int).

Copy the bytes of this ByteString into the destination array.

public void
getBytes(byte[]
the destination array
dest
,
int
the offset into the destination array
offs
,
int
the maximum number of bytes to copy
len
)
Deprecated Replaced by copyTo(byte[], int, int).

Copy the bytes of this ByteString into the destination array.

private static byte[]
getStringBytes(final boolean trust, final byte[] dst, final int dstOffs, final String src, final int srcOffs, final int len)

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Get the hash code for this ByteString.

public int
public int

Returns:

the index, or -1 if it was not found
indexOf
(final char
the character
c
)

Get the index of the given character in this string.

public int

Returns:

the index, or -1 if it was not found
indexOf
(final char
the character
c
,
int start)

Get the index of the given character in this string.

public int
indexOf(final ByteString other)

public int
indexOf(final ByteString other, int start)

public int
indexOf(final String other)

public int
indexOf(final String other, int start)

public int
public int
indexOfIgnoreCase(final ByteString other, int start)

public int
public int
indexOfIgnoreCase(final String other, int start)

public int

Returns:

the index, or -1 if it was not found
lastIndexOf
(final char
the character
c
)

Get the last index of the given character in this string.

public int

Returns:

the index, or -1 if it was not found
lastIndexOf
(final char
the character
c
,
int start)

Get the last index of the given character in this string.

public int
lastIndexOf(final ByteString other)

public int
lastIndexOf(final ByteString other, int start)

public int
lastIndexOf(final String other)

public int
lastIndexOf(final String other, int start)

public int
public int
lastIndexOfIgnoreCase(final ByteString other, int start)

public int
public int
lastIndexOfIgnoreCase(final String other, int start)

public int

Returns:

the number of bytes
length
()

Implements java.lang.CharSequence.length.

Get the number of bytes in this byte string.

public static ByteString

Returns:

the byte string
of
(byte...
the bytes
bytes
)

Create a byte string of the given literal bytes.

private void
public boolean
regionMatches(boolean ignoreCase, int offset, byte[] other, int otherOffset, int len)

public boolean
regionMatches(boolean ignoreCase, int offset, ByteString other, int otherOffset, int len)

public boolean
regionMatches(boolean ignoreCase, int offset, String other, int otherOffset, int len)

public boolean
public boolean
public boolean
startsWith(char prefix)

public boolean
public boolean
public boolean
startsWithIgnoreCase(char prefix)

public ByteString
subSequence(final int
the start index, inclusive
start
,
final int
the end index, exclusive
end
)

Implements java.lang.CharSequence.subSequence.

Returns a CharSequence that is a subsequence of this sequence.

public ByteString

Returns:

the substring
substring
(int
the offset
offs
)

Get the substring of this string starting at the given offset.

public ByteString

Returns:

the substring
substring
(int
the offset
offs
,
int
the substring length
len
)

Get the substring of this string starting at the given offset.

public int

Returns:

the value
toInt
(final int
the index to start at (must be less than or equal to length)
start
)

Get the unsigned int value of this string.

public int

Returns:

the value
toInt
()

Get the unsigned int value of this string.

public long

Returns:

the value
toLong
(final int
the index to start at (must be less than or equal to length)
start
)

Get the unsigned long value of this string.

public long

Returns:

the value
toLong
()

Get the unsigned long value of this string.

public String

Returns:

the standard string
toString
(String
the character set to use
charset
)

Convert this byte string to a standard string.

public String

Returns:

the Latin-1-decoded version of this string
toString
()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Decode this byte string as a Latin-1 string.

public String

Returns:

the UTF-8-decoded version of this string
toUtf8String
()

Decode this byte string as a UTF-8 string.

public int

Returns:

the number of bytes appended
tryAppendTo
(final int
the start offset
offs
,
final ByteBuffer
the buffer to append to
buffer
)

Append as many bytes as possible to a byte buffer.

private static int
upperCase(byte b)

public void
writeTo(OutputStream
the stream to write to
output
)

Append to an output stream.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait