Class StringUtils
- java.lang.Object
-
- org.apache.maven.surefire.util.internal.StringUtils
-
public final class StringUtils extends java.lang.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
-
-
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 StandardCharsetsstatic 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 arrayinput
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 isnull
or blank.static boolean
isNotBlank(java.lang.String str)
Checks if a (trimmed) String is notnull
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 ifbuffer
starts with specific literal(s).static java.nio.ByteBuffer
unescapeBytes(java.lang.String str, java.lang.String charsetName)
Reverses the effect ofescapeBytesToPrintable(byte[], byte[], int, int)
.static void
unescapeString(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
null
or blank.- Parameters:
str
- the String to check- Returns:
true
if the String isnull
, 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 notnull
and length of trimmedstr
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 tostr.getBytes().length * 5
chars.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)
-
escapeBytesToPrintable
public static StringUtils.EncodedArray escapeBytesToPrintable(byte[] header, byte[] input, int off, int len)
Escapes the bytes in the arrayinput
to 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 sequenceheader
and 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 parameterheader
orinput
is nulljava.lang.IndexOutOfBoundsException
- ifoff
orlen
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)
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 ifbuffer
starts with specific literal(s).- Parameters:
buffer
- Examined StringBufferpattern
- a pattern which should start inbuffer
- Returns:
true
if buffer's literal starts with givenpattern
, or both are empty.
-
-