Class StringUtils

java.lang.Object
org.apache.maven.surefire.util.internal.StringUtils

public final class StringUtils extends Object

Common java.lang.String manipulation routines.


Originally from Turbine and the GenerationJavaCore library.


NOTE: This class is not part of any api and is public purely for technical reasons !
Since:
1.0
Version:
$Id: StringUtils.java 8001 2009-01-03 13:17:09Z vsiveton $
Author:
Jon S. Stevens, Daniel Rall, Greg Coladonato, Henri Yandell, Ed Korthof, Rand McNeely, Stephen Colebourne, Fredrik Westermarck, Holger Krauth, Alexander Day Chaffee, Vincent Siveton
  • Field Details

    • NL

      public static final String NL
    • US_ASCII

      public static final Charset US_ASCII
      TODO Use JDK7 StandardCharsets
    • ISO_8859_1

      public static final Charset ISO_8859_1
    • UTF_8

      public static final Charset UTF_8
  • Method Details

    • split

      public static String[] split(String text, String separator)
    • isBlank

      public static boolean isBlank(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(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(StringBuilder target, 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.
    • unescapeString

      public static void unescapeString(StringBuilder target, CharSequence str)
      Parameters:
      target - target string buffer
      str - the String to un-escape, as created by escapeToPrintable(StringBuilder, CharSequence)
    • 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:
      NullPointerException - if the specified parameter header or input is null
      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 ByteBuffer unescapeBytes(String str, String charsetName)
      Parameters:
      str - the input String
      charsetName - the charset name
      Returns:
      the number of bytes written to out
    • encodeStringForForkCommunication

      public static byte[] encodeStringForForkCommunication(String string)
    • startsWith

      public static boolean startsWith(StringBuffer buffer, 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.