Class ByteBufAsciiString
- java.lang.Object
-
- com.linkedin.alpini.base.misc.ByteBufAsciiString
-
- All Implemented Interfaces:
io.netty.util.ReferenceCounted
,java.lang.CharSequence
,java.lang.Comparable<java.lang.CharSequence>
public final class ByteBufAsciiString extends java.lang.Object implements java.lang.CharSequence, io.netty.util.ReferenceCounted, java.lang.Comparable<java.lang.CharSequence>
A string implementation, similar to AsciiString, which is backed by a ByteBuf instead of a byte[] array.
-
-
Field Summary
Fields Modifier and Type Field Description static ByteBufAsciiString
EMPTY_STRING
static int
INDEX_NOT_FOUND
-
Constructor Summary
Constructors Constructor Description ByteBufAsciiString(byte[] bytes, int offset, int length, boolean copy)
ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, byte[] bytes)
ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, char[] value)
Create a copy ofvalue
into this instance assuming ASCII encoding.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, char[] value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, char[] value, java.nio.charset.Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, char[] value, java.nio.charset.Charset charset, int start, int length)
Create a copy ofvalue
into a this instance using the encoding type ofcharset
.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, java.lang.CharSequence charSequence)
ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, java.lang.CharSequence value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, java.lang.CharSequence value, java.nio.charset.Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.ByteBufAsciiString(io.netty.buffer.ByteBufAllocator alloc, java.lang.CharSequence value, java.nio.charset.Charset charset, int start, int length)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static char
b2c(byte b)
byte
byteAt(int index)
static byte
c2b(char c)
static byte
c2b0(char c)
char
charAt(int index)
int
compareTo(java.lang.CharSequence string)
Compares the specified string to this string using the ASCII values of the characters.ByteBufAsciiString
concat(java.lang.CharSequence... strings)
Concatenates this string and the specified string.boolean
contains(java.lang.CharSequence cs)
Determines if thisString
contains the sequence of characters in theCharSequence
passed.static boolean
contains(java.lang.CharSequence a, java.lang.CharSequence b)
Determine ifa
containsb
in a case sensitive manner.static boolean
containsAllContentEqualsIgnoreCase(java.util.Collection<java.lang.CharSequence> a, java.util.Collection<java.lang.CharSequence> b)
Determine ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.static boolean
containsContentEqualsIgnoreCase(java.util.Collection<java.lang.CharSequence> collection, java.lang.CharSequence value)
Determine ifcollection
containsvalue
and usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.static boolean
containsIgnoreCase(java.lang.CharSequence a, java.lang.CharSequence b)
Determine ifa
containsb
in a case insensitive manner.boolean
contentEquals(java.lang.CharSequence a)
Compares aCharSequence
to thisString
to determine if their contents are equal.static boolean
contentEquals(java.lang.CharSequence a, java.lang.CharSequence b)
Returnstrue
if the content of bothCharSequence
's are equals.boolean
contentEqualsIgnoreCase(java.lang.CharSequence string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.static boolean
contentEqualsIgnoreCase(java.lang.CharSequence a, java.lang.CharSequence b)
Returnstrue
if bothCharSequence
's are equals when ignore the case.static ByteBufAsciiString
copy(io.netty.buffer.ByteBuf byteBuf, int index, int length)
boolean
endsWith(java.lang.CharSequence suffix)
Compares the specified string to this string to determine if the specified string is a suffix.boolean
equals(java.lang.Object obj)
int
forEachByte(int index, int length, io.netty.util.ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in ascending order.int
forEachByte(io.netty.util.ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.int
forEachByteDesc(int index, int length, io.netty.util.ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in descending order.int
forEachByteDesc(io.netty.util.ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in descending order.int
hashCode()
static int
hashCode(java.lang.CharSequence value)
Returns the case-insensitive hash code of the specified string.int
indexOf(char ch, int start)
Searches in this string for the index of the specified charch
.int
indexOf(java.lang.CharSequence string)
Searches in this string for the first index of the specified string.static int
indexOf(java.lang.CharSequence cs, char searchChar, int start)
Finds the first index in theCharSequence
that matches the specified character.int
indexOf(java.lang.CharSequence subString, int start)
Searches in this string for the index of the specified string.static int
indexOfIgnoreCase(java.lang.CharSequence str, java.lang.CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.static int
indexOfIgnoreCaseAscii(java.lang.CharSequence str, java.lang.CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.boolean
isEmpty()
Determine if this instance has 0 length.static boolean
isUpperCase(byte value)
static boolean
isUpperCase(char value)
int
lastIndexOf(java.lang.CharSequence string)
Searches in this string for the last index of the specified string.int
lastIndexOf(java.lang.CharSequence subString, int start)
Searches in this string for the index of the specified string.int
length()
boolean
matches(java.lang.String expr)
Determines whether this string matches a given regular expression.static ByteBufAsciiString
read(io.netty.buffer.ByteBuf byteBuf, int length)
static ByteBufAsciiString
readBytes(io.netty.buffer.ByteBuf byteBuf, int length)
static ByteBufAsciiString
readRetainedSlice(io.netty.buffer.ByteBuf byteBuf, int length)
int
refCnt()
boolean
regionMatches(boolean ignoreCase, int thisStart, java.lang.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, java.lang.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.static boolean
regionMatches(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)
This methods make regionMatches operation correctly for any chars in stringsstatic boolean
regionMatchesAscii(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)
This is optimized version of regionMatches for string with ASCII chars onlyboolean
release()
boolean
release(int decrement)
ByteBufAsciiString
replace(char oldChar, char newChar)
Copies this string replacing occurrences of the specified character with another character.ByteBufAsciiString
retain()
ByteBufAsciiString
retain(int increment)
static ByteBufAsciiString
slice(io.netty.buffer.ByteBuf byteBuf, int index, int length)
ByteBufAsciiString[]
split(char delim)
Splits the specifiedString
with the specified delimiter..ByteBufAsciiString[]
split(java.lang.String expr, int max)
Splits this string using the supplied regular expressionexpr
.ByteBufAsciiString[]
split(java.util.regex.Pattern pattern)
ByteBufAsciiString[]
split(java.util.regex.Pattern pattern, int limit)
boolean
startsWith(java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.boolean
startsWith(java.lang.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.static boolean
startsWith(java.lang.CharSequence string, java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.static boolean
startsWith(java.lang.CharSequence string, java.lang.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.static boolean
startsWithIgnoreCase(java.lang.CharSequence string, java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.static boolean
startsWithIgnoreCase(java.lang.CharSequence string, java.lang.CharSequence prefix, int start)
ByteBufAsciiString
subSequence(int start)
Copies a range of characters into a new string.ByteBufAsciiString
subSequence(int start, int end)
Copies a range of characters into a new string.ByteBufAsciiString
subSequence(int start, int end, boolean copy)
Either copy or share a subset of underlying sub-sequence of bytes.io.netty.util.AsciiString
toAsciiString()
byte[]
toByteArray()
Converts this string to a byte array.byte[]
toByteArray(int start, int end)
Converts a subset of this string to a byte array.ByteBufAsciiString
toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.java.lang.String
toString()
Translates the entire byte string to aString
.java.lang.String
toString(int start)
Translates the entire byte string to aString
using thecharset
encoding.java.lang.String
toString(int start, int end)
Translates the [start
,end
) range of this byte string to aString
.io.netty.util.ReferenceCounted
touch()
io.netty.util.ReferenceCounted
touch(java.lang.Object hint)
ByteBufAsciiString
toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.ByteBufAsciiString
trim()
Duplicates this string removing white space characters from the beginning and end of the string, without copying.static java.lang.CharSequence
trim(java.lang.CharSequence c)
Copies this string removing white space characters from the beginning and end of the string, and tries not to copy if possible.
-
-
-
Field Detail
-
EMPTY_STRING
public static final ByteBufAsciiString EMPTY_STRING
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull byte[] bytes)
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull java.lang.CharSequence charSequence)
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull java.lang.CharSequence value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding. The copy will start at indexstart
and copylength
bytes.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull char[] value)
Create a copy ofvalue
into this instance assuming ASCII encoding.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull char[] value, int start, int length)
Create a copy ofvalue
into this instance assuming ASCII encoding. The copy will start at indexstart
and copylength
bytes.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull char[] value, java.nio.charset.Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull char[] value, java.nio.charset.Charset charset, int start, int length)
Create a copy ofvalue
into a this instance using the encoding type ofcharset
. The copy will start at indexstart
and copylength
bytes.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull java.lang.CharSequence value, java.nio.charset.Charset charset)
Create a copy ofvalue
into this instance using the encoding type ofcharset
.
-
ByteBufAsciiString
public ByteBufAsciiString(@Nonnull io.netty.buffer.ByteBufAllocator alloc, @Nonnull java.lang.CharSequence value, java.nio.charset.Charset charset, int start, int length)
Create a copy ofvalue
into this instance using the encoding type ofcharset
. The copy will start at indexstart
and copylength
bytes.
-
ByteBufAsciiString
public ByteBufAsciiString(byte[] bytes, int offset, int length, boolean copy)
-
-
Method Detail
-
readBytes
public static ByteBufAsciiString readBytes(io.netty.buffer.ByteBuf byteBuf, int length)
-
readRetainedSlice
public static ByteBufAsciiString readRetainedSlice(io.netty.buffer.ByteBuf byteBuf, int length)
-
read
public static ByteBufAsciiString read(io.netty.buffer.ByteBuf byteBuf, int length)
-
copy
public static ByteBufAsciiString copy(io.netty.buffer.ByteBuf byteBuf, int index, int length)
-
slice
public static ByteBufAsciiString slice(io.netty.buffer.ByteBuf byteBuf, int index, int length)
-
forEachByte
public int forEachByte(io.netty.util.ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in ascending order.- Returns:
-1
if the processor iterated to or beyond the end of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByte
public int forEachByte(int index, int length, io.netty.util.ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in ascending order. (i.e.index
,(index + 1)
, ..(index + length - 1)
).- Returns:
-1
if the processor iterated to or beyond the end of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
public int forEachByteDesc(io.netty.util.ByteProcessor visitor)
Iterates over the readable bytes of this buffer with the specifiedprocessor
in descending order.- Returns:
-1
if the processor iterated to or beyond the beginning of the readable bytes. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
forEachByteDesc
public int forEachByteDesc(int index, int length, io.netty.util.ByteProcessor visitor)
Iterates over the specified area of this buffer with the specifiedprocessor
in descending order. (i.e.(index + length - 1)
,(index + length - 2)
, ...index
).- Returns:
-1
if the processor iterated to or beyond the beginning of the specified area. The last-visited index If theByteProcessor.process(byte)
returnedfalse
.
-
isEmpty
public boolean isEmpty()
Determine if this instance has 0 length.
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
byteAt
public byte byteAt(int index)
-
toByteArray
public byte[] toByteArray()
Converts this string to a byte array.
-
toByteArray
public byte[] toByteArray(int start, int end)
Converts a subset of this string to a byte array. The subset is defined by the range [start
,end
).
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
contains
public boolean contains(java.lang.CharSequence cs)
Determines if thisString
contains the sequence of characters in theCharSequence
passed.- Parameters:
cs
- the character sequence to search for.- Returns:
true
if the sequence of characters are contained in this string, otherwisefalse
.
-
compareTo
public int compareTo(@Nonnull java.lang.CharSequence string)
Compares the specified string to this string using the ASCII values of the characters. Returns 0 if the strings contain the same characters in the same order. Returns a negative integer if the first non-equal character in this string has an ASCII value which is less than the ASCII value of the character at the same position in the specified string, or if this string is a prefix of the specified string. Returns a positive integer if the first non-equal character in this string has a ASCII value which is greater than the ASCII value of the character at the same position in the specified string, or if the specified string is a prefix of this string.- Specified by:
compareTo
in interfacejava.lang.Comparable<java.lang.CharSequence>
- Parameters:
string
- the string to compare.- 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.
- Throws:
java.lang.NullPointerException
- ifstring
isnull
.
-
concat
public ByteBufAsciiString concat(java.lang.CharSequence... strings)
Concatenates this string and the specified string.- Parameters:
strings
- the strings to concatenate- Returns:
- a new string which is the concatenation of this string and the specified string.
-
endsWith
public boolean endsWith(java.lang.CharSequence suffix)
Compares the specified string to this string to determine if the specified string is a suffix.- Parameters:
suffix
- the suffix to look for.- Returns:
true
if the specified string is a suffix of this string,false
otherwise.- Throws:
java.lang.NullPointerException
- ifsuffix
isnull
.
-
contentEqualsIgnoreCase
public boolean contentEqualsIgnoreCase(java.lang.CharSequence string)
Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.- Parameters:
string
- the string to compare.- Returns:
true
if the specified string is equal to this string,false
otherwise.
-
subSequence
public ByteBufAsciiString subSequence(int start)
Copies a range of characters into a new string.- Parameters:
start
- the offset of the first character (inclusive).- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
java.lang.IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
subSequence
public ByteBufAsciiString subSequence(int start, int end)
Copies a range of characters into a new string.- Specified by:
subSequence
in interfacejava.lang.CharSequence
- Parameters:
start
- the offset of the first character (inclusive).end
- The index to stop at (exclusive).- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
java.lang.IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
subSequence
public ByteBufAsciiString subSequence(int start, int end, boolean copy)
Either copy or share a subset of underlying sub-sequence of bytes.- Parameters:
start
- the offset of the first character (inclusive).end
- The index to stop at (exclusive).copy
- Iftrue
then a copy of the underlying storage will be made. Iffalse
then the underlying storage will be shared.- Returns:
- a new string containing the characters from start to the end of the string.
- Throws:
java.lang.IndexOutOfBoundsException
- ifstart < 0
orstart > length()
.
-
indexOf
public int indexOf(java.lang.CharSequence string)
Searches in this string for the first index of the specified string. The search for the string starts at the beginning and moves towards the end of this string.- Parameters:
string
- the string to find.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
java.lang.NullPointerException
- ifstring
isnull
.
-
indexOf
public int indexOf(java.lang.CharSequence subString, int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the end of this string.- Parameters:
subString
- the string to find.start
- the starting offset.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
java.lang.NullPointerException
- ifsubString
isnull
.
-
indexOf
public int indexOf(char ch, int start)
Searches in this string for the index of the specified charch
. The search for the char starts at the specified offsetstart
and moves towards the end of this string.- Parameters:
ch
- the char to find.start
- the starting offset.- Returns:
- the index of the first occurrence of the specified char
ch
in this string, -1 if found no occurrence.
-
lastIndexOf
public int lastIndexOf(java.lang.CharSequence string)
Searches in this string for the last index of the specified string. The search for the string starts at the end and moves towards the beginning of this string.- Parameters:
string
- the string to find.- Returns:
- the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
- Throws:
java.lang.NullPointerException
- ifstring
isnull
.
-
lastIndexOf
public int lastIndexOf(java.lang.CharSequence subString, int start)
Searches in this string for the index of the specified string. The search for the string starts at the specified offset and moves towards the beginning of this string.- Parameters:
subString
- the string to find.start
- the starting offset.- Returns:
- the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
- Throws:
java.lang.NullPointerException
- ifsubString
isnull
.
-
regionMatches
public boolean regionMatches(int thisStart, java.lang.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.- Parameters:
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.- Returns:
true
if the ranges of characters are equal,false
otherwise- Throws:
java.lang.NullPointerException
- ifstring
isnull
.
-
regionMatches
public boolean regionMatches(boolean ignoreCase, int thisStart, java.lang.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. When ignoreCase is true, the case of the characters is ignored during the comparison.- Parameters:
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.- Returns:
true
if the ranges of characters are equal,false
otherwise.- Throws:
java.lang.NullPointerException
- ifstring
isnull
.
-
replace
public ByteBufAsciiString replace(char oldChar, char newChar)
Copies this string replacing occurrences of the specified character with another character.- Parameters:
oldChar
- the character to replace.newChar
- the replacement character.- Returns:
- a new string with occurrences of oldChar replaced by newChar.
-
startsWith
public boolean startsWith(java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.- Parameters:
prefix
- the string to look for.- Returns:
true
if the specified string is a prefix of this string,false
otherwise- Throws:
java.lang.NullPointerException
- ifprefix
isnull
.
-
startsWith
public static boolean startsWith(java.lang.CharSequence string, java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.- Parameters:
prefix
- the string to look for.- Returns:
true
if the specified string is a prefix of this string,false
otherwise- Throws:
java.lang.NullPointerException
- ifprefix
isnull
.
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.CharSequence string, java.lang.CharSequence prefix)
Compares the specified string to this string to determine if the specified string is a prefix.- Parameters:
prefix
- the string to look for.- Returns:
true
if the specified string is a prefix of this string,false
otherwise- Throws:
java.lang.NullPointerException
- ifprefix
isnull
.
-
startsWith
public boolean startsWith(java.lang.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.- Parameters:
prefix
- the string to look for.start
- the starting offset.- Returns:
true
if the specified string occurs in this string at the specified offset,false
otherwise.- Throws:
java.lang.NullPointerException
- ifprefix
isnull
.
-
startsWith
public static boolean startsWith(java.lang.CharSequence string, java.lang.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.- Parameters:
prefix
- the string to look for.start
- the starting offset.- Returns:
true
if the specified string occurs in this string at the specified offset,false
otherwise.- Throws:
java.lang.NullPointerException
- ifprefix
isnull
.
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.CharSequence string, java.lang.CharSequence prefix, int start)
-
toLowerCase
public ByteBufAsciiString toLowerCase()
Converts the characters in this string to lowercase, using the default Locale.- Returns:
- a new string containing the lowercase characters equivalent to the characters in this string.
-
toUpperCase
public ByteBufAsciiString toUpperCase()
Converts the characters in this string to uppercase, using the default Locale.- Returns:
- a new string containing the uppercase characters equivalent to the characters in this string.
-
trim
public static java.lang.CharSequence trim(java.lang.CharSequence c)
Copies this string removing white space characters from the beginning and end of the string, and tries not to copy if possible.- Parameters:
c
- TheCharSequence
to trim.- Returns:
- a new string with characters
<= \\u0020
removed from the beginning and the end.
-
trim
public ByteBufAsciiString trim()
Duplicates this string removing white space characters from the beginning and end of the string, without copying.- Returns:
- a new string with characters
<= \\u0020
removed from the beginning and the end.
-
contentEquals
public boolean contentEquals(java.lang.CharSequence a)
Compares aCharSequence
to thisString
to determine if their contents are equal.- Parameters:
a
- the character sequence to compare to.- Returns:
true
if equal, otherwisefalse
-
matches
public boolean matches(java.lang.String expr)
Determines whether this string matches a given regular expression.- Parameters:
expr
- the regular expression to be matched.- Returns:
true
if the expression matches, otherwisefalse
.- Throws:
java.util.regex.PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.java.lang.NullPointerException
- ifexpr
isnull
.
-
split
public ByteBufAsciiString[] split(java.lang.String expr, int max)
Splits this string using the supplied regular expressionexpr
. The parametermax
controls the behavior how many times the pattern is applied to the string.- Parameters:
expr
- the regular expression used to divide the string.max
- the number of entries in the resulting array.- Returns:
- an array of Strings created by separating the string along matches of the regular expression.
- Throws:
java.lang.NullPointerException
- ifexpr
isnull
.java.util.regex.PatternSyntaxException
- if the syntax of the supplied regular expression is not valid.- See Also:
Pattern.split(CharSequence, int)
-
split
public ByteBufAsciiString[] split(@Nonnull java.util.regex.Pattern pattern)
-
split
public ByteBufAsciiString[] split(@Nonnull java.util.regex.Pattern pattern, int limit)
-
split
public ByteBufAsciiString[] split(char delim)
Splits the specifiedString
with the specified delimiter..
-
hashCode
public int hashCode()
Provides a case-insensitive hash code for Ascii like byte strings.
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toAsciiString
@Nonnull public io.netty.util.AsciiString toAsciiString()
-
toString
@Nonnull public java.lang.String toString()
Translates the entire byte string to aString
.- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
- See Also:
toString(int)
-
toString
public java.lang.String toString(int start)
Translates the entire byte string to aString
using thecharset
encoding.- See Also:
toString(int, int)
-
toString
public java.lang.String toString(int start, int end)
Translates the [start
,end
) range of this byte string to aString
.
-
containsContentEqualsIgnoreCase
public static boolean containsContentEqualsIgnoreCase(java.util.Collection<java.lang.CharSequence> collection, java.lang.CharSequence value)
Determine ifcollection
containsvalue
and usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.- Parameters:
collection
- The collection to look for and equivalent element asvalue
.value
- The value to look for incollection
.- Returns:
true
ifcollection
containsvalue
according tocontentEqualsIgnoreCase(CharSequence, CharSequence)
.false
otherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
containsAllContentEqualsIgnoreCase
public static boolean containsAllContentEqualsIgnoreCase(java.util.Collection<java.lang.CharSequence> a, java.util.Collection<java.lang.CharSequence> b)
Determine ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.- Parameters:
a
- The collection under test.b
- The values to test for.- Returns:
true
ifa
contains all of the values inb
usingcontentEqualsIgnoreCase(CharSequence, CharSequence)
to compare values.false
otherwise.- See Also:
contentEqualsIgnoreCase(CharSequence, CharSequence)
-
contentEquals
public static boolean contentEquals(java.lang.CharSequence a, java.lang.CharSequence b)
Returnstrue
if the content of bothCharSequence
's are equals. This only supports 8-bit ASCII.
-
hashCode
public static int hashCode(java.lang.CharSequence value)
Returns the case-insensitive hash code of the specified string. Note that this method uses the same hashing algorithm withhashCode()
so that you can put bothAsciiString
s and arbitraryCharSequence
s into the same headers.
-
contains
public static boolean contains(java.lang.CharSequence a, java.lang.CharSequence b)
Determine ifa
containsb
in a case sensitive manner.
-
containsIgnoreCase
public static boolean containsIgnoreCase(java.lang.CharSequence a, java.lang.CharSequence b)
Determine ifa
containsb
in a case insensitive manner.
-
contentEqualsIgnoreCase
public static boolean contentEqualsIgnoreCase(java.lang.CharSequence a, java.lang.CharSequence b)
Returnstrue
if bothCharSequence
's are equals when ignore the case. This only supports 8-bit ASCII.
-
regionMatches
public static boolean regionMatches(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)
This methods make regionMatches operation correctly for any chars in strings- Parameters:
cs
- theCharSequence
to be processedignoreCase
- specifies if case should be ignored.csStart
- the starting offset in thecs
CharSequencestring
- theCharSequence
to compare.start
- the starting offset in the specifiedstring
.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise.
-
regionMatchesAscii
public static boolean regionMatchesAscii(java.lang.CharSequence cs, boolean ignoreCase, int csStart, java.lang.CharSequence string, int start, int length)
This is optimized version of regionMatches for string with ASCII chars only- Parameters:
cs
- theCharSequence
to be processedignoreCase
- specifies if case should be ignored.csStart
- the starting offset in thecs
CharSequencestring
- theCharSequence
to compare.start
- the starting offset in the specifiedstring
.length
- the number of characters to compare.- Returns:
true
if the ranges of characters are equal,false
otherwise.
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(java.lang.CharSequence str, java.lang.CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position.
A
null
CharSequence will return-1
. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.AsciiString.indexOfIgnoreCase(null, *, *) = -1 AsciiString.indexOfIgnoreCase(*, null, *) = -1 AsciiString.indexOfIgnoreCase("", "", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "", 2) = 2 AsciiString.indexOfIgnoreCase("abc", "", 9) = -1
- Parameters:
str
- the CharSequence to check, may be nullsearchStr
- the CharSequence to find, may be nullstartPos
- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos),
-1 if no match or
null
string input
-
indexOfIgnoreCaseAscii
public static int indexOfIgnoreCaseAscii(java.lang.CharSequence str, java.lang.CharSequence searchStr, int startPos)
Case in-sensitive find of the first index within a CharSequence from the specified position. This method optimized and works correctly for ASCII CharSequences only
A
null
CharSequence will return-1
. A negative start position is treated as zero. An empty ("") search CharSequence always matches. A start position greater than the string length only matches an empty search CharSequence.AsciiString.indexOfIgnoreCase(null, *, *) = -1 AsciiString.indexOfIgnoreCase(*, null, *) = -1 AsciiString.indexOfIgnoreCase("", "", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "A", 0) = 0 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 0) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "AB", 0) = 1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 3) = 5 AsciiString.indexOfIgnoreCase("aabaabaa", "B", 9) = -1 AsciiString.indexOfIgnoreCase("aabaabaa", "B", -1) = 2 AsciiString.indexOfIgnoreCase("aabaabaa", "", 2) = 2 AsciiString.indexOfIgnoreCase("abc", "", 9) = -1
- Parameters:
str
- the CharSequence to check, may be nullsearchStr
- the CharSequence to find, may be nullstartPos
- the start position, negative treated as zero- Returns:
- the first index of the search CharSequence (always ≥ startPos),
-1 if no match or
null
string input
-
indexOf
public static int indexOf(java.lang.CharSequence cs, char searchChar, int start)
Finds the first index in the
CharSequence
that matches the specified character.- Parameters:
cs
- theCharSequence
to be processed, not nullsearchChar
- the char to be searched forstart
- the start index, negative starts at the string start- Returns:
- the index where the search char was found,
-1 if char
searchChar
is not found orcs == null
-
isUpperCase
public static boolean isUpperCase(byte value)
-
isUpperCase
public static boolean isUpperCase(char value)
-
c2b
public static byte c2b(char c)
-
c2b0
public static byte c2b0(char c)
-
b2c
public static char b2c(byte b)
-
refCnt
public int refCnt()
- Specified by:
refCnt
in interfaceio.netty.util.ReferenceCounted
-
retain
public ByteBufAsciiString retain()
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
-
retain
public ByteBufAsciiString retain(int increment)
- Specified by:
retain
in interfaceio.netty.util.ReferenceCounted
-
touch
public io.netty.util.ReferenceCounted touch()
- Specified by:
touch
in interfaceio.netty.util.ReferenceCounted
-
touch
public io.netty.util.ReferenceCounted touch(java.lang.Object hint)
- Specified by:
touch
in interfaceio.netty.util.ReferenceCounted
-
release
public boolean release()
- Specified by:
release
in interfaceio.netty.util.ReferenceCounted
-
release
public boolean release(int decrement)
- Specified by:
release
in interfaceio.netty.util.ReferenceCounted
-
-