public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
AMP_ENCODE |
static String |
APOS_ENCODE |
static String |
GT_ENCODE |
static char[] |
HEX_CHARS |
static String |
LT_ENCODE |
static String |
MD5 |
static String |
QUOTE_ENCODE |
static String |
SHA1 |
static String |
USASCII |
static String |
UTF8 |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
collectionToString(Collection<? extends Object> collection)
Transform a collection of objects to a whitespace delimited String.
|
static String |
encodeHex(byte[] bytes)
Encodes an array of bytes as String representation of hexadecimal.
|
static CharSequence |
escapeForXml(CharSequence input)
Escape
input for XML. |
static CharSequence |
escapeForXmlAttribute(CharSequence input)
Escape
input for XML. |
static CharSequence |
escapeForXmlAttributeApos(CharSequence input)
Escape
input for XML. |
static CharSequence |
escapeForXmlText(CharSequence input)
Escape
input for XML. |
static String |
hash(String data)
Deprecated.
use
SHA1.hex(String) instead. |
static String |
insecureRandomString(int length)
Returns a random String of numbers and letters (lower and upper case)
of the specified length.
|
static boolean |
isEmpty(CharSequence cs)
Returns true if the given CharSequence is empty.
|
static boolean |
isNotEmpty(CharSequence... css)
Returns true if all given CharSequences are not empty.
|
static boolean |
isNotEmpty(CharSequence cs)
Returns true if CharSequence is not null and is not empty, false otherwise.
|
static boolean |
isNullOrEmpty(CharSequence... css)
Returns true if all given CharSequences are either null or empty.
|
static boolean |
isNullOrEmpty(CharSequence cs)
Returns true if the given CharSequence is null or empty.
|
static String |
maybeToString(CharSequence cs)
Return the String representation of the given char sequence if it is not null.
|
static int |
nullSafeCharSequenceComparator(CharSequence csOne,
CharSequence csTwo) |
static boolean |
nullSafeCharSequenceEquals(CharSequence csOne,
CharSequence csTwo) |
static String |
randomString(int length) |
static <CS extends CharSequence> |
requireNotNullOrEmpty(CS cs,
String message) |
static <CS extends CharSequence> |
requireNullOrNotEmpty(CS cs,
String message) |
static String |
returnIfNotEmptyTrimmed(String string) |
static StringBuilder |
toStringBuilder(Collection<? extends Object> collection,
String delimiter)
Transform a collection of objects to a delimited String.
|
static byte[] |
toUtf8Bytes(String string) |
public static final String MD5
public static final String SHA1
public static final String UTF8
public static final String USASCII
public static final String QUOTE_ENCODE
public static final String APOS_ENCODE
public static final String AMP_ENCODE
public static final String LT_ENCODE
public static final String GT_ENCODE
public static final char[] HEX_CHARS
public StringUtils()
public static CharSequence escapeForXml(CharSequence input)
input
for XML.input
- the input to escape.input
.public static CharSequence escapeForXmlAttribute(CharSequence input)
input
for XML.input
- the input to escape.input
.public static CharSequence escapeForXmlAttributeApos(CharSequence input)
input
for XML.
This is an optimized variant of escapeForXmlAttribute(CharSequence)
for XML where the
XML attribute is quoted using ''' (Apos).
input
- the input to escape.input
.public static CharSequence escapeForXmlText(CharSequence input)
input
for XML.input
- the input to escape.input
.@Deprecated public static String hash(String data)
SHA1.hex(String)
instead.A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.
data
- the String to compute the hash of.public static String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex string.public static byte[] toUtf8Bytes(String string)
public static String insecureRandomString(int length)
The specified length must be at least one. If not, the method will return null.
length
- the desired length of the random String to return.public static String randomString(int length)
public static boolean isNotEmpty(CharSequence cs)
cs
- checked CharSequencepublic static boolean isNullOrEmpty(CharSequence cs)
cs
- public static boolean isNotEmpty(CharSequence... css)
css
- the CharSequences to test.public static boolean isNullOrEmpty(CharSequence... css)
css
- the CharSequences to test.public static boolean isEmpty(CharSequence cs)
cs
- public static String collectionToString(Collection<? extends Object> collection)
collection
- the collection to transform.public static StringBuilder toStringBuilder(Collection<? extends Object> collection, String delimiter)
collection
- the collection to transform.delimiter
- the delimiter used to delimit the Strings.public static String returnIfNotEmptyTrimmed(String string)
public static boolean nullSafeCharSequenceEquals(CharSequence csOne, CharSequence csTwo)
public static int nullSafeCharSequenceComparator(CharSequence csOne, CharSequence csTwo)
public static <CS extends CharSequence> CS requireNotNullOrEmpty(CS cs, String message)
public static <CS extends CharSequence> CS requireNullOrNotEmpty(CS cs, String message)
public static String maybeToString(CharSequence cs)
cs
- the char sequence or null.cs
or null.