public final class StringUtils
extends java.lang.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 |
---|---|
private static java.nio.charset.Charset |
DEFAULT_CHARSET |
private static byte[] |
HEX_CHARS |
static java.lang.String |
NL |
Modifier | Constructor and Description |
---|---|
private |
StringUtils() |
Modifier and Type | Method and Description |
---|---|
private static int |
digit(char ch) |
static byte[] |
encodeStringForForkCommunication(java.lang.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(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 is
null or blank. |
static boolean |
isNotBlank(java.lang.String str)
Checks if a (trimmed) String is not
null 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 if
buffer starts with specific literal(s). |
static java.nio.ByteBuffer |
unescapeBytes(java.lang.String str,
java.lang.String charsetName)
Reverses the effect of
escapeBytesToPrintable(byte[], byte[], int, int) . |
static void |
unescapeString(java.lang.StringBuilder target,
java.lang.CharSequence str)
Reverses the effect of
escapeToPrintable(StringBuilder, CharSequence) . |
public static final java.lang.String NL
private static final byte[] HEX_CHARS
private static final java.nio.charset.Charset DEFAULT_CHARSET
public static java.lang.String[] split(java.lang.String text, java.lang.String separator)
public static boolean isBlank(java.lang.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(java.lang.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(java.lang.StringBuilder target, java.lang.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(java.lang.StringBuilder target, java.lang.CharSequence str)
escapeToPrintable(StringBuilder, CharSequence)
.target
- target string bufferstr
- the String to un-escape, as created by escapeToPrintable(StringBuilder, CharSequence)
private static int digit(char ch)
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
java.lang.NullPointerException
- if the specified parameter header
or input
is nulljava.lang.IndexOutOfBoundsException
- if off
or len
is out of range
(off < 0 || len < 0 || off >= input.length || len > input.length || off + len > input.length
)public static java.nio.ByteBuffer unescapeBytes(java.lang.String str, java.lang.String charsetName)
escapeBytesToPrintable(byte[], byte[], int, int)
.str
- the input StringcharsetName
- the charset nameout
public static byte[] encodeStringForForkCommunication(java.lang.String string)
public static boolean startsWith(java.lang.StringBuffer buffer, java.lang.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.