Package org.europa.together.utils
Class StringUtils
- java.lang.Object
-
- org.europa.together.utils.StringUtils
-
public final class StringUtils extends Object
Some useful Methods for String manipulation, Hash and UUID generation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbyteToString(byte[] bytes)Create a String from a given ByteArray.static StringconcatString(String... strings)Concatenate a list of Strings using StringBuilder.static StringescapeXmlCharacters(String content)Escape (decode) in a String all special Characters for XML to thir equivalent representation.static StringgenerateLoremIpsum(int chars)Produce a lorem ipsum Text with 4 paragraphs and 2100 characters.static StringgenerateStringOfLength(int length)Creates a String of specified length with the content of numbers.static StringgenerateUUID()Generates an universally unique identifier (UUID).static inthashToInt(String hash)Convert a Hash String to an Integer.static booleanisEmpty(String string)Test a String if is Empty or NULL.static Stringshrink(String content)Shrink XML, JS and CSS Files to reduce the payload for network traffic.static StringskipBom(String content)Detect and remove the (BOM) Byte Order Mark from a string.static List<String>stringListBuilder(String... strings)Creates a List with Strings entries in a short way.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(String string)
Test a String if 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 if the string is empty or null
-
hashToInt
public static int hashToInt(String hash)
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
public static List<String> stringListBuilder(String... strings)
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
public static String byteToString(byte[] bytes)
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
public static String concatString(String... strings)
Concatenate a list of Strings using StringBuilder.- Parameters:
strings- as String- Returns:
- string as string
-
escapeXmlCharacters
public static String escapeXmlCharacters(String content)
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:
- escapedHtml as String
-
generateLoremIpsum
public static String generateLoremIpsum(int chars)
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
public static String generateStringOfLength(int length)
Creates a String of specified length with the content of numbers. generateStringOfLength(13) = [0123456789012]- Parameters:
length- as int- Returns:
- string as String
-
generateUUID
public static 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
public static String shrink(String content)
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:
- shrink content as String
-
-