Package org.europa.together.utils
Class StringUtils
java.lang.Object
org.europa.together.utils.StringUtils
Some useful Methods for String manipulation, Hash and UUID generation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
base64UrlDecoding
(String base64Url) Encode from a Base64 back to a readable URL.static String
base64UrlEncoding
(String url) Decode a given URL to a Base64 String.static String
byteToString
(byte[] bytes) Create a String from a given ByteArray.static String
concatString
(String... strings) Concatenate a list of Strings using StringBuilder.static Date
createDateFromString
(String timestamp) Create from a given String for UTC in the format of yyyy-mm-dd HH:mm:ss a java.util.Date class.static String
escapeXmlCharacters
(String content) Escape (decode) in a String all special Characters for XML to thir equivalent representation.static String
generateLoremIpsum
(int chars) Produce a lorem ipsum text with 4 paragraphs and 2100 characters.static String
generateStringOfLength
(int length) Creates a String of specified length with the content of numbers.static String
Generates an universally unique identifier (UUID).static int
Convert a Hash String to an Integer.static boolean
Test a String if is empty or NULL.static String
Shrink XML, JS and CSS Files to reduce the payload for network traffic.static String
Detect and remove the (BOM) Byte Order Mark from a string.stringListBuilder
(String... strings) Creates a List with Strings entries in a short way.
-
Method Details
-
isEmpty
Test a String if is empty or NULL. Return TRUE when the String is empty or NULL. The test don't figure out when a Sting contains only non printable or whitespace characters.- Parameters:
string
- as String- Returns:
- true on success
-
hashToInt
Convert a Hash String to an Integer. Takes each character of the hash string, convert them to his ASCII number as int and add the result to a sum.- Parameters:
hash
- as String- Returns:
- hash as integer
-
stringListBuilder
Creates a List with Strings entries in a short way. Sample: List<String> list = new arrayList(); list.add("foo"); list.add("more");
is reduced to stringListBuilder("foo", "more");- Parameters:
strings
- as String- Returns:
- a List of Strings
-
byteToString
Create a String from a given ByteArray. Each character get converted to his UTF-8 hexadecimal expression. e.g. '#' -> "23"- Parameters:
bytes
- as byteArray- Returns:
- bytes as String
-
concatString
Concatenate a list of Strings using StringBuilder.- Parameters:
strings
- as String- Returns:
- string as String
-
base64UrlEncoding
Decode a given URL to a Base64 String.- Parameters:
url
- as String- Returns:
- decodedUrl as String
-
base64UrlDecoding
Encode from a Base64 back to a readable URL.- Parameters:
base64Url
- as byte[]- Returns:
- encodedUrl as String
-
escapeXmlCharacters
Escape (decode) in a String all special Characters for XML to thir equivalent representation. Characters: <, >, &, ', "
This replacement extend the security of a web Application against XSS and SQL Injections for user modified content.- Parameters:
content
- as String- Returns:
- escapedXml as String
-
generateLoremIpsum
Produce a lorem ipsum text with 4 paragraphs and 2100 characters. The parameter chars reduce the output to the given count of characters. To get the whole text set chars to 0.- Parameters:
chars
- as int- Returns:
- out as String
-
generateStringOfLength
Creates a String of specified length with the content of numbers. generateStringOfLength(13) = [0123456789012]- Parameters:
length
- as int- Returns:
- string as String
-
generateUUID
Generates an universally unique identifier (UUID). The UUID is a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator.- Returns:
- UUID as String
-
shrink
Shrink XML, JS and CSS Files to reduce the payload for network traffic. The shrinker removes comments and unnecessary whitespace and line breaks.- Parameters:
content
- as String- Returns:
- shrinked content as String
-
skipBom
Detect and remove the (BOM) Byte Order Mark from a string.- Parameters:
content
- as String- Returns:
- utf-8 String
-
createDateFromString
Create from a given String for UTC in the format of yyyy-mm-dd HH:mm:ss a java.util.Date class.- Parameters:
timestamp
- as Sting- Returns:
- timestamp as Date
- Throws:
ParseException
-