public class StringUtils
extends java.lang.Object
CharEncoding
,
Standard charsetsConstructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
getBytesIso8859_1(java.lang.String string)
Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new
byte array.
|
static byte[] |
getBytesUnchecked(java.lang.String string,
java.lang.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[] |
getBytesUsAscii(java.lang.String string)
Encodes the given string into a sequence of bytes using the US-ASCII charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16(java.lang.String string)
Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16Be(java.lang.String string)
Encodes the given string into a sequence of bytes using the UTF-16BE charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf16Le(java.lang.String string)
Encodes the given string into a sequence of bytes using the UTF-16LE charset, storing the result into a new byte
array.
|
static byte[] |
getBytesUtf8(java.lang.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 java.lang.String |
newString(byte[] bytes,
java.lang.String charsetName)
Constructs a new
String by decoding the specified array of bytes using the given charset. |
static java.lang.String |
newStringIso8859_1(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the ISO-8859-1 charset. |
static java.lang.String |
newStringUsAscii(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the US-ASCII charset. |
static java.lang.String |
newStringUtf16(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16 charset. |
static java.lang.String |
newStringUtf16Be(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16BE charset. |
static java.lang.String |
newStringUtf16Le(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-16LE charset. |
static java.lang.String |
newStringUtf8(byte[] bytes)
Constructs a new
String by decoding the specified array of bytes using the UTF-8 charset. |
public static byte[] getBytesIso8859_1(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUsAscii(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUtf16(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUtf16Be(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUtf16Le(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUtf8(java.lang.String string)
string
- the String to encode, may be null
null
if the input string was null
java.lang.IllegalStateException
- Thrown when the charset is missing, which should be never according the the Java specification.getBytesUnchecked(String, String)
public static byte[] getBytesUnchecked(java.lang.String string, java.lang.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 encode, may be null
charsetName
- The name of a required Charset
null
if the input string was null
java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen for a
required charset name.CharEncoding
,
String.getBytes(String)
public static java.lang.String newString(byte[] bytes, java.lang.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 characters, may be null
charsetName
- The name of a required Charset
String
decoded from the specified array of bytes using the given charset,
or null
if the input byte array was null
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen for a
required charset name.CharEncoding
,
String.String(byte[], String)
public static java.lang.String newStringIso8859_1(byte[] bytes)
String
by decoding the specified array of bytes using the ISO-8859-1 charset.bytes
- The bytes to be decoded into characters, may be null
String
decoded from the specified array of bytes using the ISO-8859-1 charset,
or null
if the input byte array was null
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.public static java.lang.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
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.public static java.lang.String newStringUtf16(byte[] bytes)
String
by decoding the specified array of bytes using the UTF-16 charset.bytes
- The bytes to be decoded into charactersString
decoded from the specified array of bytes using the UTF-16 charset
or null
if the input byte array was null
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.public static java.lang.String newStringUtf16Be(byte[] bytes)
String
by decoding the specified array of bytes using the UTF-16BE charset.bytes
- The bytes to be decoded into charactersString
decoded from the specified array of bytes using the UTF-16BE charset,
or null
if the input byte array was null
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.public static java.lang.String newStringUtf16Le(byte[] bytes)
String
by decoding the specified array of bytes using the UTF-16LE charset.bytes
- The bytes to be decoded into charactersString
decoded from the specified array of bytes using the UTF-16LE charset,
or null
if the input byte array was null
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.public static java.lang.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
.java.lang.IllegalStateException
- Thrown when a UnsupportedEncodingException
is caught, which should never happen since the
charset is required.This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.