public class StringUtils extends Object
This class is immutable and thread-safe.
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
getBytesUtf8(String string)
Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte
array.
|
static String |
newStringUsAscii(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the US-ASCII charset. |
static String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8 charset. |
public static byte[] getBytesUtf8(String string)
string - the String to encode, may be nullnull if the input string was nullNullPointerException - Thrown if StandardCharsets.UTF_8 is not initialized, which should never happen
since it is required by the Java platform specification.NullPointerException instead of UnsupportedEncodingExceptionpublic static String newStringUsAscii(byte[] bytes)
String by decoding the specified array of bytes using the US-ASCII charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the US-ASCII charset,
or null if the input byte array was null.NullPointerException - Thrown if StandardCharsets.US_ASCII is not initialized, which should never happen
since it is required by the Java platform specification.NullPointerException instead of UnsupportedEncodingExceptionpublic static String newStringUtf8(byte[] bytes)
String by decoding the specified array of bytes using the UTF-8 charset.bytes - The bytes to be decoded into charactersString decoded from the specified array of bytes using the UTF-8 charset,
or null if the input byte array was null.NullPointerException - Thrown if StandardCharsets.UTF_8 is not initialized, which should never happen since it is
required by the Java platform specification.NullPointerException instead of UnsupportedEncodingExceptionCopyright © 2000-2022 Apache Software Foundation. All Rights Reserved.