Package org.apache.wicket.util.crypt
Class StringUtils
- java.lang.Object
-
- org.apache.wicket.util.crypt.StringUtils
-
public class StringUtils extends java.lang.ObjectConverts String to and from bytes using the encodings required by the Java specification. These encodings are specified in Standard charsets- Since:
- 1.4
- Version:
- $Id$
- Author:
- Gary Gregory
- See Also:
CharEncoding, Standard charsets
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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.StringnewString(byte[] bytes, java.lang.String charsetName)Constructs a newStringby decoding the specified array of bytes using the given charset.static java.lang.StringnewStringIso8859_1(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the ISO-8859-1 charset.static java.lang.StringnewStringUsAscii(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the US-ASCII charset.static java.lang.StringnewStringUtf16(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the UTF-16 charset.static java.lang.StringnewStringUtf16Be(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the UTF-16BE charset.static java.lang.StringnewStringUtf16Le(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the UTF-16LE charset.static java.lang.StringnewStringUtf8(byte[] bytes)Constructs a newStringby decoding the specified array of bytes using the UTF-8 charset.
-
-
-
Method Detail
-
getBytesIso8859_1
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUsAscii
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUtf16
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUtf16Be
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUtf16Le
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUtf8
public 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.- Parameters:
string- the String to encode- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when the charset is missing, which should be never according the the Java specification.- See Also:
- Standard
charsets,
getBytesUnchecked(String, String)
-
getBytesUnchecked
public 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.This method catches
UnsupportedEncodingExceptionand rethrows it asIllegalStateException, which should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.- Parameters:
string- the String to encodecharsetName- The name of a requiredCharset- Returns:
- encoded bytes
- Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen for a required charset name.- See Also:
CharEncoding,String.getBytes(String)
-
newString
public static java.lang.String newString(byte[] bytes, java.lang.String charsetName)Constructs a newStringby decoding the specified array of bytes using the given charset.This method catches
UnsupportedEncodingExceptionand re-throws it asIllegalStateException, which should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.- Parameters:
bytes- The bytes to be decoded into characterscharsetName- The name of a requiredCharset- Returns:
- A new
Stringdecoded from the specified array of bytes using the given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen for a required charset name.- See Also:
CharEncoding,String(byte[], String)
-
newStringIso8859_1
public static java.lang.String newStringIso8859_1(byte[] bytes)
Constructs a newStringby decoding the specified array of bytes using the ISO-8859-1 charset.- Parameters:
bytes- The bytes to be decoded into characters- Returns:
- A new
Stringdecoded from the specified array of bytes using the given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
newStringUsAscii
public static java.lang.String newStringUsAscii(byte[] bytes)
Constructs 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 given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
newStringUtf16
public static java.lang.String newStringUtf16(byte[] bytes)
Constructs a newStringby decoding the specified array of bytes using the UTF-16 charset.- Parameters:
bytes- The bytes to be decoded into characters- Returns:
- A new
Stringdecoded from the specified array of bytes using the given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
newStringUtf16Be
public static java.lang.String newStringUtf16Be(byte[] bytes)
Constructs a newStringby decoding the specified array of bytes using the UTF-16BE charset.- Parameters:
bytes- The bytes to be decoded into characters- Returns:
- A new
Stringdecoded from the specified array of bytes using the given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
newStringUtf16Le
public static java.lang.String newStringUtf16Le(byte[] bytes)
Constructs a newStringby decoding the specified array of bytes using the UTF-16LE charset.- Parameters:
bytes- The bytes to be decoded into characters- Returns:
- A new
Stringdecoded from the specified array of bytes using the given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
newStringUtf8
public static java.lang.String newStringUtf8(byte[] bytes)
Constructs 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 given charset. - Throws:
java.lang.IllegalStateException- Thrown when aUnsupportedEncodingExceptionis caught, which should never happen since the charset is required.
-
-