Class StringUtils
java.lang.Object
org.apache.tomcat.util.codec.binary.StringUtils
Converts String to and from bytes using the encodings required by the Java specification. These encodings are
 specified in 
 Standard charsets.
 
This class is immutable and thread-safe.
- Since:
- 1.4
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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 StringnewStringUsAscii(byte[] bytes) Constructs a newStringby decoding the specified array of bytes using the US-ASCII charset.static StringnewStringUtf8(byte[] bytes) Constructs a newStringby decoding the specified array of bytes using the UTF-8 charset.
- 
Constructor Details- 
StringUtilspublic StringUtils()
 
- 
- 
Method Details- 
getBytesUtf8Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.- Parameters:
- string- the String to encode, may be- null
- Returns:
- encoded bytes, or nullif the input string wasnull
- Throws:
- NullPointerException- Thrown if- StandardCharsets.UTF_8is not initialized, which should never happen since it is required by the Java platform specification.
- Since:
- As of 1.7, throws NullPointerExceptioninstead of UnsupportedEncodingException
- See Also:
 
- 
newStringUsAsciiConstructs a newStringby decoding the specified array of bytes using the US-ASCII charset.- Parameters:
- bytes- The bytes to be decoded into characters
- Returns:
- A new Stringdecoded from the specified array of bytes using the US-ASCII charset, ornullif the input byte array wasnull.
- Throws:
- NullPointerException- Thrown if- StandardCharsets.US_ASCIIis not initialized, which should never happen since it is required by the Java platform specification.
- Since:
- As of 1.7, throws NullPointerExceptioninstead of UnsupportedEncodingException
 
- 
newStringUtf8Constructs a newStringby decoding the specified array of bytes using the UTF-8 charset.- Parameters:
- bytes- The bytes to be decoded into characters
- Returns:
- A new Stringdecoded from the specified array of bytes using the UTF-8 charset, ornullif the input byte array wasnull.
- Throws:
- NullPointerException- Thrown if- StandardCharsets.UTF_8is not initialized, which should never happen since it is required by the Java platform specification.
- Since:
- As of 1.7, throws NullPointerExceptioninstead of UnsupportedEncodingException
 
 
-