public class StringUtils
extends java.lang.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 java.lang.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 int |
countOccurrences(java.lang.String haystack,
char needle)
Counts the number of occurrences of the given character.
|
static int |
countOccurrences(java.lang.String haystack,
java.lang.String needle)
Counts the number of occurrences of the given character.
|
static byte[] |
hexToBytes(java.lang.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(java.lang.String text)
Universal check on String-objects that even works on non-instantiated variables (null-references), as it checks for
null first.
|
static java.lang.String |
md5Hash(java.lang.String text)
Compute the MD-5 hash of a string, and return it has a string of hexadecimal numbers.
|
static int |
md5HashInt(java.lang.String text)
Compute the MD-5 hash of a string, and return a truncated int-value of the hash.
|
static long |
md5HashLong(java.lang.String text)
Compute the MD-5 hash of a string, and return a truncated long-value of the hash.
|
static java.lang.String |
sha1Hash(java.lang.String text)
Compute the SHA-1 hash of a string, and return it has a string of hexadecimal numbers.
|
static int |
sha1HashInt(java.lang.String text)
Compute the SHA-1 hash of a string, and return a truncated int-value of the hash.
|
static long |
sha1HashLong(java.lang.String text)
Compute the SHA-1 hash of a string, and return a truncated long-value of the hash.
|
static java.lang.String |
shorten(java.lang.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(java.lang.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(java.lang.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(java.lang.String text)
text
- The string-object to be checkedpublic static java.lang.String bytesToHex(byte[] bytes)
bytes
- the array to convert into hexadecimal stringpublic static byte[] hexToBytes(java.lang.String hex)
hex
- String of pairs of hexadecimal numberspublic static java.lang.String sha1Hash(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofjava.security.NoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int sha1HashInt(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofjava.security.NoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static long sha1HashLong(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the SHA-1 hash ofjava.security.NoSuchAlgorithmException
- thrown if the SHA-1 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static java.lang.String md5Hash(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofjava.security.NoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int md5HashInt(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofjava.security.NoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static long md5HashLong(java.lang.String text) throws java.security.NoSuchAlgorithmException, java.io.UnsupportedEncodingException
text
- Text to compute the MD-5 hash ofjava.security.NoSuchAlgorithmException
- thrown if the MD-5 algorithm cannot be foundjava.io.UnsupportedEncodingException
- thrown if the encoding is not supportedpublic static int truncateHashToInt(java.lang.String hash)
hash
- the hash-stringpublic static int truncateHashToInt(byte[] bytes)
bytes
- hash-value as a byte-arraypublic static long truncateHashToLong(java.lang.String hash)
hash
- the hash-stringpublic static long truncateHashToLong(byte[] bytes)
bytes
- the hash-value as a byte-arraypublic static java.lang.String shorten(java.lang.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 shortenedpublic static int countOccurrences(java.lang.String haystack, char needle)
haystack
- The string in which to search for the given character.needle
- The character to search for.public static int countOccurrences(java.lang.String haystack, java.lang.String needle)
haystack
- The string in which to search for the given character.needle
- The character to search for.Copyright © 2015. All Rights Reserved.