Class StringUtils

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  StringUtils.EncodedArray
      Escaped string to byte array with offset 0 and certain length.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.nio.charset.Charset ISO_8859_1  
      static java.lang.String NL  
      static java.nio.charset.Charset US_ASCII
      TODO Use JDK7 StandardCharsets
      static java.nio.charset.Charset UTF_8  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] encodeStringForForkCommunication​(java.lang.String string)  
      static StringUtils.EncodedArray escapeBytesToPrintable​(byte[] header, byte[] input, int off, int len)
      Escapes the bytes in the array input to contain only 'printable' bytes.
      static void escapeToPrintable​(java.lang.StringBuilder target, java.lang.CharSequence str)
      Escape the specified string to a representation that only consists of nicely printable characters, without any newlines and without a comma.
      static boolean isBlank​(java.lang.String str)
      Checks if a (trimmed) String is null or blank.
      static boolean isNotBlank​(java.lang.String str)
      Checks if a (trimmed) String is not null and not blank.
      static java.lang.String[] split​(java.lang.String text, java.lang.String separator)  
      static boolean startsWith​(java.lang.StringBuffer buffer, java.lang.String pattern)
      Determines if buffer starts with specific literal(s).
      static java.nio.ByteBuffer unescapeBytes​(java.lang.String str, java.lang.String charsetName)
      static void unescapeString​(java.lang.StringBuilder target, java.lang.CharSequence str)
      • Methods inherited from class java.lang.Object

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

      • NL

        public static final java.lang.String NL
      • US_ASCII

        public static final java.nio.charset.Charset US_ASCII
        TODO Use JDK7 StandardCharsets
      • ISO_8859_1

        public static final java.nio.charset.Charset ISO_8859_1
      • UTF_8

        public static final java.nio.charset.Charset UTF_8
    • Method Detail

      • split

        public static java.lang.String[] split​(java.lang.String text,
                                               java.lang.String separator)
      • isBlank

        public static boolean isBlank​(java.lang.String str)

        Checks if a (trimmed) String is null or blank.

        Parameters:
        str - the String to check
        Returns:
        true if the String is null, or length zero once trimmed
      • isNotBlank

        public static boolean isNotBlank​(java.lang.String str)

        Checks if a (trimmed) String is not null and not blank.

        Parameters:
        str - the String to check
        Returns:
        true if the String is not null and length of trimmed str is not zero.
      • escapeToPrintable

        public static void escapeToPrintable​(java.lang.StringBuilder target,
                                             java.lang.CharSequence str)
        Escape the specified string to a representation that only consists of nicely printable characters, without any newlines and without a comma.

        The reverse-method is unescapeString(StringBuilder, CharSequence).

        Parameters:
        target - target string buffer. The required space will be up to str.getBytes().length * 5 chars.
        str - String to escape values in, may be null.
      • escapeBytesToPrintable

        public static StringUtils.EncodedArray escapeBytesToPrintable​(byte[] header,
                                                                      byte[] input,
                                                                      int off,
                                                                      int len)
        Escapes the bytes in the array input to contain only 'printable' bytes.
        Escaping is done by encoding the non-nicely printable bytes to '\' + upperCaseHexBytes(byte).
        The reverse-method is unescapeBytes(String, String).
        The returned byte array is started with aligned sequence header and finished by \n.
        Parameters:
        header - prefix header
        input - input buffer
        off - offset in the input buffer
        len - number of bytes to copy from the input buffer
        Returns:
        number of bytes written to out
        Throws:
        java.lang.NullPointerException - if the specified parameter header or input is null
        java.lang.IndexOutOfBoundsException - if off or len is out of range (off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length)
      • unescapeBytes

        public static java.nio.ByteBuffer unescapeBytes​(java.lang.String str,
                                                        java.lang.String charsetName)
        Parameters:
        str - the input String
        charsetName - the charset name
        Returns:
        the number of bytes written to out
      • encodeStringForForkCommunication

        public static byte[] encodeStringForForkCommunication​(java.lang.String string)
      • startsWith

        public static boolean startsWith​(java.lang.StringBuffer buffer,
                                         java.lang.String pattern)
        Determines if buffer starts with specific literal(s).
        Parameters:
        buffer - Examined StringBuffer
        pattern - a pattern which should start in buffer
        Returns:
        true if buffer's literal starts with given pattern, or both are empty.