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 java.lang.String |
LT_ENCODE |
static java.lang.String |
QUOTE_ENCODE |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
collectionToString(java.util.Collection<java.lang.String> collection) |
static byte[] |
decodeBase64(java.lang.String data)
Decodes a base64 String.
|
static java.lang.String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String.
|
static java.lang.String |
encodeBase64(byte[] data,
boolean lineBreaks)
Encodes a byte array into a bse64 String.
|
static java.lang.String |
encodeBase64(byte[] data,
int offset,
int len,
boolean lineBreaks)
Encodes a byte array into a bse64 String.
|
static java.lang.String |
encodeBase64(java.lang.String data)
Encodes a String as a base64 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.String string)
Escapes all necessary characters in the String so that it can be used
in an XML doc.
|
static java.lang.String |
hash(java.lang.String data)
Hashes a String using the SHA-1 algorithm and returns the result as a
String of hexadecimal numbers.
|
static boolean |
isNotEmpty(java.lang.CharSequence cs)
Returns true if CharSequence is not null and is not empty, false otherwise
Examples:
isNotEmpty(null) - false
isNotEmpty("") - false
isNotEmpty(" ") - true
isNotEmpty("empty") - true
|
static boolean |
isNullOrEmpty(java.lang.CharSequence cs)
Returns true if the given CharSequence is not null or empty.
|
static java.lang.String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case)
of the specified length.
|
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 java.lang.CharSequence escapeForXML(java.lang.String string)
string
- the string to escape.public static java.lang.String hash(java.lang.String data)
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 java.lang.String encodeBase64(java.lang.String data)
data
- a String to encode.public static java.lang.String encodeBase64(byte[] data)
data
- a byte array to encode.public static java.lang.String encodeBase64(byte[] data, boolean lineBreaks)
data
- The byte arry to encode.lineBreaks
- True if the encoding should contain line breaks and false if it should not.public static java.lang.String encodeBase64(byte[] data, int offset, int len, boolean lineBreaks)
data
- The byte arry to encode.offset
- the offset of the bytearray to begin encoding at.len
- the length of bytes to encode.lineBreaks
- True if the encoding should contain line breaks and false if it should not.public static byte[] decodeBase64(java.lang.String data)
data
- a base64 encoded String to decode.public static java.lang.String randomString(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 boolean isNotEmpty(java.lang.CharSequence cs)
cs
- checked CharSequencepublic static boolean isNullOrEmpty(java.lang.CharSequence cs)
cs
- public static java.lang.String collectionToString(java.util.Collection<java.lang.String> collection)