public class StringUtils
extends java.lang.Object
Common String
manipulation routines.
Originally from Turbine and the GenerationJavaCore library.
Modifier and Type | Field and Description |
---|---|
private static java.nio.charset.Charset |
DEFAULT_CHARSET |
static java.lang.String |
FORK_STREAM_CHARSET_NAME |
private static byte[] |
HEX_CHARS |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
decode(byte[] toDecode,
java.nio.charset.Charset charset) |
private static int |
digit(char ch) |
static byte[] |
encode(java.lang.String toEncode,
java.nio.charset.Charset charset) |
static byte[] |
encodeStringForForkCommunication(java.lang.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(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 <T> T |
requireNonNull(T obj) |
static <T> T |
requireNonNull(T obj,
java.lang.String message) |
static java.lang.String[] |
split(java.lang.String text,
java.lang.String separator) |
static java.nio.ByteBuffer |
unescapeBytes(java.lang.String str,
java.lang.String charsetName)
Reverses the effect of
escapeBytesToPrintable(byte[], int, byte[], int, int) . |
static void |
unescapeString(java.lang.StringBuilder target,
java.lang.CharSequence str)
Reverses the effect of
escapeToPrintable(StringBuilder, CharSequence) . |
private static final byte[] HEX_CHARS
private static final java.nio.charset.Charset DEFAULT_CHARSET
public static final java.lang.String FORK_STREAM_CHARSET_NAME
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 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 java.nio.ByteBuffer unescapeBytes(java.lang.String str, java.lang.String charsetName)
escapeBytesToPrintable(byte[], int, byte[], int, int)
.str
- the input StringcharsetName
- the charset nameout
public static java.lang.String decode(byte[] toDecode, java.nio.charset.Charset charset)
public static byte[] encode(java.lang.String toEncode, java.nio.charset.Charset charset)
public static byte[] encodeStringForForkCommunication(java.lang.String string)
public static <T> T requireNonNull(T obj, java.lang.String message)
public static <T> T requireNonNull(T obj)