Top Description Fields Constructors Methods
io.netty.util.internal

public final Class StringUtil

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .Iterator, .List

String utility class.

Field Summary

Modifier and TypeField and Description
private static final String[]
private static final String[]
public static final char
public static final char
private static final int
CSV_NUMBER_ESCAPE_CHARACTERS

2 - Quote character at beginning and end.

public static final char
public static final String
private static final byte[]
public static final char
public static final String
private static final char
public static final char
public static final char

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String
byteToHexString(int value)

Converts the specified byte value into a hexadecimal integer.

public static <T extends Appendable> T
byteToHexString(T buf, int value)

Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer.

public static String
byteToHexStringPadded(int value)

Converts the specified byte value into a 2-digit hexadecimal integer.

public static <T extends Appendable> T
byteToHexStringPadded(T buf, int value)

Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer.

public static boolean

Returns:

true if both s and p are not null and both have the same suffix. Otherwise - false
commonSuffixOfLength
(String
string
s
,
String
string
p
,
int
length of the common suffix
len
)

Checks if two strings have the same suffix of specified length

public static byte
decodeHexByte(CharSequence s, int pos)

Decode a 2-digit hex byte from within a string.

public static byte[]
decodeHexDump(CharSequence
a CharSequence which contains the hex dump
hexDump
,
int
start of hex dump in hexDump
fromIndex
,
int
hex string length
length
)

Decodes part of a string with hex dump

public static byte[]
public static int

Returns:

The hexadecimal value represented in the ASCII character given, or -1 if the character is invalid.
decodeHexNibble
(final char
The ASCII character of the hexadecimal number to decode. Must be in the range [0-9a-fA-F].
c
)

Helper to decode half of a hexadecimal number from a string.

public static int

Returns:

The hexadecimal value represented in the ASCII character given, or -1 if the character is invalid.
decodeHexNibble
(final byte
The ASCII character of the hexadecimal number to decode. Must be in the range [0-9a-fA-F].
b
)

Helper to decode half of a hexadecimal number from a string.

public static boolean

Returns:

true if s ends with the char c
endsWith
(CharSequence
the string to test
s
,
char
the tested char
c
)

Determine if the string s ends with the char c.

public static CharSequence

Returns:

CharSequence the escaped value if necessary, or the value unchanged
escapeCsv
(CharSequence
The value which will be escaped according to RFC-4180
value
)

Escapes the specified value, if necessary according to RFC-4180.

public static CharSequence

Returns:

CharSequence the escaped value if necessary, or the value unchanged
escapeCsv
(CharSequence
The value which will be escaped according to RFC-4180
value
,
boolean
The value will first be trimmed of its optional white-space characters, according to RFC-7230
trimWhiteSpace
)

Escapes the specified value, if necessary according to RFC-4180.

private static int

Returns:

length if no OWS is found.
indexOfFirstNonOwsChar
(CharSequence value, int length)

private static int

Returns:

start if no OWS is found.
indexOfLastNonOwsChar
(CharSequence value, int start, int length)

public static int

Returns:

the index of the first non-white space character or <-1 if none was found.
indexOfNonWhiteSpace
(CharSequence
The string to search.
seq
,
int
The offset to start searching at.
offset
)

Find the index of the first non-white space character in s starting at offset.

public static int

Returns:

the index of the first white space character or <-1 if none was found.
indexOfWhiteSpace
(CharSequence
The string to search.
seq
,
int
The offset to start searching at.
offset
)

Find the index of the first white space character in s starting at offset.

private static boolean
isDoubleQuote(char c)

public static boolean
isNullOrEmpty(String s)

Determine if a string is null or String#isEmpty() returns true.

private static boolean
isOws(char c)

public static boolean

Returns:

true if c lies within the range of values defined for Surrogate Code Point. false otherwise.
isSurrogate
(char
the character to check.
c
)

Determine if c lies within the range of values defined for Surrogate Code Point.

public static CharSequence

Returns:

a char sequence joined by a given separator.
join
(CharSequence
for each element
separator
,
Iterable<? extends CharSequence>
to join together
elements
)

Returns a char sequence that contains all elements joined by a given separator.

public static int
length(String s)

Get the length of a string, null input is considered 0 length.

private static IllegalArgumentException
public static String
public static String
simpleClassName(Class<?> clazz)

Generates a simplified name from a Class.

public static String
substringAfter(String value, char delim)

Get the item after one char delim if the delim is found (else null).

public static String
substringBefore(String value, char delim)

Get the item before one char delim if the delim is found (else null).

public static String
toHexString(byte[] src)

Converts the specified byte array into a hexadecimal value.

public static String
toHexString(byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value.

public static <T extends Appendable> T
toHexString(T dst, byte[] src)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

public static <T extends Appendable> T
toHexString(T dst, byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

public static String
toHexStringPadded(byte[] src)

Converts the specified byte array into a hexadecimal value.

public static String
toHexStringPadded(byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value.

public static <T extends Appendable> T
toHexStringPadded(T dst, byte[] src)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

public static <T extends Appendable> T
toHexStringPadded(T dst, byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

public static CharSequence

Returns:

CharSequence the trimmed value if necessary, or the value unchanged
trimOws
(CharSequence
the value to trim
value
)

Trim optional white-space characters from the specified value, according to RFC-7230.

public static CharSequence

Returns:

CharSequence the unescaped value if necessary, or the value unchanged
unescapeCsv
(CharSequence
The escaped CSV field which will be unescaped according to RFC-4180
value
)

Unescapes the specified escaped CSV field, if necessary according to RFC-4180.

public static List<CharSequence>

Returns:

List the list of unescaped fields
unescapeCsvFields
(CharSequence
A string with multiple CSV escaped fields which will be unescaped according to RFC-4180
value
)

Unescapes the specified escaped CSV fields according to RFC-4180.

private static void
validateCsvFormat(CharSequence value)

Validate if value is a valid csv field without double-quotes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE2HEX_NOPADback to summary
private static final String[] BYTE2HEX_NOPAD
BYTE2HEX_PADback to summary
private static final String[] BYTE2HEX_PAD
CARRIAGE_RETURNback to summary
public static final char CARRIAGE_RETURN
COMMAback to summary
public static final char COMMA
CSV_NUMBER_ESCAPE_CHARACTERSback to summary
private static final int CSV_NUMBER_ESCAPE_CHARACTERS

2 - Quote character at beginning and end. 5 - Extra allowance for anticipated escape characters that may be added.

DOUBLE_QUOTEback to summary
public static final char DOUBLE_QUOTE
EMPTY_STRINGback to summary
public static final String EMPTY_STRING
HEX2Bback to summary
private static final byte[] HEX2B
LINE_FEEDback to summary
public static final char LINE_FEED
NEWLINEback to summary
public static final String NEWLINE
PACKAGE_SEPARATOR_CHARback to summary
private static final char PACKAGE_SEPARATOR_CHAR
SPACEback to summary
public static final char SPACE
TABback to summary
public static final char TAB

Constructor Detail

StringUtilback to summary
private StringUtil()

Method Detail

byteToHexStringback to summary
public static String byteToHexString(int value)

Converts the specified byte value into a hexadecimal integer.

byteToHexStringback to summary
public static <T extends Appendable> T byteToHexString(T buf, int value)

Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer.

byteToHexStringPaddedback to summary
public static String byteToHexStringPadded(int value)

Converts the specified byte value into a 2-digit hexadecimal integer.

byteToHexStringPaddedback to summary
public static <T extends Appendable> T byteToHexStringPadded(T buf, int value)

Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer.

commonSuffixOfLengthback to summary
public static boolean commonSuffixOfLength(String s, String p, int len)

Checks if two strings have the same suffix of specified length

Parameters
s:String

string

p:String

string

len:int

length of the common suffix

Returns:boolean

true if both s and p are not null and both have the same suffix. Otherwise - false

decodeHexByteback to summary
public static byte decodeHexByte(CharSequence s, int pos)

Decode a 2-digit hex byte from within a string.

decodeHexDumpback to summary
public static byte[] decodeHexDump(CharSequence hexDump, int fromIndex, int length)

Decodes part of a string with hex dump

Parameters
hexDump:CharSequence

a CharSequence which contains the hex dump

fromIndex:int

start of hex dump in hexDump

length:int

hex string length

decodeHexDumpback to summary
public static byte[] decodeHexDump(CharSequence hexDump)

Decodes a hex dump

decodeHexNibbleback to summary
public static int decodeHexNibble(final char c)

Helper to decode half of a hexadecimal number from a string.

Parameters
c:char

The ASCII character of the hexadecimal number to decode. Must be in the range [0-9a-fA-F].

Returns:int

The hexadecimal value represented in the ASCII character given, or -1 if the character is invalid.

decodeHexNibbleback to summary
public static int decodeHexNibble(final byte b)

Helper to decode half of a hexadecimal number from a string.

Parameters
b:byte

The ASCII character of the hexadecimal number to decode. Must be in the range [0-9a-fA-F].

Returns:int

The hexadecimal value represented in the ASCII character given, or -1 if the character is invalid.

endsWithback to summary
public static boolean endsWith(CharSequence s, char c)

Determine if the string s ends with the char c.

Parameters
s:CharSequence

the string to test

c:char

the tested char

Returns:boolean

true if s ends with the char c

escapeCsvback to summary
public static CharSequence escapeCsv(CharSequence value)

Escapes the specified value, if necessary according to RFC-4180.

Parameters
value:CharSequence

The value which will be escaped according to RFC-4180

Returns:CharSequence

CharSequence the escaped value if necessary, or the value unchanged

escapeCsvback to summary
public static CharSequence escapeCsv(CharSequence value, boolean trimWhiteSpace)

Escapes the specified value, if necessary according to RFC-4180.

Parameters
value:CharSequence

The value which will be escaped according to RFC-4180

trimWhiteSpace:boolean

The value will first be trimmed of its optional white-space characters, according to RFC-7230

Returns:CharSequence

CharSequence the escaped value if necessary, or the value unchanged

indexOfFirstNonOwsCharback to summary
private static int indexOfFirstNonOwsChar(CharSequence value, int length)
Returns:int

length if no OWS is found.

indexOfLastNonOwsCharback to summary
private static int indexOfLastNonOwsChar(CharSequence value, int start, int length)
Returns:int

start if no OWS is found.

indexOfNonWhiteSpaceback to summary
public static int indexOfNonWhiteSpace(CharSequence seq, int offset)

Find the index of the first non-white space character in s starting at offset.

Parameters
seq:CharSequence

The string to search.

offset:int

The offset to start searching at.

Returns:int

the index of the first non-white space character or <-1 if none was found.

indexOfWhiteSpaceback to summary
public static int indexOfWhiteSpace(CharSequence seq, int offset)

Find the index of the first white space character in s starting at offset.

Parameters
seq:CharSequence

The string to search.

offset:int

The offset to start searching at.

Returns:int

the index of the first white space character or <-1 if none was found.

isDoubleQuoteback to summary
private static boolean isDoubleQuote(char c)
isNullOrEmptyback to summary
public static boolean isNullOrEmpty(String s)

Determine if a string is null or String#isEmpty() returns true.

isOwsback to summary
private static boolean isOws(char c)
isSurrogateback to summary
public static boolean isSurrogate(char c)

Determine if c lies within the range of values defined for Surrogate Code Point.

Parameters
c:char

the character to check.

Returns:boolean

true if c lies within the range of values defined for Surrogate Code Point. false otherwise.

joinback to summary
public static CharSequence join(CharSequence separator, Iterable<? extends CharSequence> elements)

Returns a char sequence that contains all elements joined by a given separator.

Parameters
separator:CharSequence

for each element

elements:Iterable<? extends CharSequence>

to join together

Returns:CharSequence

a char sequence joined by a given separator.

lengthback to summary
public static int length(String s)

Get the length of a string, null input is considered 0 length.

newInvalidEscapedCsvFieldExceptionback to summary
private static IllegalArgumentException newInvalidEscapedCsvFieldException(CharSequence value, int index)
simpleClassNameback to summary
public static String simpleClassName(Object o)

The shortcut to simpleClassName(o.getClass()).

simpleClassNameback to summary
public static String simpleClassName(Class<?> clazz)

Generates a simplified name from a Class. Similar to Class#getSimpleName(), but it works fine with anonymous classes.

substringAfterback to summary
public static String substringAfter(String value, char delim)

Get the item after one char delim if the delim is found (else null). This operation is a simplified and optimized version of String#split(String, int).

substringBeforeback to summary
public static String substringBefore(String value, char delim)

Get the item before one char delim if the delim is found (else null). This operation is a simplified and optimized version of String#split(String, int).

toHexStringback to summary
public static String toHexString(byte[] src)

Converts the specified byte array into a hexadecimal value.

toHexStringback to summary
public static String toHexString(byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value.

toHexStringback to summary
public static <T extends Appendable> T toHexString(T dst, byte[] src)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

toHexStringback to summary
public static <T extends Appendable> T toHexString(T dst, byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

toHexStringPaddedback to summary
public static String toHexStringPadded(byte[] src)

Converts the specified byte array into a hexadecimal value.

toHexStringPaddedback to summary
public static String toHexStringPadded(byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value.

toHexStringPaddedback to summary
public static <T extends Appendable> T toHexStringPadded(T dst, byte[] src)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

toHexStringPaddedback to summary
public static <T extends Appendable> T toHexStringPadded(T dst, byte[] src, int offset, int length)

Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.

trimOwsback to summary
public static CharSequence trimOws(CharSequence value)

Trim optional white-space characters from the specified value, according to RFC-7230.

Parameters
value:CharSequence

the value to trim

Returns:CharSequence

CharSequence the trimmed value if necessary, or the value unchanged

unescapeCsvback to summary
public static CharSequence unescapeCsv(CharSequence value)

Unescapes the specified escaped CSV field, if necessary according to RFC-4180.

Parameters
value:CharSequence

The escaped CSV field which will be unescaped according to RFC-4180

Returns:CharSequence

CharSequence the unescaped value if necessary, or the value unchanged

unescapeCsvFieldsback to summary
public static List<CharSequence> unescapeCsvFields(CharSequence value)

Unescapes the specified escaped CSV fields according to RFC-4180.

Parameters
value:CharSequence

A string with multiple CSV escaped fields which will be unescaped according to RFC-4180

Returns:List<CharSequence>

List the list of unescaped fields

validateCsvFormatback to summary
private static void validateCsvFormat(CharSequence value)

Validate if value is a valid csv field without double-quotes.

Exceptions
IllegalArgumentException:
if value needs to be encoded with double-quotes.