public class StringUtils extends Object
Common String
manipulation routines.
Originally from Turbine and the GenerationJavaCore library.
Modifier and Type | Field and Description |
---|---|
static String |
FORK_STREAM_CHARSET_NAME |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
decode(byte[] toDecode,
Charset charset) |
static byte[] |
encode(String toEncode,
Charset charset) |
static byte[] |
encodeStringForForkCommunication(String string) |
static int |
escapeBytesToPrintable(byte[] out,
int outoff,
byte[] input,
int off,
int len)
Escapes the bytes in the array
str 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 <T> T |
requireNonNull(T obj) |
static <T> T |
requireNonNull(T obj,
String message) |
static String[] |
split(String text,
String separator) |
static ByteBuffer |
unescapeBytes(String str,
String charsetName)
Reverses the effect of
escapeBytesToPrintable(byte[], int, byte[], int, int) . |
static void |
unescapeString(StringBuilder target,
CharSequence str)
Reverses the effect of
escapeToPrintable(StringBuilder, CharSequence) . |
public static final String FORK_STREAM_CHARSET_NAME
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 int escapeBytesToPrintable(byte[] out, int outoff, byte[] input, int off, int len)
str
to contain only 'printable' bytes.
Escaping is done by encoding the non-nicely printable bytes to '\' + upperCaseHexBytes(byte)
.
A save length of out
is len * 3 + outoff
.
The reverse-method is #unescapeBytes(byte[], String)
.
out
- output bufferoutoff
- offset in the output bufferinput
- input bufferoff
- offset in the input bufferlen
- number of bytes to copy from the input bufferout
public static ByteBuffer unescapeBytes(String str, String charsetName)
escapeBytesToPrintable(byte[], int, byte[], int, int)
.str
- the input StringcharsetName
- the charset nameout
public static byte[] encodeStringForForkCommunication(String string)
public static <T> T requireNonNull(T obj, String message)
public static <T> T requireNonNull(T obj)
Copyright © 2004–2015 The Apache Software Foundation. All rights reserved.