# java.nio.charset

Defines charsets, decoders, and encoders, for translating between bytes and Unicode characters.
>
> | Class name | Description |
> |---|---|
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/Charset.html` | A named mapping between characters and bytes |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetDecoder.html` | Decodes bytes into characters |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetEncoder.html` | Encodes characters into bytes |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CoderResult.html` | Describes coder results |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CodingErrorAction.html` | 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*](http://www.ietf.org/rfc/rfc2278.txt). 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/Charset.html` 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html` class, together with the existing `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStreamReader.html` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html` 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/InputStreamReader.html` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStreamWriter.html`
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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/spi/CharsetProvider.html` class in the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/spi/package-summary.html` package.

Unless otherwise noted, passing a null argument to a constructor
or method in any class or interface in this package will cause a `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html` to be thrown.

### Classes

|---|---|
| [Charset](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/Charset.html) | A named mapping between sequences of sixteen-bit Unicode [code units](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Character.html#unicode) and sequences of bytes. |
| [CharsetDecoder](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetDecoder.html) | An engine that can transform a sequence of bytes in a specific charset into a sequence of sixteen-bit Unicode characters. |
| [CharsetEncoder](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetEncoder.html) | An engine that can transform a sequence of sixteen-bit Unicode characters into a sequence of bytes in a specific charset. |
| [CoderResult](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CoderResult.html) | A description of the result state of a coder. |
| [CodingErrorAction](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CodingErrorAction.html) | A typesafe enumeration for coding-error actions. |
| [StandardCharsets](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/StandardCharsets.html) | Constant definitions for the standard `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/Charset.html`. |

### Exceptions

|---|---|
| [CharacterCodingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharacterCodingException.html) | Checked exception thrown when a character encoding or decoding error occurs. |
| [IllegalCharsetNameException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/IllegalCharsetNameException.html) | Unchecked exception thrown when a string that is not a [legal charset name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/Charset#names) is used as such. |
| [MalformedInputException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/MalformedInputException.html) | 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/UnmappableCharacterException.html) | Checked exception thrown when an input character (or byte) sequence is valid but cannot be mapped to an output byte (or character) sequence. |
| [UnsupportedCharsetException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/UnsupportedCharsetException.html) | Unchecked exception thrown when no support is available for a requested charset. |

### Errors

|---|---|
| [CoderMalfunctionError](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CoderMalfunctionError.html) | Error thrown when the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetDecoder.html#decodeLoop(java.nio.ByteBuffer,%20java.nio.CharBuffer)` method of a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetDecoder.html`, or the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetEncoder.html#encodeLoop(java.nio.CharBuffer,%20java.nio.ByteBuffer)` method of a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/charset/CharsetEncoder.html`, throws an unexpected exception. |