Class StringUtils

java.lang.Object
is.galia.util.StringUtils

public final class StringUtils extends Object
  • Field Details

  • Method Details

    • decodeSlashes

      public static String decodeSlashes(String uriPathComponent)
      Some web servers have issues dealing with encoded slashes ( %2F) in URIs. This method enables the use of an alternate string to represent a slash via Key.SLASH_SUBSTITUTE.
      Parameters:
      uriPathComponent - Path component (a part of the path before, after, or between slashes).
      Returns:
      Path component with slashes decoded.
      See Also:
    • encodeSlashes

      public static String encodeSlashes(String uriPathComponent)
      Parameters:
      uriPathComponent - URI path component, not yet URL-encoded.
      Returns:
      Path component with slashes substituted.
      See Also:
    • escapeHTML

      public static String escapeHTML(String html)
    • fromByteSize

      public static String fromByteSize(long byteSize)
      Parameters:
      byteSize - Size in bytes.
      Returns:
      String with unit suffix.
    • md5

      public static String md5(String str)
      Parameters:
      str - String to hash.
      Returns:
      Lowercase MD5 checksum string.
    • randomAlphanumeric

      public static String randomAlphanumeric(int length)
      Parameters:
      length - Length of the string.
      Returns:
      Random alphanumeric string.
    • removeTrailingZeroes

      public static String removeTrailingZeroes(double d)
      Returns:
      String representation of the given number with trailing zeroes removed.
    • reverse

      public static String reverse(String str)
      Parameters:
      str - String to reverse.
      Returns:
      Reversed string.
    • sanitize

      public static String sanitize(String dirty, String... removeables)
      Recursively filters out removeables from the given dirty string.
      Returns:
      Sanitized string.
    • sanitize

      public static String sanitize(String dirty, Pattern... removeables)
      Recursively filters out removeables from the given dirty string, replacing it with replacement.
      Returns:
      Sanitized string.
    • stripEnd

      public static String stripEnd(String str, String toStrip)
      Strips a string from the end of another string.
      Parameters:
      str - String to search.
      toStrip - String to strip off the end of the search string.
    • stripStart

      public static String stripStart(String str, String toStrip)
      Strips a string from the beginning of another string.
      Parameters:
      str - String to search.
      toStrip - String to strip off the beginning of the search string.
    • toBoolean

      public static boolean toBoolean(String str)
      Converts a string to a boolean. 1 and true are accepted as true; 0 and false as false. All other arguments throw a NumberFormatException, in contrast to Boolean.parseBoolean(String), which treats all non-true values as false.
      Parameters:
      str - String to convert.
      Returns:
      Boolean value of the given string.
      Throws:
      NumberFormatException - if the string has an unrecognized format.
    • toByteSize

      public static long toByteSize(String str)
      The following byte size formats are supported:
      • Whole number
      • Decimal number suffixed with K, KB, M, MB, G, GB, T, TB, P, PB
        • Lowercase suffixes are allowed.
        • Spaces are allowed between the number and suffix.
      Parameters:
      str - String byte size.
      Returns:
      If the given string had no units, a long representation. Otherwise, a power of 1024.
    • toHex

      public static String toHex(byte[] bytes)
      Parameters:
      bytes - Bytes to print.
      Returns:
      Lowercase hexadecimal string.
    • wrap

      public static List<String> wrap(String str, FontMetrics fm, int maxWidth)
      Returns an array of strings, one for each line in the string after it has been wrapped to fit lines of maxWidth. Lines end with any of CR, LF, or CRLF. A line ending at the end of the string will not output a further, empty string.
      Parameters:
      str - The string to split. Must not be null.
      fm - Used for string width calculations.
      maxWidth - The max line width, in points.
      Returns:
      List of strings.