public final class Strings
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static byte[] |
EMPTY_BYTES
A empty byte array
|
private static byte[] |
HEX_CHAR
Hex chars
|
private static byte[] |
UTF8 |
| Constructor and Description |
|---|
Strings() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
dumpByte(byte octet)
Helper function that dump a byte in hex form
|
static java.lang.String |
dumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex form
|
static char |
dumpHex(byte hex)
Helper function that returns a char from an hex
|
static java.lang.String |
dumpHexPairs(byte[] buffer)
Helper function that dump an array of bytes in hex pair form,
without '0x' and space chars
|
static byte[] |
getBytesUtf8(java.lang.String string)
Return UTF-8 encoded byte[] representation of a String
|
static byte[] |
getBytesUtf8Ascii(java.lang.String string)
When the string to convert to bytes is pure ascii, this is a faster
method than the getBytesUtf8.
|
static boolean |
isEmpty(byte[] bytes)
Checks if a bytes array is empty or null.
|
static boolean |
isEmpty(java.lang.String str)
Checks if a String is empty ("") or null.
|
static java.lang.String |
listToString(java.util.List<?> list)
Utility method that return a String representation of a list
|
static java.lang.String |
listToString(java.util.List<?> list,
java.lang.String tabs)
Utility method that return a String representation of a list
|
static java.lang.String |
mapToString(java.util.Map<?,?> map)
Utility method that return a String representation of a map.
|
static java.lang.String |
mapToString(java.util.Map<?,?> map,
java.lang.String tabs)
Utility method that return a String representation of a map.
|
static java.lang.String |
setToString(java.util.Set<?> set)
Utility method that return a String representation of a set
|
static byte[] |
toByteArray(java.lang.String hexString)
Get byte array from hex string
|
static java.lang.String |
toHexString(byte[] res)
Gets a hex string from byte array.
|
static java.lang.String |
utf8ToString(byte[] bytes)
Return an UTF-8 encoded String
|
static java.lang.String |
utf8ToString(byte[] bytes,
int length)
Return an UTF-8 encoded String
|
static java.lang.String |
utf8ToString(byte[] bytes,
int start,
int length)
Return an UTF-8 encoded String
|
static java.lang.String |
utf8ToString(java.nio.ByteBuffer bytes)
Return an UTF-8 encoded String
|
private static final byte[] HEX_CHAR
public static final byte[] EMPTY_BYTES
private static final byte[] UTF8
public static java.lang.String dumpBytes(byte[] buffer)
buffer - The bytes array to dumppublic static java.lang.String dumpByte(byte octet)
octet - The byte to dumppublic static char dumpHex(byte hex)
hex - The hex to dumppublic static java.lang.String dumpHexPairs(byte[] buffer)
buffer - The bytes array to dumppublic static java.lang.String toHexString(byte[] res)
res - the byte arraypublic static byte[] toByteArray(java.lang.String hexString)
hexString - the hex string to convert to a byte arraypublic static java.lang.String utf8ToString(byte[] bytes)
bytes - The byte array to be transformed to a Stringpublic static java.lang.String utf8ToString(java.nio.ByteBuffer bytes)
bytes - The byte array to be transformed to a Stringpublic static java.lang.String utf8ToString(byte[] bytes,
int length)
bytes - The byte array to be transformed to a Stringlength - The length of the byte array to be convertedpublic static java.lang.String utf8ToString(byte[] bytes,
int start,
int length)
bytes - The byte array to be transformed to a Stringstart - the starting position in the byte arraylength - The length of the byte array to be convertedpublic static boolean isEmpty(java.lang.String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str - the String to check, may be nulltrue if the String is empty or nullpublic static boolean isEmpty(byte[] bytes)
bytes - The bytes array to check, may be nulltrue if the bytes array is empty or nullpublic static byte[] getBytesUtf8(java.lang.String string)
string - The string to be transformed to a byte arraypublic static byte[] getBytesUtf8Ascii(java.lang.String string)
string - The string to convert to byte[]public static java.lang.String listToString(java.util.List<?> list)
list - The list to transform to a stringpublic static java.lang.String setToString(java.util.Set<?> set)
set - The set to transform to a stringpublic static java.lang.String listToString(java.util.List<?> list,
java.lang.String tabs)
list - The list to transform to a stringtabs - The tabs to add in ffront of the elementspublic static java.lang.String mapToString(java.util.Map<?,?> map)
map - The map to transform to a stringpublic static java.lang.String mapToString(java.util.Map<?,?> map,
java.lang.String tabs)
map - The map to transform to a stringtabs - The tabs to add in ffront of the elements