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 theCharsetDecoder
has been used.Call the three-argument version of
decode( )
one or more times. The third argument should betrue
on, and only on, the last invocation of the method. The first argument todecode( )
is aByteBuffer
that contains bytes to be decoded. The second argument is aCharBuffer
into which the resulting characters are stored. The return value of the method is aCoderResult
object that specifies the state of the ongoing the decoding operation. The possibleCoderResult
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, ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.