Name
CharsetDecoder
Synopsis
A
CharsetDecoder is a
“decoding engine” that converts a
sequence of bytes into a sequence of characters based on the encoding
of some charset. Obtain a CharsetDecoder from the
Charset that represents the charset to be decoded.
If you have a complete sequence of bytes to be decoded in a
ByteBuffer you can pass that buffer to the
one-argument version of decode(
)
.
This convenience method decodes the bytes and stores the resulting
characters into a newly allocated CharBuffer,
resetting and flushing the decoder as necessary. It throws an
exception if there are problems with the bytes to be decoded.
Typically, however, the three-argument version of decode(
) is used in a multistep decoding process:
Call the
reset( )method, unless this is the first time theCharsetDecoderhas been used.Call the three-argument version of
decode( )one or more times. The third argument should betrueon, and only on, the last invocation of the method. The first argument todecode( )is aByteBufferthat contains bytes to be decoded. The second argument is aCharBufferinto which the resulting characters are stored. The return value of the method is aCoderResultobject that specifies the state of the ongoing the decoding operation. The possibleCoderResultreturn values are detailed below. In a typical case, however,decode( )returns after it has decoded all of the bytes in the input buffer. In this case, you would then typically fill the input buffer with more bytes to be decoded, ...