Class StringUtil
java.lang.Object
io.netty.util.internal.StringUtil
public final class StringUtil
extends java.lang.Object
String utility class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final java.lang.String[]private static final java.lang.String[]static final charstatic final charprivate static final int2 - Quote character at beginning and end.static final charstatic final java.lang.Stringprivate static final byte[]static final charstatic final java.lang.Stringprivate static final charstatic final charstatic final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic java.lang.StringbyteToHexString(int value) Converts the specified byte value into a hexadecimal integer.static <T extends java.lang.Appendable>
TbyteToHexString(T buf, int value) Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer.static java.lang.StringbyteToHexStringPadded(int value) Converts the specified byte value into a 2-digit hexadecimal integer.static <T extends java.lang.Appendable>
TbyteToHexStringPadded(T buf, int value) Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer.static java.lang.StringclassName(java.lang.Object o) Generates a class name from aClass.static booleancommonSuffixOfLength(java.lang.String s, java.lang.String p, int len) Checks if two strings have the same suffix of specified lengthstatic bytedecodeHexByte(java.lang.CharSequence s, int pos) Decode a 2-digit hex byte from within a string.static byte[]decodeHexDump(java.lang.CharSequence hexDump) Decodes a hex dumpstatic byte[]decodeHexDump(java.lang.CharSequence hexDump, int fromIndex, int length) Decodes part of a string with hex dumpstatic intdecodeHexNibble(byte b) Helper to decode half of a hexadecimal number from a string.static intdecodeHexNibble(char c) Helper to decode half of a hexadecimal number from a string.static booleanendsWith(java.lang.CharSequence s, char c) Determine if the stringsends with the charc.static java.lang.CharSequenceescapeCsv(java.lang.CharSequence value) Escapes the specified value, if necessary according to RFC-4180.static java.lang.CharSequenceescapeCsv(java.lang.CharSequence value, boolean trimWhiteSpace) Escapes the specified value, if necessary according to RFC-4180.private static intindexOfFirstNonOwsChar(java.lang.CharSequence value, int length) private static intindexOfLastNonOwsChar(java.lang.CharSequence value, int start, int length) static intindexOfNonWhiteSpace(java.lang.CharSequence seq, int offset) Find the index of the first non-white space character insstarting atoffset.static intindexOfWhiteSpace(java.lang.CharSequence seq, int offset) Find the index of the first white space character insstarting atoffset.private static booleanisDoubleQuote(char c) static booleanisNullOrEmpty(java.lang.String s) Determine if a string isnullorString.isEmpty()returnstrue.private static booleanisOws(char c) static booleanisSurrogate(char c) Determine ifclies within the range of values defined for Surrogate Code Point.static java.lang.CharSequencejoin(java.lang.CharSequence separator, java.lang.Iterable<? extends java.lang.CharSequence> elements) Returns a char sequence that contains allelementsjoined by a given separator.static intlength(java.lang.String s) Get the length of a string,nullinput is considered0length.private static java.lang.IllegalArgumentExceptionnewInvalidEscapedCsvFieldException(java.lang.CharSequence value, int index) static java.lang.StringsimpleClassName(java.lang.Class<?> clazz) Generates a simplified name from aClass.static java.lang.StringsimpleClassName(java.lang.Object o) The shortcut tosimpleClassName(o.getClass()).static java.lang.StringsubstringAfter(java.lang.String value, char delim) Get the item after one char delim if the delim is found (else null).static java.lang.StringsubstringBefore(java.lang.String value, char delim) Get the item before one char delim if the delim is found (else null).static java.lang.StringtoHexString(byte[] src) Converts the specified byte array into a hexadecimal value.static java.lang.StringtoHexString(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value.static <T extends java.lang.Appendable>
TtoHexString(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static <T extends java.lang.Appendable>
TtoHexString(T dst, byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static java.lang.StringtoHexStringPadded(byte[] src) Converts the specified byte array into a hexadecimal value.static java.lang.StringtoHexStringPadded(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value.static <T extends java.lang.Appendable>
TtoHexStringPadded(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static <T extends java.lang.Appendable>
TtoHexStringPadded(T dst, byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer.static java.lang.CharSequencetrimOws(java.lang.CharSequence value) Trim optional white-space characters from the specified value, according to RFC-7230.static java.lang.CharSequenceunescapeCsv(java.lang.CharSequence value) Unescapes the specified escaped CSV field, if necessary according to RFC-4180.static java.util.List<java.lang.CharSequence> unescapeCsvFields(java.lang.CharSequence value) Unescapes the specified escaped CSV fields according to RFC-4180.private static voidvalidateCsvFormat(java.lang.CharSequence value) Validate ifvalueis a valid csv field without double-quotes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
EMPTY_STRING
public static final java.lang.String EMPTY_STRING- See Also:
-
NEWLINE
public static final java.lang.String NEWLINE -
DOUBLE_QUOTE
public static final char DOUBLE_QUOTE- See Also:
-
COMMA
public static final char COMMA- See Also:
-
LINE_FEED
public static final char LINE_FEED- See Also:
-
CARRIAGE_RETURN
public static final char CARRIAGE_RETURN- See Also:
-
TAB
public static final char TAB- See Also:
-
SPACE
public static final char SPACE- See Also:
-
BYTE2HEX_PAD
private static final java.lang.String[] BYTE2HEX_PAD -
BYTE2HEX_NOPAD
private static final java.lang.String[] BYTE2HEX_NOPAD -
HEX2B
private static final byte[] HEX2B -
CSV_NUMBER_ESCAPE_CHARACTERS
private static final int CSV_NUMBER_ESCAPE_CHARACTERS2 - Quote character at beginning and end. 5 - Extra allowance for anticipated escape characters that may be added.- See Also:
-
PACKAGE_SEPARATOR_CHAR
private static final char PACKAGE_SEPARATOR_CHAR- See Also:
-
-
Constructor Details
-
StringUtil
private StringUtil()
-
-
Method Details
-
substringAfter
public static java.lang.String substringAfter(java.lang.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 ofString.split(String, int). -
substringBefore
public static java.lang.String substringBefore(java.lang.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 ofString.split(String, int). -
commonSuffixOfLength
public static boolean commonSuffixOfLength(java.lang.String s, java.lang.String p, int len) Checks if two strings have the same suffix of specified length- Parameters:
s- stringp- stringlen- length of the common suffix- Returns:
- true if both s and p are not null and both have the same suffix. Otherwise - false
-
byteToHexStringPadded
public static java.lang.String byteToHexStringPadded(int value) Converts the specified byte value into a 2-digit hexadecimal integer. -
byteToHexStringPadded
public static <T extends java.lang.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. -
toHexStringPadded
public static java.lang.String toHexStringPadded(byte[] src) Converts the specified byte array into a hexadecimal value. -
toHexStringPadded
public static java.lang.String toHexStringPadded(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value. -
toHexStringPadded
public static <T extends java.lang.Appendable> T toHexStringPadded(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
toHexStringPadded
public static <T extends java.lang.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. -
byteToHexString
public static java.lang.String byteToHexString(int value) Converts the specified byte value into a hexadecimal integer. -
byteToHexString
public static <T extends java.lang.Appendable> T byteToHexString(T buf, int value) Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer. -
toHexString
public static java.lang.String toHexString(byte[] src) Converts the specified byte array into a hexadecimal value. -
toHexString
public static java.lang.String toHexString(byte[] src, int offset, int length) Converts the specified byte array into a hexadecimal value. -
toHexString
public static <T extends java.lang.Appendable> T toHexString(T dst, byte[] src) Converts the specified byte array into a hexadecimal value and appends it to the specified buffer. -
toHexString
public static <T extends java.lang.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. -
decodeHexNibble
public static int decodeHexNibble(char c) Helper to decode half of a hexadecimal number from a string.- Parameters:
c- The ASCII character of the hexadecimal number to decode. Must be in the range[0-9a-fA-F].- Returns:
- The hexadecimal value represented in the ASCII character
given, or
-1if the character is invalid.
-
decodeHexNibble
public static int decodeHexNibble(byte b) Helper to decode half of a hexadecimal number from a string.- Parameters:
b- The ASCII character of the hexadecimal number to decode. Must be in the range[0-9a-fA-F].- Returns:
- The hexadecimal value represented in the ASCII character
given, or
-1if the character is invalid.
-
decodeHexByte
public static byte decodeHexByte(java.lang.CharSequence s, int pos) Decode a 2-digit hex byte from within a string. -
decodeHexDump
public static byte[] decodeHexDump(java.lang.CharSequence hexDump, int fromIndex, int length) Decodes part of a string with hex dump- Parameters:
hexDump- aCharSequencewhich contains the hex dumpfromIndex- start of hex dump inhexDumplength- hex string length
-
decodeHexDump
public static byte[] decodeHexDump(java.lang.CharSequence hexDump) Decodes a hex dump -
className
public static java.lang.String className(java.lang.Object o) Generates a class name from aClass. Similar toClass.getName(), but null-safe. -
simpleClassName
public static java.lang.String simpleClassName(java.lang.Object o) The shortcut tosimpleClassName(o.getClass()). -
simpleClassName
public static java.lang.String simpleClassName(java.lang.Class<?> clazz) Generates a simplified name from aClass. Similar toClass.getSimpleName(), but it works fine with anonymous classes. -
escapeCsv
-
escapeCsv
public static java.lang.CharSequence escapeCsv(java.lang.CharSequence value, boolean trimWhiteSpace) Escapes the specified value, if necessary according to RFC-4180. -
unescapeCsv
public static java.lang.CharSequence unescapeCsv(java.lang.CharSequence value) Unescapes the specified escaped CSV field, if necessary according to RFC-4180.- Parameters:
value- The escaped CSV field which will be unescaped according to RFC-4180- Returns:
CharSequencethe unescaped value if necessary, or the value unchanged
-
unescapeCsvFields
public static java.util.List<java.lang.CharSequence> unescapeCsvFields(java.lang.CharSequence value) Unescapes the specified escaped CSV fields according to RFC-4180.- Parameters:
value- A string with multiple CSV escaped fields which will be unescaped according to RFC-4180- Returns:
Listthe list of unescaped fields
-
validateCsvFormat
private static void validateCsvFormat(java.lang.CharSequence value) Validate ifvalueis a valid csv field without double-quotes.- Throws:
java.lang.IllegalArgumentException- ifvalueneeds to be encoded with double-quotes.
-
newInvalidEscapedCsvFieldException
private static java.lang.IllegalArgumentException newInvalidEscapedCsvFieldException(java.lang.CharSequence value, int index) -
length
public static int length(java.lang.String s) Get the length of a string,nullinput is considered0length. -
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String s) Determine if a string isnullorString.isEmpty()returnstrue. -
indexOfNonWhiteSpace
public static int indexOfNonWhiteSpace(java.lang.CharSequence seq, int offset) Find the index of the first non-white space character insstarting atoffset.- Parameters:
seq- The string to search.offset- The offset to start searching at.- Returns:
- the index of the first non-white space character or <
-1if none was found.
-
indexOfWhiteSpace
public static int indexOfWhiteSpace(java.lang.CharSequence seq, int offset) Find the index of the first white space character insstarting atoffset.- Parameters:
seq- The string to search.offset- The offset to start searching at.- Returns:
- the index of the first white space character or <
-1if none was found.
-
isSurrogate
public static boolean isSurrogate(char c) Determine ifclies within the range of values defined for Surrogate Code Point.- Parameters:
c- the character to check.- Returns:
trueifclies within the range of values defined for Surrogate Code Point.falseotherwise.
-
isDoubleQuote
private static boolean isDoubleQuote(char c) -
endsWith
public static boolean endsWith(java.lang.CharSequence s, char c) Determine if the stringsends with the charc.- Parameters:
s- the string to testc- the tested char- Returns:
- true if
sends with the charc
-
trimOws
public static java.lang.CharSequence trimOws(java.lang.CharSequence value) Trim optional white-space characters from the specified value, according to RFC-7230.- Parameters:
value- the value to trim- Returns:
CharSequencethe trimmed value if necessary, or the value unchanged
-
join
public static java.lang.CharSequence join(java.lang.CharSequence separator, java.lang.Iterable<? extends java.lang.CharSequence> elements) Returns a char sequence that contains allelementsjoined by a given separator.- Parameters:
separator- for each elementelements- to join together- Returns:
- a char sequence joined by a given separator.
-
indexOfFirstNonOwsChar
private static int indexOfFirstNonOwsChar(java.lang.CharSequence value, int length) - Returns:
lengthif no OWS is found.
-
indexOfLastNonOwsChar
private static int indexOfLastNonOwsChar(java.lang.CharSequence value, int start, int length) - Returns:
startif no OWS is found.
-
isOws
private static boolean isOws(char c)
-