public class StringUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AMP_ENCODE |
static java.lang.String |
APOS_ENCODE |
static java.lang.String |
GT_ENCODE |
static char[] |
HEX_CHARS |
static java.lang.String |
LT_ENCODE |
static java.lang.String |
MD5 |
static java.lang.String |
QUOTE_ENCODE |
static java.lang.String |
SHA1 |
static java.lang.String |
USASCII |
static java.lang.String |
UTF8 |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
collectionToString(java.util.Collection<? extends java.lang.Object> collection)
Transform a collection of objects to a whitespace delimited String.
|
static java.lang.String |
encodeHex(byte[] bytes)
Encodes an array of bytes as String representation of hexadecimal.
|
static java.lang.CharSequence |
escapeForXml(java.lang.CharSequence input)
Escape
input for XML. |
static java.lang.CharSequence |
escapeForXML(java.lang.CharSequence input)
Deprecated.
use
escapeForXml(CharSequence) instead. |
static java.lang.CharSequence |
escapeForXmlAttribute(java.lang.CharSequence input)
Escape
input for XML. |
static java.lang.CharSequence |
escapeForXmlAttributeApos(java.lang.CharSequence input)
Escape
input for XML. |
static java.lang.CharSequence |
escapeForXmlText(java.lang.CharSequence input)
Escape
input for XML. |
static java.lang.String |
hash(java.lang.String data)
Deprecated.
use
SHA1.hex(String) instead. |
static java.lang.String |
insecureRandomString(int length)
Returns a random String of numbers and letters (lower and upper case)
of the specified length.
|
static boolean |
isEmpty(java.lang.CharSequence cs)
Returns true if the given CharSequence is empty.
|
static boolean |
isNotEmpty(java.lang.CharSequence... css)
Returns true if all given CharSequences are not empty.
|
static boolean |
isNotEmpty(java.lang.CharSequence cs)
Returns true if CharSequence is not null and is not empty, false otherwise.
|
static boolean |
isNullOrEmpty(java.lang.CharSequence... css)
Returns true if all given CharSequences are either null or empty.
|
static boolean |
isNullOrEmpty(java.lang.CharSequence cs)
Returns true if the given CharSequence is null or empty.
|
static java.lang.String |
maybeToString(java.lang.CharSequence cs)
Return the String representation of the given char sequence if it is not null.
|
static int |
nullSafeCharSequenceComparator(java.lang.CharSequence csOne,
java.lang.CharSequence csTwo) |
static boolean |
nullSafeCharSequenceEquals(java.lang.CharSequence csOne,
java.lang.CharSequence csTwo) |
static java.lang.String |
randomString(int length) |
static <CS extends java.lang.CharSequence> |
requireNotNullOrEmpty(CS cs,
java.lang.String message) |
static java.lang.String |
returnIfNotEmptyTrimmed(java.lang.String string) |
static byte[] |
toBytes(java.lang.String string) |
static java.lang.StringBuilder |
toStringBuilder(java.util.Collection<? extends java.lang.Object> collection,
java.lang.String delimiter)
Transform a collection of objects to a delimited String.
|
public static final java.lang.String MD5
public static final java.lang.String SHA1
public static final java.lang.String UTF8
public static final java.lang.String USASCII
public static final java.lang.String QUOTE_ENCODE
public static final java.lang.String APOS_ENCODE
public static final java.lang.String AMP_ENCODE
public static final java.lang.String LT_ENCODE
public static final java.lang.String GT_ENCODE
public static final char[] HEX_CHARS
public StringUtils()
@Deprecated public static java.lang.CharSequence escapeForXML(java.lang.CharSequence input)
escapeForXml(CharSequence)
instead.input
for XML.input
- the input to escape.input
.public static java.lang.CharSequence escapeForXml(java.lang.CharSequence input)
input
for XML.input
- the input to escape.input
.public static java.lang.CharSequence escapeForXmlAttribute(java.lang.CharSequence input)
input
for XML.input
- the input to escape.input
.public static java.lang.CharSequence escapeForXmlAttributeApos(java.lang.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 java.lang.CharSequence escapeForXmlText(java.lang.CharSequence input)
input
for XML.input
- the input to escape.input
.@Deprecated public static java.lang.String hash(java.lang.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 java.lang.String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex string.public static byte[] toBytes(java.lang.String string)
public static java.lang.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 java.lang.String randomString(int length)
public static boolean isNotEmpty(java.lang.CharSequence cs)
cs
- checked CharSequencepublic static boolean isNullOrEmpty(java.lang.CharSequence cs)
cs
- public static boolean isNotEmpty(java.lang.CharSequence... css)
css
- the CharSequences to test.public static boolean isNullOrEmpty(java.lang.CharSequence... css)
css
- the CharSequences to test.public static boolean isEmpty(java.lang.CharSequence cs)
cs
- public static java.lang.String collectionToString(java.util.Collection<? extends java.lang.Object> collection)
collection
- the collection to transform.public static java.lang.StringBuilder toStringBuilder(java.util.Collection<? extends java.lang.Object> collection, java.lang.String delimiter)
collection
- the collection to transform.delimiter
- the delimiter used to delimit the Strings.public static java.lang.String returnIfNotEmptyTrimmed(java.lang.String string)
public static boolean nullSafeCharSequenceEquals(java.lang.CharSequence csOne, java.lang.CharSequence csTwo)
public static int nullSafeCharSequenceComparator(java.lang.CharSequence csOne, java.lang.CharSequence csTwo)
public static <CS extends java.lang.CharSequence> CS requireNotNullOrEmpty(CS cs, java.lang.String message)
public static java.lang.String maybeToString(java.lang.CharSequence cs)
cs
- the char sequence or null.cs
or null.