Class StringUtils

java.lang.Object
com.cloudinary.utils.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

    Modifier and Type Method Description
    static java.lang.String emptyIfNull​(java.lang.String str)
    Returns empty string value when passed string value is null or empty, the passed string itself otherwise.
    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 java.util.List<java.lang.String> getAllSubStringWithSize​(java.lang.String text, int n)
    Break string into groups of n size strings
    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 padStart​(java.lang.String inputString, int length, char paddingCharacter)
    Returns the padded string with requested character to the left with length equals to length param sent.
    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 boolean startWithVersionString​(java.lang.String publicId)
    Checks whether a publicId starts a versioning string (v + number, e.g.
    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 Details

  • Constructor Details

  • Method Details

    • 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 characters
      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.
    • startWithVersionString

      public static boolean startWithVersionString​(java.lang.String publicId)
      Checks whether a publicId starts a versioning string (v + number, e.g. v12345)
      Parameters:
      publicId - The url to check
      Returns:
      Whether a version string is contained within the publicId
    • 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.
    • emptyIfNull

      public static java.lang.String emptyIfNull​(java.lang.String str)
      Returns empty string value when passed string value is null or empty, the passed string itself otherwise.
      Parameters:
      str - string value to evaluate
      Returns:
      passed string value or empty string, if the passed string is null or empty
    • padStart

      public static java.lang.String padStart​(java.lang.String inputString, int length, char paddingCharacter)
      Returns the padded string with requested character to the left with length equals to length param sent.
      Parameters:
      inputString - The string to process
      length - The requested length to pad to
      paddingCharacter - The requested character to pad with
      Returns:
      reversed array of string or empty array, if the passed array is null or empty
    • getAllSubStringWithSize

      public static java.util.List<java.lang.String> getAllSubStringWithSize​(java.lang.String text, int n)
      Break string into groups of n size strings
      Parameters:
      text - The string to process
      n - Size of group
      Returns:
      List with all strings with group size n.