public final class Strings extends Object
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTES
A empty byte array
|
Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
static String |
dumpByte(byte octet)
Helper function that dump a byte in hex form
|
static 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 String |
dumpHexPairs(byte[] buffer)
Helper function that dump an array of bytes in hex pair form,
without '0x' and space chars
|
static byte[] |
getBytesUtf8(String string)
Return UTF-8 encoded byte[] representation of a String
|
static byte[] |
getBytesUtf8Ascii(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(String str)
Checks if a String is empty ("") or null.
|
static String |
listToString(List<?> list)
Utility method that return a String representation of a list
|
static String |
listToString(List<?> list,
String tabs)
Utility method that return a String representation of a list
|
static String |
mapToString(Map<?,?> map)
Utility method that return a String representation of a map.
|
static String |
mapToString(Map<?,?> map,
String tabs)
Utility method that return a String representation of a map.
|
static String |
setToString(Set<?> set)
Utility method that return a String representation of a set
|
static byte[] |
toByteArray(String hexString)
Get byte array from hex string
|
static String |
toHexString(byte[] res)
Gets a hex string from byte array.
|
static String |
utf8ToString(byte[] bytes)
Return an UTF-8 encoded String
|
static String |
utf8ToString(byte[] bytes,
int length)
Return an UTF-8 encoded String
|
static String |
utf8ToString(byte[] bytes,
int start,
int length)
Return an UTF-8 encoded String
|
static String |
utf8ToString(ByteBuffer bytes)
Return an UTF-8 encoded String
|
public static final byte[] EMPTY_BYTES
public Strings()
public static String dumpBytes(byte[] buffer)
buffer
- The bytes array to dumppublic static String dumpByte(byte octet)
octet
- The byte to dumppublic static char dumpHex(byte hex)
hex
- The hex to dumppublic static String dumpHexPairs(byte[] buffer)
buffer
- The bytes array to dumppublic static String toHexString(byte[] res)
res
- the byte arraypublic static byte[] toByteArray(String hexString)
hexString
- the hex string to convert to a byte arraypublic static String utf8ToString(byte[] bytes)
bytes
- The byte array to be transformed to a Stringpublic static String utf8ToString(ByteBuffer bytes)
bytes
- The byte array to be transformed to a Stringpublic static 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 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(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(String string)
string
- The string to be transformed to a byte arraypublic static byte[] getBytesUtf8Ascii(String string)
string
- The string to convert to byte[]public static String listToString(List<?> list)
list
- The list to transform to a stringpublic static String setToString(Set<?> set)
set
- The set to transform to a stringpublic static String listToString(List<?> list, String tabs)
list
- The list to transform to a stringtabs
- The tabs to add in ffront of the elementspublic static String mapToString(Map<?,?> map)
map
- The map to transform to a stringpublic static String mapToString(Map<?,?> map, String tabs)
map
- The map to transform to a stringtabs
- The tabs to add in ffront of the elementsCopyright © 2012–2015 Apache Mavibot Project Parent. All rights reserved.