Class StringUtils
- java.lang.Object
-
- org.apache.maven.surefire.util.internal.StringUtils
-
public final class StringUtils extends java.lang.ObjectCommon
java.lang.Stringmanipulation 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 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringUtils.EncodedArrayEscaped string to byte array with offset 0 and certain length.
-
Field Summary
Fields Modifier and Type Field Description private static java.nio.charset.CharsetDEFAULT_CHARSETprivate static byte[]HEX_CHARSstatic java.lang.StringNL
-
Constructor Summary
Constructors Modifier Constructor Description privateStringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intdigit(char ch)static byte[]encodeStringForForkCommunication(java.lang.String string)static StringUtils.EncodedArrayescapeBytesToPrintable(byte[] header, byte[] input, int off, int len)Escapes the bytes in the arrayinputto contain only 'printable' bytes.static voidescapeToPrintable(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 booleanisBlank(java.lang.String str)Checks if a (trimmed) String isnullor blank.static booleanisNotBlank(java.lang.String str)Checks if a (trimmed) String is notnulland not blank.static java.lang.String[]split(java.lang.String text, java.lang.String separator)static booleanstartsWith(java.lang.StringBuffer buffer, java.lang.String pattern)Determines ifbufferstarts with specific literal(s).static java.nio.ByteBufferunescapeBytes(java.lang.String str, java.lang.String charsetName)Reverses the effect ofescapeBytesToPrintable(byte[], byte[], int, int).static voidunescapeString(java.lang.StringBuilder target, java.lang.CharSequence str)Reverses the effect ofescapeToPrintable(StringBuilder, CharSequence).
-
-
-
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
nullor blank.- Parameters:
str- the String to check- Returns:
trueif the String isnull, or length zero once trimmed
-
isNotBlank
public static boolean isNotBlank(java.lang.String str)
Checks if a (trimmed) String is not
nulland not blank.- Parameters:
str- the String to check- Returns:
trueif the String is notnulland length of trimmedstris 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 tostr.getBytes().length * 5chars.str- String to escape values in, may benull.
-
unescapeString
public static void unescapeString(java.lang.StringBuilder target, java.lang.CharSequence str)Reverses the effect ofescapeToPrintable(StringBuilder, CharSequence).- Parameters:
target- target string bufferstr- the String to un-escape, as created byescapeToPrintable(StringBuilder, CharSequence)
-
digit
private static int digit(char ch)
-
escapeBytesToPrintable
public static StringUtils.EncodedArray escapeBytesToPrintable(byte[] header, byte[] input, int off, int len)
Escapes the bytes in the arrayinputto contain only 'printable' bytes.
Escaping is done by encoding the non-nicely printable bytes to'\' + upperCaseHexBytes(byte).
The reverse-method isunescapeBytes(String, String).
The returned byte array is started with aligned sequenceheaderand finished by\n.- Parameters:
header- prefix headerinput- input bufferoff- offset in the input bufferlen- number of bytes to copy from the input buffer- Returns:
- number of bytes written to
out - Throws:
java.lang.NullPointerException- if the specified parameterheaderorinputis nulljava.lang.IndexOutOfBoundsException- ifofforlenis 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)Reverses the effect ofescapeBytesToPrintable(byte[], byte[], int, int).- Parameters:
str- the input StringcharsetName- 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 ifbufferstarts with specific literal(s).- Parameters:
buffer- Examined StringBufferpattern- a pattern which should start inbuffer- Returns:
trueif buffer's literal starts with givenpattern, or both are empty.
-
-