Class StringUtils


  • public final class StringUtils
    extends java.lang.Object
    String utils
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern HTML_PATTERN  
      static java.util.List<java.lang.String> RULES  
      static java.util.regex.Pattern UNPRINTABLE_PATTERN  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String checkSanityString​(java.lang.String value)
      Check external argument to avoid Path Traversal attack
      static void checkSanityString​(java.lang.String... strings)
      Check external argument
      static byte[] getBytesFromArraysToString​(java.lang.String bytesString)
      Revert Arrays.toString for bytes
      static java.lang.String getClassName​(java.lang.Object object)  
      static byte[] getRandom​(int length)  
      static java.lang.String getStringFromInputStream​(java.io.InputStream is)
      Get text content of an input stream
      static java.lang.String substringBeforeLast​(java.lang.String source, java.lang.String separator)
      Gets the substring before the last occurrence of a separator.
      static java.lang.String substringBetween​(java.lang.String source, java.lang.String start, java.lang.String end)
      Gets the String that is nested in between two Strings.
      • Methods inherited from class java.lang.Object

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

      • HTML_PATTERN

        public static final java.util.regex.Pattern HTML_PATTERN
      • UNPRINTABLE_PATTERN

        public static final java.util.regex.Pattern UNPRINTABLE_PATTERN
      • RULES

        public static final java.util.List<java.lang.String> RULES
    • Method Detail

      • getRandom

        public static final byte[] getRandom​(int length)
        Parameters:
        length - the length of rray
        Returns:
        a byte array with random values
      • getBytesFromArraysToString

        public static final byte[] getBytesFromArraysToString​(java.lang.String bytesString)
        Revert Arrays.toString for bytes
        Parameters:
        bytesString - the string to transform
        Returns:
        the array of bytes
        Throws:
        java.lang.IllegalArgumentException - if bytesString is null or empty
      • getClassName

        public static final java.lang.String getClassName​(java.lang.Object object)
        Parameters:
        object - to get its class name
        Returns:
        the short name of the Class of this object
      • substringBetween

        public static final java.lang.String substringBetween​(java.lang.String source,
                                                              java.lang.String start,
                                                              java.lang.String end)
        Gets the String that is nested in between two Strings. Only the first match is returned.
        Parameters:
        source -
        start -
        end -
        Returns:
        the substring, null if no match
      • substringBeforeLast

        public static final java.lang.String substringBeforeLast​(java.lang.String source,
                                                                 java.lang.String separator)
        Gets the substring before the last occurrence of a separator. The separator is not returned.
        Parameters:
        source -
        separator -
        Returns:
        the substring before the last occurrence of the separator, null if null String input
      • getStringFromInputStream

        public static java.lang.String getStringFromInputStream​(java.io.InputStream is)
                                                         throws java.io.IOException
        Get text content of an input stream
        Parameters:
        is - input stream
        Returns:
        text content
        Throws:
        java.io.IOException - when input stream unreadable