java.lang.Object | |
↳ | java.nio.charset.Charset |
A charset defines a mapping between a Unicode character sequence and a byte sequence. It facilitates the encoding from a Unicode character sequence into a byte sequence, and the decoding from a byte sequence into a Unicode character sequence.
A charset has a canonical name, which is usually in uppercase. Typically it also has one or more aliases. The name string can only consist of the following characters: '0' - '9', 'A' - 'Z', 'a' - 'z', '.', ':'. '-' and '_'. The first character of the name must be a digit or a letter.
The following charsets should be supported by any java platform: US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16.
Additional charsets can be made available by configuring one or more charset
providers through provider configuration files. Such files are always named
as "java.nio.charset.spi.CharsetProvider" and located in the
"META-INF/services" sub folder of one or more classpaths. The files should be
encoded in "UTF-8". Each line of their content specifies the class name of a
charset provider which extends
java.nio.charset.spi.CharsetProvider
. A line should end with
'\r', '\n' or '\r\n'. Leading and trailing whitespaces are trimmed. Blank
lines, and lines (after trimming) starting with "#" which are regarded as
comments, are both ignored. Duplicates of names already found are also
ignored. Both the configuration files and the provider classes will be loaded
using the thread context class loader.
This class is thread-safe.
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a
Charset object. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the set of this charset's aliases.
| |||||||||||
Gets a map of all available charsets supported by the runtime.
| |||||||||||
Returns true if this charset supports encoding, false otherwise.
| |||||||||||
Compares this charset with the given charset.
| |||||||||||
Determines whether this charset is a super set of the given charset.
| |||||||||||
Decodes the content of the specified byte buffer and writes it to a
character buffer that is to be returned.
| |||||||||||
Gets the system default charset from the virtual machine.
| |||||||||||
Gets the name of this charset for the default locale.
| |||||||||||
Gets the name of this charset for the specified locale.
| |||||||||||
Encodes the content of the give character buffer and outputs to a byte
buffer that is to be returned.
| |||||||||||
Encodes a string and outputs to a byte buffer that is to be returned.
| |||||||||||
Determines whether this charset equals to the given object.
| |||||||||||
Gets a
Charset instance for the specified charset name. | |||||||||||
Gets the hash code of this charset.
| |||||||||||
Indicates whether this charset is known to be registered in the IANA
Charset Registry.
| |||||||||||
Determines whether the specified charset is supported by this runtime.
| |||||||||||
Gets the canonical name of this charset.
| |||||||||||
Gets a new instance of a decoder for this charset.
| |||||||||||
Gets a new instance of an encoder for this charset.
| |||||||||||
Gets a string representation of this charset.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface java.lang.Comparable
|
Constructs a Charset
object. Duplicated aliases are
ignored.
canonicalName | the canonical name of the charset. |
---|---|
aliases | an array containing all aliases of the charset. May be null. |
IllegalCharsetNameException | on an illegal value being supplied for either
canonicalName or for any element of
aliases .
|
---|
Gets the set of this charset's aliases.
Gets a map of all available charsets supported by the runtime.
The returned map contains mappings from canonical names to corresponding
instances of Charset
. The canonical names can be considered
as case-insensitive.
Returns true if this charset supports encoding, false otherwise.
Compares this charset with the given charset. This comparation is based on the case insensitive canonical names of the charsets.
charset | the given object to be compared with. |
---|
Determines whether this charset is a super set of the given charset.
charset | a given charset. |
---|
Decodes the content of the specified byte buffer and writes it to a character buffer that is to be returned.
The default action in case of decoding errors is
CodingErrorAction.REPLACE
.
buffer | the byte buffer containing the content to be decoded. |
---|
Gets the system default charset from the virtual machine.
Gets the name of this charset for the default locale.
The default implementation returns the canonical name of this charset. Subclasses may return a localized display name.
Gets the name of this charset for the specified locale.
The default implementation returns the canonical name of this charset. Subclasses may return a localized display name.
l | a certain locale |
---|
Encodes the content of the give character buffer and outputs to a byte buffer that is to be returned.
The default action in case of encoding errors is
CodingErrorAction.REPLACE
.
buffer | the character buffer containing the content to be encoded. |
---|
Encodes a string and outputs to a byte buffer that is to be returned.
The default action in case of encoding errors is
CodingErrorAction.REPLACE
.
s | the string to be encoded. |
---|
Determines whether this charset equals to the given object. They are considered to be equal if they have the same canonical name.
obj | the given object to be compared with. |
---|
Gets a Charset
instance for the specified charset name.
charsetName | the canonical name of the charset or an alias. |
---|
Charset
instance for the specified charset name.IllegalCharsetNameException | if the specified charset name is illegal. |
---|---|
UnsupportedCharsetException | if the desired charset is not supported by this runtime. |
Gets the hash code of this charset.
Indicates whether this charset is known to be registered in the IANA Charset Registry.
Determines whether the specified charset is supported by this runtime.
charsetName | the name of the charset. |
---|
IllegalCharsetNameException | if the specified charset name is illegal. |
---|
Gets the canonical name of this charset.
Gets a new instance of a decoder for this charset.
Gets a new instance of an encoder for this charset.
Gets a string representation of this charset. Usually this contains the canonical name of the charset.