Package java.nio.charset
Defines charsets, decoders, and encoders, for translating between bytes and Unicode characters.
Class name | Description |
---|---|
Charset | A named mapping between characters and bytes |
CharsetDecoder | Decodes bytes into characters |
CharsetEncoder | Encodes characters into bytes |
CoderResult | Describes coder results |
CodingErrorAction | Describes actions to take when coding errors are detected |
A charset is named mapping between sequences of sixteen-bit Unicode characters and sequences of bytes, in the sense defined in RFC 2278. A decoder is an engine which transforms bytes in a specific charset into characters, and an encoder is an engine which transforms characters into bytes. Encoders and decoders operate on byte and character buffers. They are collectively referred to as coders.
The Charset
class defines methods for creating coders for a given charset and for retrieving the various names associated with a charset. It also defines static methods for testing whether a particular charset is supported, for locating charset instances by name, and for constructing a map that contains every charset for which support is available in the current Java virtual machine.
Most users will not use these classes directly; instead they will use the existing charset-related constructors and methods in the String
class, together with the existing InputStreamReader
and OutputStreamWriter
classes, all of whose implementations have been reworked to make use of the charset facilities defined in this package. A small number of changes have been made to the InputStreamReader
and OutputStreamWriter
classes in order to allow explicit charset objects to be specified in the construction of instances of those classes.
Support for new charsets can be made available via the interface defined in the CharsetProvider
class in the java.nio.charset.spi
package.
Unless otherwise noted, passing a null
argument to a constructor or method in any class or interface in this package will cause a NullPointerException
to be thrown.
- Since:
- 1.4
Class | Description |
---|---|
Charset | A named mapping between sequences of sixteen-bit Unicode code units and sequences of bytes. |
CharsetDecoder | An engine that can transform a sequence of bytes in a specific charset into a sequence of sixteen-bit Unicode characters. |
CharsetEncoder | An engine that can transform a sequence of sixteen-bit Unicode characters into a sequence of bytes in a specific charset. |
CoderResult | A description of the result state of a coder. |
CodingErrorAction | A typesafe enumeration for coding-error actions. |
StandardCharsets | Constant definitions for the standard |
Exception | Description |
---|---|
CharacterCodingException | Checked exception thrown when a character encoding or decoding error occurs. |
IllegalCharsetNameException | Unchecked exception thrown when a string that is not a legal charset name is used as such. |
MalformedInputException | Checked exception thrown when an input byte sequence is not legal for given charset, or an input character sequence is not a legal sixteen-bit Unicode sequence. |
UnmappableCharacterException | Checked exception thrown when an input character (or byte) sequence is valid but cannot be mapped to an output byte (or character) sequence. |
UnsupportedCharsetException | Unchecked exception thrown when no support is available for a requested charset. |
Error | Description |
---|---|
CoderMalfunctionError | Error thrown when the |
© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/charset/package-summary.html