Top Description Inners Fields Constructors Methods
io.netty.util

public final Class AsciiString

extends Object
implements CharSequence, Comparable<CharSequence>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.lang.CharSequence
Imports
io.netty.util.internal.EmptyArrays, .InternalThreadLocalMap, .ObjectUtil, .PlatformDependent, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, java.util.Arrays, .Collection, .List, java.util.regex.Pattern, .PatternSyntaxException

A string which has been encoded into a character encoding whose character always takes a single byte, similarly to ASCII. It internally keeps its content in a byte array unlike String, which uses a character array, for reduced memory footprint and faster data transfer from/to byte-based data structures such as a byte array and ByteBuffer. It is often used in conjunction with Headers that require a CharSequence.

This class was designed to provide an immutable array of bytes, and caches some internal state based upon the value of this array. However underlying access to this byte array is provided via not copying the array on construction or array(). If any changes are made to the underlying byte array it is the user's responsibility to call arrayChanged() so the state of this class can be reset.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static interface
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final HashingStrategy<CharSequence>
public static final HashingStrategy<CharSequence>
public static final AsciiString
private int
hash

The hash code is cached after it is first computed.

public static final int
private final int
length

Length in bytes for value that we care about.

private static final char
private final int
offset

Offset into value that all operations should use when acting upon value.

private String
string

Used to cache the toString() value.

private final byte[]
value

If this value is modified outside the constructor then call arrayChanged().

Constructor Summary

AccessConstructor and Description
public
AsciiString(byte[] value)

Initialize this byte string based upon a byte array.

public
AsciiString(byte[] value, boolean copy)

Initialize this byte string based upon a byte array.

public
AsciiString(byte[] value, int start, int length, boolean
true then a copy of the memory will be made. false the underlying memory will be shared.
copy
)

Construct a new instance from a byte[] array.

public
AsciiString(ByteBuffer value)

Create a copy of the underlying storage from value.

public
AsciiString(ByteBuffer value, boolean copy)

Initialize an instance based upon the underlying storage from value.

public
AsciiString(ByteBuffer value, int start, int length, boolean copy)

Initialize an AsciiString based upon the underlying storage from value.

public
AsciiString(char[] value)

Create a copy of value into this instance assuming ASCII encoding.

public
AsciiString(char[] value, int start, int length)

Create a copy of value into this instance assuming ASCII encoding.

public
AsciiString(char[] value, Charset charset)

Create a copy of value into this instance using the encoding type of charset.

public
AsciiString(char[] value, Charset charset, int start, int length)

Create a copy of value into a this instance using the encoding type of charset.

public
AsciiString(CharSequence value)

Create a copy of value into this instance assuming ASCII encoding.

public
AsciiString(CharSequence value, int start, int length)

Create a copy of value into this instance assuming ASCII encoding.

public
AsciiString(CharSequence value, Charset charset)

Create a copy of value into this instance using the encoding type of charset.

public
AsciiString(CharSequence value, Charset charset, int start, int length)

Create a copy of value into this instance using the encoding type of charset.

Method Summary

Modifier and TypeMethod and Description
public byte[]
array()

This gives direct access to the underlying storage array.

public void
arrayChanged()

During normal use cases the AsciiString should be immutable, but if the underlying array is shared, and changes then this needs to be called.

public int
arrayOffset()

The offset into array() for which data for this ByteString begins.

public static char
b2c(byte b)

public byte
byteAt(int index)

public static byte
c2b(char c)

private static byte
c2b0(char c)

public static AsciiString
cached(String string)

Returns an AsciiString containing the given string and retains/caches the input string for later use in toString().

public char
charAt(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:

0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
compareTo
(CharSequence
the string to compare.
string
)

Implements java.lang.Comparable.compareTo.

Compares the specified string to this string using the ASCII values of the characters.
public AsciiString

Returns:

a new string which is the concatenation of this string and the specified string.
concat
(CharSequence
the string to concatenate
string
)

Concatenates this string and the specified string.

public boolean

Returns:

true if the sequence of characters are contained in this string, otherwise false.
contains
(CharSequence
the character sequence to search for.
cs
)

Determines if this String contains the sequence of characters in the CharSequence passed.

public static boolean
contains(CharSequence a, CharSequence b)

Determine if a contains b in a case sensitive manner.

private static boolean
public static boolean

Returns:

true if a contains all of the values in b using contentEqualsIgnoreCase(CharSequence, CharSequence) to compare values. false otherwise.
containsAllContentEqualsIgnoreCase
(Collection<CharSequence>
The collection under test.
a
,
Collection<CharSequence>
The values to test for.
b
)

Determine if a contains all of the values in b using contentEqualsIgnoreCase(CharSequence, CharSequence) to compare values.

public static boolean

Returns:

true if collection contains value according to contentEqualsIgnoreCase(CharSequence, CharSequence). false otherwise.
containsContentEqualsIgnoreCase
(Collection<CharSequence>
The collection to look for and equivalent element as value.
collection
,
CharSequence
The value to look for in collection.
value
)

Determine if collection contains value and using contentEqualsIgnoreCase(CharSequence, CharSequence) to compare values.

public static boolean
containsIgnoreCase(CharSequence a, CharSequence b)

Determine if a contains b in a case insensitive manner.

public boolean

Returns:

true if equal, otherwise false
contentEquals
(CharSequence
the character sequence to compare to.
a
)

Compares a CharSequence to this String to determine if their contents are equal.

public static boolean
contentEquals(CharSequence a, CharSequence b)

Returns true if the content of both CharSequence's are equals.

public boolean

Returns:

true if the specified string is equal to this string, false otherwise.
contentEqualsIgnoreCase
(CharSequence
the string to compare.
string
)

Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.

public static boolean
contentEqualsIgnoreCase(CharSequence a, CharSequence b)

Returns true if both CharSequence's are equals when ignore the case.

public void
copy(int
the starting offset of characters to copy.
srcIdx
,
byte[]
the destination byte array.
dst
,
int
the starting offset in the destination byte array.
dstIdx
,
int
the number of characters to copy.
length
)

Copies the content of this string to a byte array.

public void
copy(int
the starting offset of characters to copy.
srcIdx
,
char[]
the destination character array.
dst
,
int
the starting offset in the destination byte array.
dstIdx
,
int
the number of characters to copy.
length
)

Copied the content of this string to a character array.

public boolean

Returns:

true if the specified string is a suffix of this string, false otherwise.
endsWith
(CharSequence
the suffix to look for.
suffix
)

Compares the specified string to this string to determine if the specified string is a suffix.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private static boolean
equalsIgnoreCase(byte a, byte b)

private static boolean
equalsIgnoreCase(char a, char b)

public int

Returns:

-1 if the processor iterated to or beyond the end of the readable bytes. The last-visited index If the ByteProcessor#process(byte) returned false.
forEachByte
(ByteProcessor visitor)

Iterates over the readable bytes of this buffer with the specified processor in ascending order.

public int

Returns:

-1 if the processor iterated to or beyond the end of the specified area. The last-visited index If the ByteProcessor#process(byte) returned false.
forEachByte
(int index, int length, ByteProcessor visitor)

Iterates over the specified area of this buffer with the specified processor in ascending order.

private int
forEachByte0(int index, int length, ByteProcessor visitor)

public int

Returns:

-1 if the processor iterated to or beyond the beginning of the readable bytes. The last-visited index If the ByteProcessor#process(byte) returned false.
forEachByteDesc
(ByteProcessor visitor)

Iterates over the readable bytes of this buffer with the specified processor in descending order.

public int

Returns:

-1 if the processor iterated to or beyond the beginning of the specified area. The last-visited index If the ByteProcessor#process(byte) returned false.
forEachByteDesc
(int index, int length, ByteProcessor visitor)

Iterates over the specified area of this buffer with the specified processor in descending order.

private int
forEachByteDesc0(int index, int length, ByteProcessor visitor)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public static int
hashCode(CharSequence value)

Returns the case-insensitive hash code of the specified string.

public int

Returns:

the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
indexOf
(CharSequence
the string to find.
string
)

Searches in this string for the first index of the specified string.

public int

Returns:

the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
indexOf
(CharSequence
the string to find.
subString
,
int
the starting offset.
start
)

Searches in this string for the index of the specified string.

public int

Returns:

the index of the first occurrence of the specified char ch in this string, -1 if found no occurrence.
indexOf
(char
the char to find.
ch
,
int
the starting offset.
start
)

Searches in this string for the index of the specified char ch.

public static int

Returns:

the index where the search char was found, -1 if char searchChar is not found or cs == null
indexOf
(final CharSequence
the CharSequence to be processed, not null
cs
,
final char
the char to be searched for
searchChar
,
int
the start index, negative starts at the string start
start
)

Finds the first index in the CharSequence that matches the specified character.

public static int

Returns:

the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input
indexOfIgnoreCase
(final CharSequence
the CharSequence to check, may be null
str
,
final CharSequence
the CharSequence to find, may be null
searchStr
,
int
the start position, negative treated as zero
startPos
)

Case in-sensitive find of the first index within a CharSequence from the specified position.

public static int

Returns:

the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input
indexOfIgnoreCaseAscii
(final CharSequence
the CharSequence to check, may be null
str
,
final CharSequence
the CharSequence to find, may be null
searchStr
,
int
the start position, negative treated as zero
startPos
)

Case in-sensitive find of the first index within a CharSequence from the specified position.

public boolean
isEmpty()

Overrides default java.lang.CharSequence.isEmpty.

Determine if this instance has 0 length.
public boolean
isEntireArrayUsed()

Determine if the storage represented by array() is entirely used.

private static boolean
isLowerCase(byte value)

public static boolean
isUpperCase(byte value)

public static boolean
isUpperCase(char value)

public int

Returns:

the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
lastIndexOf
(CharSequence
the string to find.
string
)

Searches in this string for the last index of the specified string.

public int

Returns:

the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
lastIndexOf
(CharSequence
the string to find.
subString
,
int
the starting offset.
start
)

Searches in this string for the index of the specified string.

public int
length()

Implements java.lang.CharSequence.length.

The length in bytes of this instance.
public boolean

Returns:

true if the expression matches, otherwise false.
matches
(String
the regular expression to be matched.
expr
)

Determines whether this string matches a given regular expression.

public static AsciiString
of(CharSequence string)

Returns an AsciiString containing the given character sequence.

public boolean
public char
public char
parseChar(int start)

public double
public double
parseDouble(int start, int end)

public float
public float
parseFloat(int start, int end)

public int
public int
parseInt(int radix)

public int
parseInt(int start, int end)

public int
parseInt(int start, int end, int radix)

private int
parseInt(int start, int end, int radix, boolean negative)

public long
public long
parseLong(int radix)

public long
parseLong(int start, int end)

public long
parseLong(int start, int end, int radix)

private long
parseLong(int start, int end, int radix, boolean negative)

public short
public short
parseShort(int radix)

public short
parseShort(int start, int end)

public short
parseShort(int start, int end, int radix)

public boolean

Returns:

true if the ranges of characters are equal, false otherwise
regionMatches
(int
the starting offset in this string.
thisStart
,
CharSequence
the string to compare.
string
,
int
the starting offset in the specified string.
start
,
int
the number of characters to compare.
length
)

Compares the specified string to this string and compares the specified range of characters to determine if they are the same.

public boolean

Returns:

true if the ranges of characters are equal, false otherwise.
regionMatches
(boolean
specifies if case should be ignored.
ignoreCase
,
int
the starting offset in this string.
thisStart
,
CharSequence
the string to compare.
string
,
int
the starting offset in the specified string.
start
,
int
the number of characters to compare.
length
)

Compares the specified string to this string and compares the specified range of characters to determine if they are the same.

public static boolean

Returns:

true if the ranges of characters are equal, false otherwise.
regionMatches
(final CharSequence
the CharSequence to be processed
cs
,
final boolean
specifies if case should be ignored.
ignoreCase
,
final int
the starting offset in the cs CharSequence
csStart
,
final CharSequence
the CharSequence to compare.
string
,
final int
the starting offset in the specified string.
start
,
final int
the number of characters to compare.
length
)

This methods make regionMatches operation correctly for any chars in strings

public static boolean

Returns:

true if the ranges of characters are equal, false otherwise.
regionMatchesAscii
(final CharSequence
the CharSequence to be processed
cs
,
final boolean
specifies if case should be ignored.
ignoreCase
,
final int
the starting offset in the cs CharSequence
csStart
,
final CharSequence
the CharSequence to compare.
string
,
final int
the starting offset in the specified string.
start
,
final int
the number of characters to compare.
length
)

This is optimized version of regionMatches for string with ASCII chars only

private static boolean
regionMatchesCharSequences(final CharSequence cs, final int csStart, final CharSequence string, final int start, final int length, AsciiString.CharEqualityComparator charEqualityComparator)

public AsciiString

Returns:

a new string with occurrences of oldChar replaced by newChar.
replace
(char
the character to replace.
oldChar
,
char
the replacement character.
newChar
)

Copies this string replacing occurrences of the specified character with another character.

public AsciiString[]

Returns:

an array of Strings created by separating the string along matches of the regular expression.
split
(String
the regular expression used to divide the string.
expr
,
int
the number of entries in the resulting array.
max
)

Splits this string using the supplied regular expression expr.

public AsciiString[]
split(char delim)

Splits the specified String with the specified delimiter..

public boolean

Returns:

true if the specified string is a prefix of this string, false otherwise
startsWith
(CharSequence
the string to look for.
prefix
)

Compares the specified string to this string to determine if the specified string is a prefix.

public boolean

Returns:

true if the specified string occurs in this string at the specified offset, false otherwise.
startsWith
(CharSequence
the string to look for.
prefix
,
int
the starting offset.
start
)

Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.

public AsciiString

Returns:

a new string containing the characters from start to the end of the string.
subSequence
(int
the offset of the first character (inclusive).
start
)

Copies a range of characters into a new string.

public AsciiString

Returns:

a new string containing the characters from start to the end of the string.
subSequence
(int
the offset of the first character (inclusive).
start
,
int
The index to stop at (exclusive).
end
)

Implements java.lang.CharSequence.subSequence.

Copies a range of characters into a new string.
public AsciiString

Returns:

a new string containing the characters from start to the end of the string.
subSequence
(int
the offset of the first character (inclusive).
start
,
int
The index to stop at (exclusive).
end
,
boolean
If true then a copy of the underlying storage will be made. If false then the underlying storage will be shared.
copy
)

Either copy or share a subset of underlying sub-sequence of bytes.

private static AsciiString[]
public byte[]
toByteArray()

Converts this string to a byte array.

public byte[]
toByteArray(int start, int end)

Converts a subset of this string to a byte array.

public char[]

Returns:

a character array containing the characters of this string.
toCharArray
()

Copies the characters in this string to a character array.

public char[]

Returns:

a character array containing the characters of this string.
toCharArray
(int start, int end)

Copies the characters in this string to a character array.

public AsciiString

Returns:

a new string containing the lowercase characters equivalent to the characters in this string.
toLowerCase
()

Converts the characters in this string to lowercase, using the default Locale.

private static byte
toLowerCase(byte b)

public static char

Returns:

lowercase ASCII character equivalent
toLowerCase
(char c)

If the character is uppercase - converts the character to lowercase, otherwise returns the character as it is.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Translates the entire byte string to a String.
public String
toString(int start)

Translates the entire byte string to a String using the charset encoding.

public String
toString(int start, int end)

Translates the [start, end) range of this byte string to a String.

public AsciiString

Returns:

a new string containing the uppercase characters equivalent to the characters in this string.
toUpperCase
()

Converts the characters in this string to uppercase, using the default Locale.

private static byte
toUpperCase(byte b)

public static CharSequence

Returns:

a new string with characters <= \\u0020 removed from the beginning and the end.
trim
(CharSequence
The CharSequence to trim.
c
)

Copies this string removing white space characters from the beginning and end of the string, and tries not to copy if possible.

public AsciiString

Returns:

a new string with characters <= \\u0020 removed from the beginning and the end.
trim
()

Duplicates this string removing white space characters from the beginning and end of the string, without copying.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait