Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String EMPTY  
      protected static char[] hexArray  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encodeHexString​(byte[] bytes)
      Convert an array of bytes to a string of hex values
      static java.lang.String escapeHtml​(java.lang.String input)
      Method for html escaping a String
      static boolean hasVersionString​(java.lang.String url)
      Checks whether the url contains a versioning string (v + number, e.g.
      static byte[] hexStringToByteArray​(java.lang.String s)
      Convert a string of hex values to an array of bytes
      static boolean isBlank​(java.lang.String input)
      Verify that the input is an empty string or contains only whitespace characters.
      see Character.isWhitespace(char)
      static boolean isEmpty​(java.lang.String input)
      Verify that the input has no characters
      static boolean isHttpUrl​(java.lang.String s)
      Check if the given string starts with http:// or https://
      static boolean isNotBlank​(java.lang.Object input)
      Verify that the input has non whitespace characters in it
      static boolean isNotBlank​(java.lang.String input)
      Verify that the input has non whitespace characters in it
      static boolean isRemoteUrl​(java.lang.String file)  
      static boolean isVariable​(java.lang.String s)
      Checks whether the String fits the template for a transformation variable - $[a-zA-Z][a-zA-Z0-9]+ e.g.
      static java.lang.String join​(java.lang.Object[] array, java.lang.String separator)
      Join a array of Strings
      static java.lang.String join​(java.lang.Object[] array, java.lang.String separator, int startIndex, int endIndex)
      Join a array of Strings from startIndex to endIndex
      static java.lang.String join​(java.util.Collection<java.lang.String> collection, java.lang.String separator)
      Join a collection of Strings
      static java.lang.String join​(java.util.List<java.lang.String> list, java.lang.String separator)
      Join a list of Strings
      static java.lang.String mergeSlashesInUrl​(java.lang.String url)
      Merges all occurrences of multiple slashes into a single slash (e.g.
      static java.lang.String mergeToSingleUnderscore​(java.lang.String s)
      Merge all consecutive underscores and spaces into a single underscore, e.g.
      static java.lang.String read​(java.io.InputStream in)
      Read the entire input stream in 1KB chunks
      static java.lang.String removeStartingChars​(java.lang.String s, char c)
      Remove all consecutive chars c from the beginning of the string
      static java.lang.String replaceIfFirstChar​(java.lang.String s, char c, java.lang.String replacement)
      Replaces the char c in the string S, if it's the first character in the string.
      static java.lang.String urlEncode​(java.lang.String url, java.util.regex.Pattern unsafe, java.nio.charset.Charset charset)
      Replaces the unsafe characters in url with url-encoded values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • hexArray

        protected static final char[] hexArray
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • join

        public static java.lang.String join​(java.util.List<java.lang.String> list,
                                            java.lang.String separator)
        Join a list of Strings
        Parameters:
        list - strings to join
        separator - the separator to insert between the strings
        Returns:
        a string made of the strings in list separated by separator
      • join

        public static java.lang.String join​(java.lang.Object[] array,
                                            java.lang.String separator)
        Join a array of Strings
        Parameters:
        array - strings to join
        separator - the separator to insert between the strings
        Returns:
        a string made of the strings in array separated by separator
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> collection,
                                            java.lang.String separator)
        Join a collection of Strings
        Parameters:
        collection - strings to join
        separator - the separator to insert between the strings
        Returns:
        a string made of the strings in collection separated by separator
      • join

        public static java.lang.String join​(java.lang.Object[] array,
                                            java.lang.String separator,
                                            int startIndex,
                                            int endIndex)
        Join a array of Strings from startIndex to endIndex
        Parameters:
        array - strings to join
        separator - the separator to insert between the strings
        startIndex - the string to start from
        endIndex - the last string to join
        Returns:
        a string made of the strings in array separated by separator
      • encodeHexString

        public static java.lang.String encodeHexString​(byte[] bytes)
        Convert an array of bytes to a string of hex values
        Parameters:
        bytes - bytes to convert
        Returns:
        a string of hex values.
      • hexStringToByteArray

        public static byte[] hexStringToByteArray​(java.lang.String s)
        Convert a string of hex values to an array of bytes
        Parameters:
        s - a string of two digit Hex numbers. The length of string to parse must be even.
        Returns:
        bytes representation of the string
      • escapeHtml

        public static java.lang.String escapeHtml​(java.lang.String input)
        Method for html escaping a String
        Parameters:
        input - The String to escape
        Returns:
        The escaped String
        See Also:
        HtmlEscape.escapeTextArea(String)
      • isNotBlank

        public static boolean isNotBlank​(java.lang.Object input)
        Verify that the input has non whitespace characters in it
        Parameters:
        input - a String-like object
        Returns:
        true if input has non whitespace characters in it
      • isNotBlank

        public static boolean isNotBlank​(java.lang.String input)
        Verify that the input has non whitespace characters in it
        Parameters:
        input - a String
        Returns:
        true if input has non whitespace characters in it
      • isEmpty

        public static boolean isEmpty​(java.lang.String input)
        Verify that the input has no characters
        Parameters:
        input - a string
        Returns:
        true if input is null or has no characters
      • isBlank

        public static boolean isBlank​(java.lang.String input)
        Verify that the input is an empty string or contains only whitespace characters.
        see Character.isWhitespace(char)
        Parameters:
        input - a string
        Returns:
        true if input is an empty string or contains only whitespace characters
      • read

        public static java.lang.String read​(java.io.InputStream in)
                                     throws java.io.IOException
        Read the entire input stream in 1KB chunks
        Parameters:
        in - input stream to read from
        Returns:
        a String generated from the input stream
        Throws:
        java.io.IOException - thrown by the input stream
      • isRemoteUrl

        public static boolean isRemoteUrl​(java.lang.String file)
      • urlEncode

        public static java.lang.String urlEncode​(java.lang.String url,
                                                 java.util.regex.Pattern unsafe,
                                                 java.nio.charset.Charset charset)
        Replaces the unsafe characters in url with url-encoded values. This is based on URLEncoder.encode(String, String)
        Parameters:
        url - The url to encode
        unsafe - Regex pattern of unsafe caracters
        charset -
        Returns:
        An encoded url string
      • mergeToSingleUnderscore

        public static java.lang.String mergeToSingleUnderscore​(java.lang.String s)
        Merge all consecutive underscores and spaces into a single underscore, e.g. "ab___c_ _d" becomes "ab_c_d"
        Parameters:
        s - String to process
        Returns:
        The resulting string.
      • isVariable

        public static boolean isVariable​(java.lang.String s)
        Checks whether the String fits the template for a transformation variable - $[a-zA-Z][a-zA-Z0-9]+ e.g. $a4, $Bd, $abcdef, etc
        Parameters:
        s - The string to test
        Returns:
        Whether it's a variable or not
      • replaceIfFirstChar

        public static java.lang.String replaceIfFirstChar​(java.lang.String s,
                                                          char c,
                                                          java.lang.String replacement)
        Replaces the char c in the string S, if it's the first character in the string.
        Parameters:
        s - The string to search
        c - The character to replace
        replacement - The string to replace the character in S
        Returns:
        The string with the character replaced (or the original string if the char is not found)
      • isHttpUrl

        public static boolean isHttpUrl​(java.lang.String s)
        Check if the given string starts with http:// or https://
        Parameters:
        s - The string to check
        Returns:
        Whether it's an http url or not
      • removeStartingChars

        public static java.lang.String removeStartingChars​(java.lang.String s,
                                                           char c)
        Remove all consecutive chars c from the beginning of the string
        Parameters:
        s - String to process
        c - Char to search for
        Returns:
        The string stripped from the starting chars.
      • hasVersionString

        public static boolean hasVersionString​(java.lang.String url)
        Checks whether the url contains a versioning string (v + number, e.g. v12345)
        Parameters:
        url - The url to check
        Returns:
        Whether a version string is contained within the url
      • mergeSlashesInUrl

        public static java.lang.String mergeSlashesInUrl​(java.lang.String url)
        Merges all occurrences of multiple slashes into a single slash (e.g. "a///b//c/d" becomes "a/b/c/d")
        Parameters:
        url - The string to process
        Returns:
        The resulting string with merged slashes.