public class Charsets extends Object
This class extends the former charset provider implementations which
cannot be used in every environment (e.g. WebStart, Maven) without
installation in the JRE extensions directory where they are available to the
system classloader. It uses the same service provider files as the
platform implementation (java.nio.charset.spi.CharsetProvider
) but
is capable of using the current thread's classloader before falling back
to the system classloader for loading CharsetProvider
classes.
Modifier and Type | Method and Description |
---|---|
static String |
decode(byte[] bytes,
int off,
int count,
String charset)
Decodes the bytes of a given array to a string.
|
static String |
decode(byte[] bytes,
String charset)
Decodes the bytes of a given array to a string.
|
static byte[] |
encode(String str,
String charset)
Encodes a given string to an array of bytes representing the characters
of the string in a given charset.
|
public static byte[] encode(String str, String charset)
str
- the string to encode.charset
- the name of the charset to use.NullPointerException
- if str
or charset
is
null
.IllegalCharsetNameException
- if charset
is no valid charset name.UnsupportedCharsetException
- if charset
is not supported.public static String decode(byte[] bytes, String charset)
bytes
- the bytes to decode.charset
- the name of the charset to use.NullPointerException
- if bytes
or charset
is
null
.IllegalCharsetNameException
- if charset
is no valid charset name.UnsupportedCharsetException
- if charset
is not supported.public static String decode(byte[] bytes, int off, int count, String charset)
bytes
- the bytes to decode.off
- the offset from where to start decoding.count
- the number of bytes to decode starting at offset
.charset
- the name of the charset to use.NullPointerException
- if bytes
or charset
is
null
.IndexOutOfBoundsException
- if off
is negative or greater
than the length of bytes
or off + count
is negative or
greater than the length of bytes
.IllegalCharsetNameException
- if charset
is no valid charset name.UnsupportedCharsetException
- if charset
is not supported.Copyright © 2005-2012 jDTAUS. All Rights Reserved.