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 Details

    • isEmpty

      public static boolean isEmpty(String string)
      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

      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
    • base64UrlEncoding

      public static String base64UrlEncoding(String url)
      Decode a given URL to a Base64 String.
      Parameters:
      url - as String
      Returns:
      decodedUrl as String
    • base64UrlDecoding

      public static String base64UrlDecoding(String base64Url)
      Encode from a Base64 back to a readable URL.
      Parameters:
      base64Url - as byte[]
      Returns:
      encodedUrl 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:
      escapedXml 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:
      shrinked content as String
    • skipBom

      public static String skipBom(String content)
      Detect and remove the (BOM) Byte Order Mark from a string.
      Parameters:
      content - as String
      Returns:
      utf-8 String
    • createDateFromString

      public static Date createDateFromString(String timestamp) throws ParseException
      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