public final class StringUtils extends Object
Common java.lang.String
manipulation routines.
Originally from Turbine and the GenerationJavaCore library.
Modifier and Type | Class and Description |
---|---|
static class |
StringUtils.EncodedArray
Escaped string to byte array with offset 0 and certain length.
|
Modifier and Type | Field and Description |
---|---|
static Charset |
ISO_8859_1 |
static String |
NL |
static Charset |
US_ASCII
TODO
Use JDK7 StandardCharsets
|
static Charset |
UTF_8 |
Modifier and Type | Method and Description |
---|---|
static byte[] |
encodeStringForForkCommunication(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(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 |
isBlank(String str)
Checks if a (trimmed) String is
null or blank. |
static boolean |
isNotBlank(String str)
Checks if a (trimmed) String is not
null and not blank. |
static String[] |
split(String text,
String separator) |
static boolean |
startsWith(StringBuffer buffer,
String pattern)
Determines if
buffer starts with specific literal(s). |
static ByteBuffer |
unescapeBytes(String str,
String charsetName)
Reverses the effect of
escapeBytesToPrintable(byte[], byte[], int, int) . |
static void |
unescapeString(StringBuilder target,
CharSequence str)
Reverses the effect of
escapeToPrintable(StringBuilder, CharSequence) . |
public static final String NL
public static final Charset US_ASCII
public static final Charset ISO_8859_1
public static final Charset UTF_8
public static boolean isBlank(String str)
Checks if a (trimmed) String is null
or blank.
str
- the String to checktrue
if the String is null
, or length zero once trimmedpublic static boolean isNotBlank(String str)
Checks if a (trimmed) String is not null
and not blank.
str
- the String to checktrue
if the String is not null
and length of trimmed str
is not zero.public static void escapeToPrintable(StringBuilder target, CharSequence str)
The reverse-method is unescapeString(StringBuilder, CharSequence)
.
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
.public static void unescapeString(StringBuilder target, CharSequence str)
escapeToPrintable(StringBuilder, CharSequence)
.target
- target string bufferstr
- the String to un-escape, as created by escapeToPrintable(StringBuilder, CharSequence)
public static StringUtils.EncodedArray escapeBytesToPrintable(byte[] header, byte[] input, int off, int len)
input
to contain only 'printable' bytes.
'\' + upperCaseHexBytes(byte)
.
unescapeBytes(String, String)
.
header
and finished by \n
.header
- prefix headerinput
- input bufferoff
- offset in the input bufferlen
- number of bytes to copy from the input bufferout
NullPointerException
- if the specified parameter header
or input
is nullIndexOutOfBoundsException
- if off
or len
is out of range
(off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length
)public static ByteBuffer unescapeBytes(String str, String charsetName)
escapeBytesToPrintable(byte[], byte[], int, int)
.str
- the input StringcharsetName
- the charset nameout
public static byte[] encodeStringForForkCommunication(String string)
public static boolean startsWith(StringBuffer buffer, String pattern)
buffer
starts with specific literal(s).buffer
- Examined StringBufferpattern
- a pattern which should start in buffer
true
if buffer's literal starts with given pattern
, or both are empty.Copyright © 2004–2018 The Apache Software Foundation. All rights reserved.