Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
Static Public Member Functions | Static Private Member Functions | List of all members
org.apache.commons.codec.binary.StringUtils Class Reference

Static Public Member Functions

static byte[] getBytesIso8859_1 (final String string)
 
static byte[] getBytesUnchecked (final String string, final String charsetName)
 
static byte[] getBytesUsAscii (final String string)
 
static byte[] getBytesUtf16 (final String string)
 
static byte[] getBytesUtf16Be (final String string)
 
static byte[] getBytesUtf16Le (final String string)
 
static byte[] getBytesUtf8 (final String string)
 
static String newString (final byte[] bytes, final String charsetName)
 
static String newStringIso8859_1 (final byte[] bytes)
 
static String newStringUsAscii (final byte[] bytes)
 
static String newStringUtf16 (final byte[] bytes)
 
static String newStringUtf16Be (final byte[] bytes)
 
static String newStringUtf16Le (final byte[] bytes)
 
static String newStringUtf8 (final byte[] bytes)
 

Static Private Member Functions

static byte[] getBytes (final String string, final Charset charset)
 
static IllegalStateException newIllegalStateException (final String charsetName, final UnsupportedEncodingException e)
 
static String newString (final byte[] bytes, final Charset charset)
 

Detailed Description

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.

See also
CharEncoding
Standard charsets
Version
$Id$
Since
1.4

Definition at line 38 of file StringUtils.java.

Member Function Documentation

static byte [] org.apache.commons.codec.binary.StringUtils.getBytes ( final String  string,
final Charset  charset 
)
staticprivate
static byte [] org.apache.commons.codec.binary.StringUtils.getBytesIso8859_1 ( final String  string)
static

Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#ISO_8859_1 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 70 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.ISO_8859_1.

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUnchecked ( final String  string,
final String  charsetName 
)
static

Encodes the given string into a sequence of bytes using the named charset, storing the result into a new byte array.

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.

Parameters
stringthe String to encode, may be
null
charsetNameThe name of a required java.nio.charset.Charset
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
IllegalStateExceptionThrown when a UnsupportedEncodingException is caught, which should never happen for a required charset name.
See also
CharEncoding
String::getBytes(String)

Definition at line 94 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.newIllegalStateException().

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUsAscii ( final String  string)
static

Encodes the given string into a sequence of bytes using the US-ASCII charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#US_ASCII is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 119 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.US_ASCII.

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUtf16 ( final String  string)
static

Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 137 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.UTF_16.

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUtf16Be ( final String  string)
static

Encodes the given string into a sequence of bytes using the UTF-16BE charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16BE is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 155 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.UTF_16BE.

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUtf16Le ( final String  string)
static

Encodes the given string into a sequence of bytes using the UTF-16LE charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16LE is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 173 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.UTF_16LE.

static byte [] org.apache.commons.codec.binary.StringUtils.getBytesUtf8 ( final String  string)
static

Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.

Parameters
stringthe String to encode, may be
null
Returns
encoded bytes, or
null
if the input string was
null
Exceptions
NullPointerExceptionThrown if Charsets#UTF_8 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException
See also
Standard charsets
#getBytesUnchecked(String, String)

Definition at line 191 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.getBytes(), and org.apache.commons.codec.Charsets.UTF_8.

Referenced by org.apache.commons.codec.binary.BaseNCodec.decode(), org.apache.commons.codec.binary.Base64.isBase64(), and org.apache.commons.codec.binary.BaseNCodec.isInAlphabet().

static IllegalStateException org.apache.commons.codec.binary.StringUtils.newIllegalStateException ( final String  charsetName,
final UnsupportedEncodingException  e 
)
staticprivate
static String org.apache.commons.codec.binary.StringUtils.newString ( final byte[]  bytes,
final Charset  charset 
)
staticprivate

Constructs a new String by decoding the specified array of bytes using the given charset.

Parameters
bytesThe bytes to be decoded into characters
charsetThe Charset to encode the
String
Returns
A new String decoded from the specified array of bytes using the given charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#UTF_8 is not initialized, which should never happen since it is required by the Java platform specification.

Definition at line 213 of file StringUtils.java.

Referenced by org.apache.commons.codec.binary.StringUtils.newStringUtf8().

static String org.apache.commons.codec.binary.StringUtils.newString ( final byte[]  bytes,
final String  charsetName 
)
static

Constructs a new 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.

Parameters
bytesThe bytes to be decoded into characters, may be
null
charsetNameThe name of a required java.nio.charset.Charset
Returns
A new String decoded from the specified array of bytes using the given charset, or
null
if the input byte array was
null
.
Exceptions
IllegalStateExceptionThrown when a UnsupportedEncodingException is caught, which should never happen for a required charset name.
See also
CharEncoding
String::String(byte[], String)

Definition at line 236 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.newIllegalStateException().

static String org.apache.commons.codec.binary.StringUtils.newStringIso8859_1 ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the ISO-8859-1 charset.

Parameters
bytesThe bytes to be decoded into characters, may be
null
Returns
A new String decoded from the specified array of bytes using the ISO-8859-1 charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#ISO_8859_1 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 259 of file StringUtils.java.

References org.apache.commons.codec.Charsets.ISO_8859_1.

static String org.apache.commons.codec.binary.StringUtils.newStringUsAscii ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the US-ASCII charset.

Parameters
bytesThe bytes to be decoded into characters
Returns
A new String decoded from the specified array of bytes using the US-ASCII charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#US_ASCII is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 275 of file StringUtils.java.

References org.apache.commons.codec.Charsets.US_ASCII.

static String org.apache.commons.codec.binary.StringUtils.newStringUtf16 ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the UTF-16 charset.

Parameters
bytesThe bytes to be decoded into characters
Returns
A new String decoded from the specified array of bytes using the UTF-16 charset or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 291 of file StringUtils.java.

References org.apache.commons.codec.Charsets.UTF_16.

static String org.apache.commons.codec.binary.StringUtils.newStringUtf16Be ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the UTF-16BE charset.

Parameters
bytesThe bytes to be decoded into characters
Returns
A new String decoded from the specified array of bytes using the UTF-16BE charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16BE is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 307 of file StringUtils.java.

References org.apache.commons.codec.Charsets.UTF_16BE.

static String org.apache.commons.codec.binary.StringUtils.newStringUtf16Le ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the UTF-16LE charset.

Parameters
bytesThe bytes to be decoded into characters
Returns
A new String decoded from the specified array of bytes using the UTF-16LE charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#UTF_16LE is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 323 of file StringUtils.java.

References org.apache.commons.codec.Charsets.UTF_16LE.

static String org.apache.commons.codec.binary.StringUtils.newStringUtf8 ( final byte[]  bytes)
static

Constructs a new String by decoding the specified array of bytes using the UTF-8 charset.

Parameters
bytesThe bytes to be decoded into characters
Returns
A new String decoded from the specified array of bytes using the UTF-8 charset, or
null
if the input byte array was
null
.
Exceptions
NullPointerExceptionThrown if Charsets#UTF_8 is not initialized, which should never happen since it is required by the Java platform specification.
Since
As of 1.7, throws NullPointerException instead of UnsupportedEncodingException

Definition at line 339 of file StringUtils.java.

References org.apache.commons.codec.binary.StringUtils.newString(), and org.apache.commons.codec.Charsets.UTF_8.

Referenced by org.apache.commons.codec.binary.Base64.Base64(), org.apache.commons.codec.binary.BaseNCodec.encodeAsString(), org.apache.commons.codec.binary.Base64.encodeBase64String(), org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(), and org.apache.commons.codec.binary.BaseNCodec.encodeToString().


The documentation for this class was generated from the following file: