public final class AsciiString extends Object implements CharSequence, Comparable<CharSequence>
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
ByteBuf
. It is often used in conjunction with TextHeaders
.Modifier and Type | Field and Description |
---|---|
static Comparator<AsciiString> |
CASE_INSENSITIVE_ORDER |
static Comparator<AsciiString> |
CASE_SENSITIVE_ORDER |
static Comparator<CharSequence> |
CHARSEQUENCE_CASE_INSENSITIVE_ORDER |
static Comparator<CharSequence> |
CHARSEQUENCE_CASE_SENSITIVE_ORDER |
static AsciiString |
EMPTY_STRING |
Constructor and Description |
---|
AsciiString(byte[] value) |
AsciiString(byte[] value,
boolean copy) |
AsciiString(byte[] value,
int start,
int length) |
AsciiString(byte[] value,
int start,
int length,
boolean copy) |
AsciiString(ByteBuffer value) |
AsciiString(ByteBuffer value,
int start,
int length) |
AsciiString(char[] value) |
AsciiString(char[] value,
int start,
int length) |
AsciiString(CharSequence value) |
AsciiString(CharSequence value,
int start,
int length) |
Modifier and Type | Method and Description |
---|---|
byte[] |
array() |
int |
arrayOffset() |
byte |
byteAt(int index) |
static int |
caseInsensitiveHashCode(CharSequence value)
Returns the case-insensitive hash code of the specified string.
|
char |
charAt(int index) |
int |
compareTo(CharSequence string)
Compares the specified string to this string using the ASCII values of the characters.
|
int |
compareToIgnoreCase(CharSequence string)
Compares the specified string to this string using the ASCII values of the characters, ignoring case differences.
|
AsciiString |
concat(CharSequence string)
Concatenates this string and the specified string.
|
boolean |
contains(CharSequence cs)
Determines if this
String contains the sequence of characters in the CharSequence passed. |
boolean |
contentEquals(CharSequence cs)
Compares a
CharSequence to this String to determine if their contents are equal. |
void |
copy(int srcIdx,
byte[] dst,
int dstIdx,
int length)
Copies the content of this string to a byte array.
|
void |
copy(int srcIdx,
ByteBuf dst,
int length)
Copies the content of this string to a
ByteBuf using ByteBuf.writeBytes(byte[], int, int) . |
void |
copy(int srcIdx,
ByteBuf dst,
int dstIdx,
int length)
Copies the content of this string to a
ByteBuf using ByteBuf.writeBytes(byte[], int, int) . |
void |
copy(int srcIdx,
char[] dst,
int dstIdx,
int length)
Copied the content of this string to a character array.
|
boolean |
endsWith(CharSequence suffix)
Compares the specified string to this string to determine if the specified string is a suffix.
|
static boolean |
equals(CharSequence a,
CharSequence b)
Returns
true if both CharSequence 's are equals. |
boolean |
equals(Object obj) |
boolean |
equalsIgnoreCase(CharSequence string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are
equal.
|
static boolean |
equalsIgnoreCase(CharSequence a,
CharSequence b)
Returns
true if both CharSequence 's are equals when ignore the case. |
static byte[] |
getBytes(CharSequence v,
Charset charset) |
int |
hashCode() |
int |
indexOf(CharSequence string)
Searches in this string for the first index of the specified string.
|
int |
indexOf(CharSequence subString,
int start)
Searches in this string for the index of the specified string.
|
int |
indexOf(int c)
Searches in this string for the first index of the specified character.
|
int |
indexOf(int c,
int start)
Searches in this string for the index of the specified character.
|
boolean |
isEmpty()
Answers if the size of this String is zero.
|
int |
lastIndexOf(CharSequence string)
Searches in this string for the last index of the specified string.
|
int |
lastIndexOf(CharSequence subString,
int start)
Searches in this string for the index of the specified string.
|
int |
lastIndexOf(int c)
Searches in this string for the last index of the specified character.
|
int |
lastIndexOf(int c,
int start)
Searches in this string for the index of the specified character.
|
int |
length() |
boolean |
matches(String expr)
Determines whether this string matches a given regular expression.
|
static AsciiString |
of(CharSequence string)
Returns an
AsciiString containing the given character sequence. |
double |
parseDouble() |
double |
parseDouble(int start,
int end) |
float |
parseFloat() |
float |
parseFloat(int start,
int end) |
int |
parseInt() |
int |
parseInt(int radix) |
int |
parseInt(int start,
int end) |
int |
parseInt(int start,
int end,
int radix) |
long |
parseLong() |
long |
parseLong(int radix) |
long |
parseLong(int start,
int end) |
long |
parseLong(int start,
int end,
int radix) |
short |
parseShort() |
short |
parseShort(int radix) |
short |
parseShort(int start,
int end) |
short |
parseShort(int start,
int end,
int radix) |
boolean |
regionMatches(boolean ignoreCase,
int thisStart,
CharSequence string,
int start,
int length)
Compares the specified string to this string and compares the specified range of characters to determine if they
are the same.
|
boolean |
regionMatches(int thisStart,
CharSequence string,
int start,
int length)
Compares the specified string to this string and compares the specified range of characters to determine if they
are the same.
|
AsciiString |
replace(char oldChar,
char newChar)
Copies this string replacing occurrences of the specified character with another character.
|
AsciiString[] |
split(char delim)
Splits the specified
String with the specified delimiter.. |
AsciiString[] |
split(String expr,
int max)
Splits this string using the supplied regular expression
expr . |
boolean |
startsWith(CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.
|
boolean |
startsWith(CharSequence prefix,
int start)
Compares the specified string to this string, starting at the specified offset, to determine if the specified
string is a prefix.
|
AsciiString |
subSequence(int start)
Copies a range of characters into a new string.
|
AsciiString |
subSequence(int start,
int end) |
byte[] |
toByteArray()
Converts this string to a byte array using the ASCII encoding.
|
byte[] |
toByteArray(int start,
int end)
Converts this string to a byte array using the ASCII encoding.
|
char[] |
toCharArray()
Copies the characters in this string to a character array.
|
char[] |
toCharArray(int start,
int end)
Copies the characters in this string to a character array.
|
AsciiString |
toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.
|
String |
toString() |
String |
toString(int start,
int end) |
AsciiString |
toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.
|
AsciiString |
trim()
Copies this string removing white space characters from the beginning and end of the string.
|
public static final AsciiString EMPTY_STRING
public static final Comparator<AsciiString> CASE_INSENSITIVE_ORDER
public static final Comparator<AsciiString> CASE_SENSITIVE_ORDER
public static final Comparator<CharSequence> CHARSEQUENCE_CASE_INSENSITIVE_ORDER
public static final Comparator<CharSequence> CHARSEQUENCE_CASE_SENSITIVE_ORDER
public AsciiString(byte[] value)
public AsciiString(byte[] value, boolean copy)
public AsciiString(byte[] value, int start, int length)
public AsciiString(byte[] value, int start, int length, boolean copy)
public AsciiString(char[] value)
public AsciiString(char[] value, int start, int length)
public AsciiString(CharSequence value)
public AsciiString(CharSequence value, int start, int length)
public AsciiString(ByteBuffer value)
public AsciiString(ByteBuffer value, int start, int length)
public static int caseInsensitiveHashCode(CharSequence value)
hashCode()
so that you can put both AsciiString
s and arbitrary
CharSequence
s into the same TextHeaders
.public static boolean equalsIgnoreCase(CharSequence a, CharSequence b)
true
if both CharSequence
's are equals when ignore the case. This only supports 8-bit
ASCII.public static boolean equals(CharSequence a, CharSequence b)
true
if both CharSequence
's are equals. This only supports 8-bit ASCII.public static byte[] getBytes(CharSequence v, Charset charset)
public static AsciiString of(CharSequence string)
AsciiString
containing the given character sequence. If the given string is already a
AsciiString
, just returns the same instance.public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public byte byteAt(int index)
public byte[] array()
public int arrayOffset()
public AsciiString subSequence(int start)
start
- the offset of the first character.IndexOutOfBoundsException
- if start < 0
or start > length()
.public AsciiString subSequence(int start, int end)
subSequence
in interface CharSequence
public String toString()
toString
in interface CharSequence
toString
in class Object
public String toString(int start, int end)
public int compareTo(CharSequence string)
compareTo
in interface Comparable<CharSequence>
string
- the string to compare.NullPointerException
- if string
is null
.public int compareToIgnoreCase(CharSequence string)
string
- the string to compare.NullPointerException
- if string
is null
.public AsciiString concat(CharSequence string)
string
- the string to concatenatepublic boolean endsWith(CharSequence suffix)
suffix
- the suffix to look for.true
if the specified string is a suffix of this string, false
otherwise.NullPointerException
- if suffix
is null
.public boolean equalsIgnoreCase(CharSequence string)
string
- the string to compare.true
if the specified string is equal to this string, false
otherwise.public byte[] toByteArray()
public byte[] toByteArray(int start, int end)
public char[] toCharArray()
public char[] toCharArray(int start, int end)
public void copy(int srcIdx, ByteBuf dst, int dstIdx, int length)
ByteBuf
using ByteBuf.writeBytes(byte[], int, int)
.srcIdx
- the starting offset of characters to copy.dst
- the destination byte array.dstIdx
- the starting offset in the destination byte array.length
- the number of characters to copy.public void copy(int srcIdx, ByteBuf dst, int length)
ByteBuf
using ByteBuf.writeBytes(byte[], int, int)
.srcIdx
- the starting offset of characters to copy.dst
- the destination byte array.length
- the number of characters to copy.public void copy(int srcIdx, byte[] dst, int dstIdx, int length)
srcIdx
- the starting offset of characters to copy.dst
- the destination byte array.dstIdx
- the starting offset in the destination byte array.length
- the number of characters to copy.public void copy(int srcIdx, char[] dst, int dstIdx, int length)
srcIdx
- the starting offset of characters to copy.dst
- the destination character array.dstIdx
- the starting offset in the destination byte array.length
- the number of characters to copy.public int indexOf(int c)
c
- the character to find.public int indexOf(int c, int start)
c
- the character to find.start
- the starting offset.public int indexOf(CharSequence string)
string
- the string to find.NullPointerException
- if string
is null
.public int indexOf(CharSequence subString, int start)
subString
- the string to find.start
- the starting offset.NullPointerException
- if subString
is null
.public int lastIndexOf(int c)
c
- the character to find.public int lastIndexOf(int c, int start)
c
- the character to find.start
- the starting offset.public int lastIndexOf(CharSequence string)
string
- the string to find.NullPointerException
- if string
is null
.public int lastIndexOf(CharSequence subString, int start)
subString
- the string to find.start
- the starting offset.NullPointerException
- if subString
is null
.public boolean isEmpty()
public boolean regionMatches(int thisStart, CharSequence string, int start, int length)
thisStart
- the starting offset in this string.string
- the string to compare.start
- the starting offset in the specified string.length
- the number of characters to compare.true
if the ranges of characters are equal, false
otherwiseNullPointerException
- if string
is null
.public boolean regionMatches(boolean ignoreCase, int thisStart, CharSequence string, int start, int length)
ignoreCase
- specifies if case should be ignored.thisStart
- the starting offset in this string.string
- the string to compare.start
- the starting offset in the specified string.length
- the number of characters to compare.true
if the ranges of characters are equal, false
otherwise.NullPointerException
- if string
is null
.public AsciiString replace(char oldChar, char newChar)
oldChar
- the character to replace.newChar
- the replacement character.public boolean startsWith(CharSequence prefix)
prefix
- the string to look for.true
if the specified string is a prefix of this string, false
otherwiseNullPointerException
- if prefix
is null
.public boolean startsWith(CharSequence prefix, int start)
prefix
- the string to look for.start
- the starting offset.true
if the specified string occurs in this string at the specified offset, false
otherwise.NullPointerException
- if prefix
is null
.public AsciiString toLowerCase()
public AsciiString toUpperCase()
public AsciiString trim()
<= \\u0020
removed from the beginning and the end.public boolean contentEquals(CharSequence cs)
CharSequence
to this String
to determine if their contents are equal.cs
- the character sequence to compare to.true
if equal, otherwise false
public boolean matches(String expr)
expr
- the regular expression to be matched.true
if the expression matches, otherwise false
.PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.NullPointerException
- if expr
is null
.public AsciiString[] split(String expr, int max)
expr
. The parameter max
controls the
behavior how many times the pattern is applied to the string.expr
- the regular expression used to divide the string.max
- the number of entries in the resulting array.NullPointerException
- if expr
is null
.PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.Pattern.split(CharSequence, int)
public AsciiString[] split(char delim)
String
with the specified delimiter..public boolean contains(CharSequence cs)
String
contains the sequence of characters in the CharSequence
passed.cs
- the character sequence to search for.true
if the sequence of characters are contained in this string, otherwise false
.public int parseInt()
public int parseInt(int radix)
public int parseInt(int start, int end)
public int parseInt(int start, int end, int radix)
public long parseLong()
public long parseLong(int radix)
public long parseLong(int start, int end)
public long parseLong(int start, int end, int radix)
public short parseShort()
public short parseShort(int radix)
public short parseShort(int start, int end)
public short parseShort(int start, int end, int radix)
public float parseFloat()
public float parseFloat(int start, int end)
public double parseDouble()
public double parseDouble(int start, int end)
Copyright © 2008–2015 The Netty Project. All rights reserved.