public class StringUtils extends Object
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
getBytesUnchecked(String string,
String charsetName)
Encodes the given string into a sequence of bytes using the named charset, storing the result into a new byte
array.
|
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 |
newString(byte[] bytes,
String charsetName)
Constructs a new
String by decoding the specified array of bytes using the given charset. |
static String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8 charset. |
public static final String UTF_8
public static String newString(byte[] bytes, String charsetName)
String by decoding the specified array of bytes using the given charset.
This method catches UnsupportedEncodingException and re-throws it as IllegalStateException, which
should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.
bytes - The bytes to be decoded into characterscharsetName - The name of a required CharsetString decoded from the specified array of bytes using the given charset.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a
required charset name.String.String(byte[], String)public 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 given charset.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the
charset is required.public static byte[] getBytesUtf8(String string)
string - the String to encodeIllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)public static byte[] getBytesUnchecked(String string, String charsetName)
This method catches UnsupportedEncodingException and rethrows it as IllegalStateException, which
should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.
string - the String to encodecharsetName - The name of a required CharsetIllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a
required charset name.String.getBytes(String)Copyright © 2021. All rights reserved.