Package org.xnio

# Class ByteString

java.lang.Object
org.xnio.ByteString

All Implemented Interfaces:
  `Serializable`, `CharSequence`, `Comparable<ByteString>`

public final class ByteString extends Object implements Comparable<ByteString>, Serializable, CharSequence
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.

See Also:
  - Serialized Form

## Method Summary

Modifier and Type
Method
Description
`void`
`appendTo(ByteBuffer dest)`
Append the bytes of this string into the given buffer.
`byte`
`byteAt(int idx)`
Get the byte at an index.
`char`
`charAt(int index)`
`int`
`compareTo(ByteString other)`
Compare this string to another in a case-sensitive manner.
`int`
`compareToIgnoreCase(ByteString other)`
Compare this string to another in a case-insensitive manner.
`ByteString`
`concat(byte[] suffixBytes)`
`ByteString`
`concat(byte[] suffixBytes, int offs, int len)`
`ByteString`
`concat(String suffix)`
`ByteString`
`concat(String suffix, int offs, int len)`
`static ByteString`
`concat(String prefix, String suffix)`
`static ByteString`
`concat(String prefix, ByteString suffix)`
`ByteString`
`concat(ByteString suffix)`
`ByteString`
`concat(ByteString suffix, int offs, int len)`
`boolean`
`contains(String other)`
Determine whether this string contains another string (case-sensitive).
`boolean`
`contains(ByteString other)`
Determine whether this string contains another string (case-sensitive).
`boolean`
`containsIgnoreCase(String other)`
Determine whether this string contains another string (case-sensitive).
`boolean`
`containsIgnoreCase(ByteString other)`
Determine whether this string contains another string (case-insensitive).
`static ByteString`
`copyOf(byte[] b, int offs, int len)`
Create a byte string from the given array segment.
`void`
`copyTo(byte[] dst)`
Copy all the bytes from this string to the given array at the given offset.
`void`
`copyTo(byte[] dst, int offs)`
Copy all the bytes from this string to the given array at the given offset.
`void`
`copyTo(byte[] dst, int offs, int len)`
Copy `len` bytes from this string to the given array at the given offset.
`void`
`copyTo(int srcOffs, byte[] dst, int offs, int len)`
Copy `len` bytes from this string at offset `srcOffs` to the given array at the given offset.
`boolean`
`endsWith(char suffix)`
`boolean`
`endsWith(String suffix)`
`boolean`
`endsWith(ByteString suffix)`
`boolean`
`endsWithIgnoreCase(char suffix)`
`boolean`
`endsWithIgnoreCase(String suffix)`
`boolean`
`endsWithIgnoreCase(ByteString suffix)`
`boolean`
`equals(Object obj)`
Determine if this ByteString equals another ByteString.
`boolean`
`equals(ByteString other)`
Determine if this ByteString equals another ByteString.
`boolean`
`equalsIgnoreCase(ByteString other)`
Determine if this ByteString equals another ByteString, ignoring case (ASCII).
`boolean`
`equalToString(String str)`
Determine whether this `ByteString` is equal (case-sensitively) to the given `String`.
`boolean`
`equalToStringIgnoreCase(String str)`
Determine whether this `ByteString` is equal (case-insensitively) to the given `String`.
`static ByteString`
`fromInt(int val)`
Get a string version of the given value.
`static ByteString`
`fromLong(long val)`
Get a string version of the given value.
`byte[]`
`getBytes()`
Get a copy of the bytes of this ByteString.
`void`
`getBytes(byte[] dest)`
Deprecated.
Replaced by `copyTo(byte[])`.
`void`
`getBytes(byte[] dest, int offs)`
Deprecated.
Replaced by `copyTo(byte[],int)`.
`void`
`getBytes(byte[] dest, int offs, int len)`
Deprecated.
Replaced by `copyTo(byte[],int,int)`.
`static ByteString`
`getBytes(String str)`
Get a byte string from the bytes of the character string.
`static ByteString`
`getBytes(String str, String charset)`
Get a byte string from the bytes of a character string.
`static ByteString`
`getBytes(String str, Charset charset)`
Get a byte string from the bytes of a character string.
`static ByteString`
`getBytes(ByteBuffer buffer)`
Get a byte string from all remaining bytes of a ByteBuffer.
`static ByteString`
`getBytes(ByteBuffer buffer, int length)`
Get a byte string from a ByteBuffer.
`int`
`hashCode()`
Get the hash code for this ByteString.
`int`
`hashCodeIgnoreCase()`
`int`
`indexOf(char c)`
Get the index of the given character in this string.
`int`
`indexOf(char c, int start)`
Get the index of the given character in this string.
`int`
`indexOf(String other)`
`int`
`indexOf(String other, int start)`
`int`
`indexOf(ByteString other)`
`int`
`indexOf(ByteString other, int start)`
`int`
`indexOfIgnoreCase(String other)`
`int`
`indexOfIgnoreCase(String other, int start)`
`int`
`indexOfIgnoreCase(ByteString other)`
`int`
`indexOfIgnoreCase(ByteString other, int start)`
`int`
`lastIndexOf(char c)`
Get the last index of the given character in this string.
`int`
`lastIndexOf(char c, int start)`
Get the last index of the given character in this string.
`int`
`lastIndexOf(String other)`
`int`
`lastIndexOf(String other, int start)`
`int`
`lastIndexOf(ByteString other)`
`int`
`lastIndexOf(ByteString other, int start)`
`int`
`lastIndexOfIgnoreCase(String other)`
`int`
`lastIndexOfIgnoreCase(String other, int start)`
`int`
`lastIndexOfIgnoreCase(ByteString other)`
`int`
`lastIndexOfIgnoreCase(ByteString other, int start)`
`int`
`length()`
Get the number of bytes in this byte string.
`static ByteString`
`of(byte... bytes)`
Create a byte string of the given literal bytes.
`boolean`
`regionMatches(boolean ignoreCase, int offset, byte[] other, int otherOffset, int len)`
`boolean`
`regionMatches(boolean ignoreCase, int offset, String other, int otherOffset, int len)`
`boolean`
`regionMatches(boolean ignoreCase, int offset, ByteString other, int otherOffset, int len)`
`boolean`
`startsWith(char prefix)`
`boolean`
`startsWith(String prefix)`
`boolean`
`startsWith(ByteString prefix)`
`boolean`
`startsWithIgnoreCase(char prefix)`
`boolean`
`startsWithIgnoreCase(String prefix)`
`boolean`
`startsWithIgnoreCase(ByteString prefix)`
`ByteString`
`subSequence(int start, int end)`
`ByteString`
`substring(int offs)`
Get the substring of this string starting at the given offset.
`ByteString`
`substring(int offs, int len)`
Get the substring of this string starting at the given offset.
`int`
`toInt()`
Get the unsigned `int` value of this string.
`int`
`toInt(int start)`
Get the unsigned `int` value of this string.
`long`
`toLong()`
Get the unsigned `long` value of this string.
`long`
`toLong(int start)`
Get the unsigned `long` value of this string.
`String`
`toString()`
Decode this byte string as a Latin-1 string.
`String`
`toString(String charset)`
Convert this byte string to a standard string.
`String`
`toUtf8String()`
Decode this byte string as a UTF-8 string.
`int`
`tryAppendTo(int offs, ByteBuffer buffer)`
Append as many bytes as possible to a byte buffer.
`void`
`writeTo(OutputStream output)`
Append to an output stream.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.CharSequence

`chars, codePoints, isEmpty`

## Method Details

### of

public static ByteString of(byte... bytes)
Create a byte string of the given literal bytes. The given array is copied.

Parameters:
  `bytes` - the bytes
Returns:
  the byte string

### copyOf

public static ByteString copyOf(byte[] b, int offs, int len)
Create a byte string from the given array segment.

Parameters:
  `b` - the byte array
  `offs` - the offset into the array
  `len` - the number of bytes to copy
Returns:
  the new byte string

### getBytes

public static ByteString getBytes(String str, String charset) throws UnsupportedEncodingException
Get a byte string from the bytes of a character string.

Parameters:
  `str` - the character string
  `charset` - the character set to use
Returns:
  the byte string
Throws:
  `UnsupportedEncodingException` - if the encoding is not supported

### getBytes

public static ByteString getBytes(String str, Charset charset)
Get a byte string from the bytes of a character string.

Parameters:
  `str` - the character string
  `charset` - the character set to use
Returns:
  the byte string

### getBytes

public static ByteString getBytes(String str)
Get a byte string from the bytes of the character string. The string must be a Latin-1 string.

Parameters:
  `str` - the character string
Returns:
  the byte string

### getBytes

public static ByteString getBytes(ByteBuffer buffer)
Get a byte string from all remaining bytes of a ByteBuffer.

Parameters:
  `buffer` - the buffer
Returns:
  the byte string

### getBytes

public static ByteString getBytes(ByteBuffer buffer, int length)
Get a byte string from a ByteBuffer.

Parameters:
  `buffer` - the buffer
  `length` - the number of bytes to get
Returns:
  the byte string

### getBytes

public byte[] getBytes()
Get a copy of the bytes of this ByteString.

Returns:
  the copy

### getBytes

public void getBytes(byte[] dest)
Deprecated.
Replaced by `copyTo(byte[])`.
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
  `dest` - the destination array

### getBytes

public void getBytes(byte[] dest, int offs)
Deprecated.
Replaced by `copyTo(byte[],int)`.
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
  `dest` - the destination array
  `offs` - the offset into the destination array

### getBytes

public void getBytes(byte[] dest, int offs, int len)
Deprecated.
Replaced by `copyTo(byte[],int,int)`.
Copy the bytes of this ByteString into the destination array. If the array is too short to hold the bytes, then only enough bytes to fill the array will be copied.

Parameters:
  `dest` - the destination array
  `offs` - the offset into the destination array
  `len` - the maximum number of bytes to copy

### copyTo

public void copyTo(int srcOffs, byte[] dst, int offs, int len)
Copy `len` bytes from this string at offset `srcOffs` to the given array at the given offset.

Parameters:
  `srcOffs` - the source offset
  `dst` - the destination
  `offs` - the destination offset
  `len` - the number of bytes to copy

### copyTo

public void copyTo(byte[] dst, int offs, int len)
Copy `len` bytes from this string to the given array at the given offset.

Parameters:
  `dst` - the destination
  `offs` - the destination offset
  `len` - the number of bytes

### copyTo

public void copyTo(byte[] dst, int offs)
Copy all the bytes from this string to the given array at the given offset.

Parameters:
  `dst` - the destination
  `offs` - the destination offset

### copyTo

public void copyTo(byte[] dst)
Copy all the bytes from this string to the given array at the given offset.

Parameters:
  `dst` - the destination

### appendTo

public void appendTo(ByteBuffer dest)
Append the bytes of this string into the given buffer.

Parameters:
  `dest` - the target buffer

### tryAppendTo

public int tryAppendTo(int offs, ByteBuffer buffer)
Append as many bytes as possible to a byte buffer.

Parameters:
  `offs` - the start offset
  `buffer` - the buffer to append to
Returns:
  the number of bytes appended

### writeTo

public void writeTo(OutputStream output) throws IOException
Append to an output stream.

Parameters:
  `output` - the stream to write to
Throws:
  `IOException` - if an error occurs

### compareTo

public int compareTo(ByteString other)
Compare this string to another in a case-sensitive manner.

Specified by:
  `compareTo` in interface `Comparable<ByteString>`
Parameters:
  `other` - the other string
Returns:
  -1, 0, or 1

### compareToIgnoreCase

public int compareToIgnoreCase(ByteString other)
Compare this string to another in a case-insensitive manner.

Parameters:
  `other` - the other string
Returns:
  -1, 0, or 1

### toString

public String toString(String charset) throws UnsupportedEncodingException
Convert this byte string to a standard string.

Parameters:
  `charset` - the character set to use
Returns:
  the standard string
Throws:
  `UnsupportedEncodingException` - if the charset is unknown

### length

public int length()
Get the number of bytes in this byte string.

Specified by:
  `length` in interface `CharSequence`
Returns:
  the number of bytes

### toString

public String toString()
Decode this byte string as a Latin-1 string.

Specified by:
  `toString` in interface `CharSequence`
Overrides:
  `toString` in class `Object`
Returns:
  the Latin-1-decoded version of this string

### toUtf8String

public String toUtf8String()
Decode this byte string as a UTF-8 string.

Returns:
  the UTF-8-decoded version of this string

### byteAt

public byte byteAt(int idx)
Get the byte at an index.

Returns:
  the byte at an index

### substring

public ByteString substring(int offs)
Get the substring of this string starting at the given offset.

Parameters:
  `offs` - the offset
Returns:
  the substring

### substring

public ByteString substring(int offs, int len)
Get the substring of this string starting at the given offset.

Parameters:
  `offs` - the offset
  `len` - the substring length
Returns:
  the substring

### hashCode

public int hashCode()
Get the hash code for this ByteString.

Overrides:
  `hashCode` in class `Object`
Returns:
  the hash code

### hashCodeIgnoreCase

public int hashCodeIgnoreCase()

### equals

public boolean equals(Object obj)
Determine if this ByteString equals another ByteString.

Overrides:
  `equals` in class `Object`
Parameters:
  `obj` - the other object
Returns:
  `true` if they are equal

### equals

public boolean equals(ByteString other)
Determine if this ByteString equals another ByteString.

Parameters:
  `other` - the other object
Returns:
  `true` if they are equal

### equalsIgnoreCase

public boolean equalsIgnoreCase(ByteString other)
Determine if this ByteString equals another ByteString, ignoring case (ASCII).

Parameters:
  `other` - the other object
Returns:
  `true` if they are equal

### toInt

public int toInt(int start)
Get the unsigned `int` value of this string. If the value is greater than would fit in 32 bits, only the low 32 bits are returned. Parsing stops on the first non-digit character.

Parameters:
  `start` - the index to start at (must be less than or equal to length)
Returns:
  the value

### toInt

public int toInt()
Get the unsigned `int` value of this string. If the value is greater than would fit in 32 bits, only the low 32 bits are returned. Parsing stops on the first non-digit character.

Returns:
  the value

### toLong

public long toLong(int start)
Get the unsigned `long` value of this string. If the value is greater than would fit in 64 bits, only the low 64 bits are returned. Parsing stops on the first non-digit character.

Parameters:
  `start` - the index to start at (must be less than or equal to length)
Returns:
  the value

### toLong

public long toLong()
Get the unsigned `long` value of this string. If the value is greater than would fit in 64 bits, only the low 64 bits are returned. Parsing stops on the first non-digit character.

Returns:
  the value

### fromLong

public static ByteString fromLong(long val)
Get a string version of the given value.

Parameters:
  `val` - the value
Returns:
  the string

### fromInt

public static ByteString fromInt(int val)
Get a string version of the given value.

Parameters:
  `val` - the value
Returns:
  the string

### equalToString

public boolean equalToString(String str)
Determine whether this `ByteString` is equal (case-sensitively) to the given `String`.

Parameters:
  `str` - the string to check
Returns:
  `true` if the given string is equal (case-sensitively) to this instance, `false` otherwise

### equalToStringIgnoreCase

public boolean equalToStringIgnoreCase(String str)
Determine whether this `ByteString` is equal (case-insensitively) to the given `String`.

Parameters:
  `str` - the string to check
Returns:
  `true` if the given string is equal (case-insensitively) to this instance, `false` otherwise

### indexOf

public int indexOf(char c)
Get the index of the given character in this string.

Parameters:
  `c` - the character
Returns:
  the index, or -1 if it was not found

### indexOf

public int indexOf(char c, int start)
Get the index of the given character in this string.

Parameters:
  `c` - the character
Returns:
  the index, or -1 if it was not found

### lastIndexOf

public int lastIndexOf(char c)
Get the last index of the given character in this string.

Parameters:
  `c` - the character
Returns:
  the index, or -1 if it was not found

### lastIndexOf

public int lastIndexOf(char c, int start)
Get the last index of the given character in this string.

Parameters:
  `c` - the character
Returns:
  the index, or -1 if it was not found

### contains

public boolean contains(ByteString other)
Determine whether this string contains another string (case-sensitive).

Parameters:
  `other` - the string to test
Returns:
  `true` if this string contains `other`, `false` otherwise

### contains

public boolean contains(String other)
Determine whether this string contains another string (case-sensitive).

Parameters:
  `other` - the string to test
Returns:
  `true` if this string contains `other`, `false` otherwise

### containsIgnoreCase

public boolean containsIgnoreCase(ByteString other)
Determine whether this string contains another string (case-insensitive).

Parameters:
  `other` - the string to test
Returns:
  `true` if this string contains `other`, `false` otherwise

### containsIgnoreCase

public boolean containsIgnoreCase(String other)
Determine whether this string contains another string (case-sensitive).

Parameters:
  `other` - the string to test
Returns:
  `true` if this string contains `other`, `false` otherwise

### indexOf

public int indexOf(ByteString other)

### indexOf

public int indexOf(ByteString other, int start)

### indexOf

public int indexOf(String other)

### indexOf

public int indexOf(String other, int start)

### indexOfIgnoreCase

public int indexOfIgnoreCase(ByteString other)

### indexOfIgnoreCase

public int indexOfIgnoreCase(ByteString other, int start)

### indexOfIgnoreCase

public int indexOfIgnoreCase(String other)

### indexOfIgnoreCase

public int indexOfIgnoreCase(String other, int start)

### lastIndexOf

public int lastIndexOf(ByteString other)

### lastIndexOf

public int lastIndexOf(ByteString other, int start)

### lastIndexOf

public int lastIndexOf(String other)

### lastIndexOf

public int lastIndexOf(String other, int start)

### lastIndexOfIgnoreCase

public int lastIndexOfIgnoreCase(ByteString other)

### lastIndexOfIgnoreCase

public int lastIndexOfIgnoreCase(ByteString other, int start)

### lastIndexOfIgnoreCase

public int lastIndexOfIgnoreCase(String other)

### lastIndexOfIgnoreCase

public int lastIndexOfIgnoreCase(String other, int start)

### regionMatches

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

### regionMatches

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

### regionMatches

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

### startsWith

public boolean startsWith(ByteString prefix)

### startsWith

public boolean startsWith(String prefix)

### startsWith

public boolean startsWith(char prefix)

### startsWithIgnoreCase

public boolean startsWithIgnoreCase(ByteString prefix)

### startsWithIgnoreCase

public boolean startsWithIgnoreCase(String prefix)

### startsWithIgnoreCase

public boolean startsWithIgnoreCase(char prefix)

### endsWith

public boolean endsWith(ByteString suffix)

### endsWith

public boolean endsWith(String suffix)

### endsWith

public boolean endsWith(char suffix)

### endsWithIgnoreCase

public boolean endsWithIgnoreCase(ByteString suffix)

### endsWithIgnoreCase

public boolean endsWithIgnoreCase(String suffix)

### endsWithIgnoreCase

public boolean endsWithIgnoreCase(char suffix)

### concat

public ByteString concat(byte[] suffixBytes)

### concat

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

### concat

public ByteString concat(ByteString suffix)

### concat

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

### concat

public ByteString concat(String suffix)

### concat

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

### concat

public static ByteString concat(String prefix, ByteString suffix)

### concat

public static ByteString concat(String prefix, String suffix)

### charAt

public char charAt(int index)

Specified by:
  `charAt` in interface `CharSequence`

### subSequence

public ByteString subSequence(int start, int end)

Specified by:
  `subSequence` in interface `CharSequence`