public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
SHORTEN_END |
static int |
SHORTEN_MIDDLE |
static int |
SHORTEN_START |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
bytesToHex(byte[] bytes)
Convert an array of arbitrary bytes into a String of hexadecimal number-pairs with each pair representing on byte
of the array.
|
static byte[] |
hexToBytes(String hex)
Convert a string consisting of hex-numbers into an array of bytes, which contains the binary representation of
those hexadecimal-numbers (takes pairs of numbers, so make sure the number of characters is even).
|
static boolean |
isEmpty(String text)
Universal check on String-objects that even works on non-instantiated variables (null-references), as it checks for
null first.
|
static String |
md5Hash(String text)
Compute the MD-5 hash of a string, and return it has a string of hexadecimal numbers.
|
static int |
md5HashInt(String text)
Compute the MD-5 hash of a string, and return a truncated int-value of the hash.
|
static long |
md5HashLong(String text)
Compute the MD-5 hash of a string, and return a truncated long-value of the hash.
|
static String |
sha1Hash(String text)
Compute the SHA-1 hash of a string, and return it has a string of hexadecimal numbers.
|
static int |
sha1HashInt(String text)
Compute the SHA-1 hash of a string, and return a truncated int-value of the hash.
|
static long |
sha1HashLong(String text)
Compute the SHA-1 hash of a string, and return a truncated long-value of the hash.
|
static String |
shorten(String text,
int size,
int mode)
Shortens a given String "text" down to size length, indicating the shortening by three dots ("...").
|
static int |
truncateHashToInt(byte[] bytes)
Computes a truncated code from the given hash-value and returns it as int-variable.
|
static int |
truncateHashToInt(String hash)
Computes a truncated code from the given hash-value and returns it as int-variable.
|
static long |
truncateHashToLong(byte[] bytes)
Computes a truncated code from the given hash-value and returns it as long-variable.
|
static long |
truncateHashToLong(String hash)
Computes a truncated code from the given hash-value and returns it as long-variable.
|
public static final int SHORTEN_START
public static final int SHORTEN_MIDDLE
public static final int SHORTEN_END
public static boolean isEmpty(String text)
text
- The string-object to be checkedpublic static String bytesToHex(byte[] bytes)
bytes
- the array to convert into hexadecimal stringpublic static byte[] hexToBytes(String hex)
hex
- String of pairs of hexadecimal numberspublic static String sha1Hash(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofNoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int sha1HashInt(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofNoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static long sha1HashLong(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofNoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static String md5Hash(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofNoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int md5HashInt(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofNoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static long md5HashLong(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofNoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundUnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int truncateHashToInt(String hash)
hash
- the hash-stringpublic static int truncateHashToInt(byte[] bytes)
bytes
- hash-value as a byte-arraypublic static long truncateHashToLong(String hash)
hash
- the hash-stringpublic static long truncateHashToLong(byte[] bytes)
bytes
- the hash-value as a byte-arraypublic static String shorten(String text, int size, int mode)
text
- The string to shortensize
- The size the text is to shortened to.mode
- The mode in which the string shall be shortenedCopyright © 2015. All Rights Reserved.