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
This convenience method decodes the bytes and stores the resulting
characters into a newly allocated
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
) is used in a multistep decoding process:
reset( ) method, unless this is the first
CharsetDecoder has been used.
Call the three-argument version of
decode( ) one
or more times. The third argument should be
on, and only on, the last invocation of the method. The first
decode( ) is a
ByteBuffer that contains bytes to be decoded. The
second argument is a
CharBuffer into which the
resulting characters are stored. The return value of the method is a
CoderResult object that specifies the state of the
ongoing the decoding operation. The possible
CoderResult return 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, ...