public final class StringUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
BYTE2HEX_NOPAD |
private static java.lang.String[] |
BYTE2HEX_PAD |
static char |
CARRIAGE_RETURN |
static char |
COMMA |
private static int |
CSV_NUMBER_ESCAPE_CHARACTERS
2 - Quote character at beginning and end.
|
static char |
DOUBLE_QUOTE |
static java.lang.String |
EMPTY_STRING |
static char |
LINE_FEED |
static java.lang.String |
NEWLINE |
private static char |
PACKAGE_SEPARATOR_CHAR |
static char |
SPACE |
static char |
TAB |
Modifier | Constructor and Description |
---|---|
private |
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
byteToHexString(int value)
Converts the specified byte value into a hexadecimal integer.
|
static <T extends java.lang.Appendable> |
byteToHexString(T buf,
int value)
Converts the specified byte value into a hexadecimal integer and appends it to the specified buffer.
|
static java.lang.String |
byteToHexStringPadded(int value)
Converts the specified byte value into a 2-digit hexadecimal integer.
|
static <T extends java.lang.Appendable> |
byteToHexStringPadded(T buf,
int value)
Converts the specified byte value into a 2-digit hexadecimal integer and appends it to the specified buffer.
|
static boolean |
commonSuffixOfLength(java.lang.String s,
java.lang.String p,
int len)
Checks if two strings have the same suffix of specified length
|
static byte |
decodeHexByte(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 dump
|
static byte[] |
decodeHexDump(java.lang.CharSequence hexDump,
int fromIndex,
int length)
Decodes part of a string with hex dump
|
static int |
decodeHexNibble(char c)
Helper to decode half of a hexadecimal number from a string.
|
static boolean |
endsWith(java.lang.CharSequence s,
char c)
Determine if the string
s ends with the char c . |
static java.lang.CharSequence |
escapeCsv(java.lang.CharSequence value)
Escapes the specified value, if necessary according to
RFC-4180.
|
static java.lang.CharSequence |
escapeCsv(java.lang.CharSequence value,
boolean trimWhiteSpace)
Escapes the specified value, if necessary according to
RFC-4180.
|
private static int |
indexOfFirstNonOwsChar(java.lang.CharSequence value,
int length) |
private static int |
indexOfLastNonOwsChar(java.lang.CharSequence value,
int start,
int length) |
static int |
indexOfNonWhiteSpace(java.lang.CharSequence seq,
int offset)
Find the index of the first non-white space character in
s starting at offset . |
private static boolean |
isDoubleQuote(char c) |
static boolean |
isNullOrEmpty(java.lang.String s)
Determine if a string is
null or String.isEmpty() returns true . |
private static boolean |
isOws(char c) |
static boolean |
isSurrogate(char c)
Determine if
c lies within the range of values defined for
Surrogate Code Point. |
static int |
length(java.lang.String s)
Get the length of a string,
null input is considered 0 length. |
private static java.lang.IllegalArgumentException |
newInvalidEscapedCsvFieldException(java.lang.CharSequence value,
int index) |
static java.lang.String |
simpleClassName(java.lang.Class<?> clazz)
Generates a simplified name from a
Class . |
static java.lang.String |
simpleClassName(java.lang.Object o)
The shortcut to
simpleClassName(o.getClass()) . |
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).
|
static java.lang.String |
toHexString(byte[] src)
Converts the specified byte array into a hexadecimal value.
|
static java.lang.String |
toHexString(byte[] src,
int offset,
int length)
Converts the specified byte array into a hexadecimal value.
|
static <T extends java.lang.Appendable> |
toHexString(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> |
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.
|
static java.lang.String |
toHexStringPadded(byte[] src)
Converts the specified byte array into a hexadecimal value.
|
static java.lang.String |
toHexStringPadded(byte[] src,
int offset,
int length)
Converts the specified byte array into a hexadecimal value.
|
static <T extends java.lang.Appendable> |
toHexStringPadded(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> |
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.
|
static java.lang.CharSequence |
trimOws(java.lang.CharSequence value)
Trim optional white-space characters from the specified value,
according to RFC-7230.
|
static java.lang.CharSequence |
unescapeCsv(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 void |
validateCsvFormat(java.lang.CharSequence value)
Validate if
value is a valid csv field without double-quotes. |
public static final java.lang.String EMPTY_STRING
public static final java.lang.String NEWLINE
public static final char DOUBLE_QUOTE
public static final char COMMA
public static final char LINE_FEED
public static final char CARRIAGE_RETURN
public static final char TAB
public static final char SPACE
private static final java.lang.String[] BYTE2HEX_PAD
private static final java.lang.String[] BYTE2HEX_NOPAD
private static final int CSV_NUMBER_ESCAPE_CHARACTERS
private static final char PACKAGE_SEPARATOR_CHAR
public static java.lang.String substringAfter(java.lang.String value, char delim)
String.split(String, int)
.public static boolean commonSuffixOfLength(java.lang.String s, java.lang.String p, int len)
s
- stringp
- stringlen
- length of the common suffixpublic static java.lang.String byteToHexStringPadded(int value)
public static <T extends java.lang.Appendable> T byteToHexStringPadded(T buf, int value)
public static java.lang.String toHexStringPadded(byte[] src)
public static java.lang.String toHexStringPadded(byte[] src, int offset, int length)
public static <T extends java.lang.Appendable> T toHexStringPadded(T dst, byte[] src)
public static <T extends java.lang.Appendable> T toHexStringPadded(T dst, byte[] src, int offset, int length)
public static java.lang.String byteToHexString(int value)
public static <T extends java.lang.Appendable> T byteToHexString(T buf, int value)
public static java.lang.String toHexString(byte[] src)
public static java.lang.String toHexString(byte[] src, int offset, int length)
public static <T extends java.lang.Appendable> T toHexString(T dst, byte[] src)
public static <T extends java.lang.Appendable> T toHexString(T dst, byte[] src, int offset, int length)
public static int decodeHexNibble(char c)
c
- The ASCII character of the hexadecimal number to decode.
Must be in the range [0-9a-fA-F]
.-1
if the character is invalid.public static byte decodeHexByte(java.lang.CharSequence s, int pos)
public static byte[] decodeHexDump(java.lang.CharSequence hexDump, int fromIndex, int length)
hexDump
- a CharSequence
which contains the hex dumpfromIndex
- start of hex dump in hexDump
length
- hex string lengthpublic static byte[] decodeHexDump(java.lang.CharSequence hexDump)
public static java.lang.String simpleClassName(java.lang.Object o)
simpleClassName(o.getClass())
.public static java.lang.String simpleClassName(java.lang.Class<?> clazz)
Class
. Similar to Class.getSimpleName()
, but it works fine
with anonymous classes.public static java.lang.CharSequence escapeCsv(java.lang.CharSequence value)
value
- The value which will be escaped according to
RFC-4180CharSequence
the escaped value if necessary, or the value unchangedpublic static java.lang.CharSequence escapeCsv(java.lang.CharSequence value, boolean trimWhiteSpace)
public static java.lang.CharSequence unescapeCsv(java.lang.CharSequence value)
value
- The escaped CSV field which will be unescaped according to
RFC-4180CharSequence
the unescaped value if necessary, or the value unchangedpublic static java.util.List<java.lang.CharSequence> unescapeCsvFields(java.lang.CharSequence value)
value
- A string with multiple CSV escaped fields which will be unescaped according to
RFC-4180List
the list of unescaped fieldsprivate static void validateCsvFormat(java.lang.CharSequence value)
value
is a valid csv field without double-quotes.java.lang.IllegalArgumentException
- if value
needs to be encoded with double-quotes.private static java.lang.IllegalArgumentException newInvalidEscapedCsvFieldException(java.lang.CharSequence value, int index)
public static int length(java.lang.String s)
null
input is considered 0
length.public static boolean isNullOrEmpty(java.lang.String s)
null
or String.isEmpty()
returns true
.public static int indexOfNonWhiteSpace(java.lang.CharSequence seq, int offset)
s
starting at offset
.seq
- The string to search.offset
- The offset to start searching at.0
if none was found.public static boolean isSurrogate(char c)
c
lies within the range of values defined for
Surrogate Code Point.c
- the character to check.true
if c
lies within the range of values defined for
Surrogate Code Point. false
otherwise.private static boolean isDoubleQuote(char c)
public static boolean endsWith(java.lang.CharSequence s, char c)
s
ends with the char c
.s
- the string to testc
- the tested chars
ends with the char c
public static java.lang.CharSequence trimOws(java.lang.CharSequence value)
value
- the value to trimCharSequence
the trimmed value if necessary, or the value unchangedprivate static int indexOfFirstNonOwsChar(java.lang.CharSequence value, int length)
length
if no OWS is found.private static int indexOfLastNonOwsChar(java.lang.CharSequence value, int start, int length)
start
if no OWS is found.private static boolean isOws(char c)