Class StringUtils
java.lang.Object
org.apache.maven.surefire.util.internal.StringUtils
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 ClassesModifier and TypeClassDescriptionstatic final class
Escaped string to byte array with offset 0 and certain length. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
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
(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.static boolean
Checks if a (trimmed) String isnull
or blank.static boolean
isNotBlank
(String str) Checks if a (trimmed) String is notnull
and not blank.static String[]
static boolean
startsWith
(StringBuffer buffer, String pattern) Determines ifbuffer
starts with specific literal(s).static ByteBuffer
unescapeBytes
(String str, String charsetName) Reverses the effect ofescapeBytesToPrintable(byte[], byte[], int, int)
.static void
unescapeString
(StringBuilder target, CharSequence str) Reverses the effect ofescapeToPrintable(StringBuilder, CharSequence)
.
-
Field Details
-
NL
-
US_ASCII
TODO Use JDK7 StandardCharsets -
ISO_8859_1
-
UTF_8
-
-
Method Details
-
split
-
isBlank
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
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
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
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:
NullPointerException
- if the specified parameterheader
orinput
is nullIndexOutOfBoundsException
- ifoff
orlen
is out of range (off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length
)
-
unescapeBytes
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
-
startsWith
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.
-