java.nio.charset
Class CharsetDecoder

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.nio.charset.CharsetDecoder

public abstract class CharsetDecoder
extends Object sample code for java.lang.Object definition code for java.lang.Object

An engine that can transform a sequence of bytes in a specific charset into a sequence of sixteen-bit Unicode characters.

The input byte sequence is provided in a byte buffer or a series of such buffers. The output character sequence is written to a character buffer or a series of such buffers. A decoder should always be used by making the following sequence of method invocations, hereinafter referred to as a decoding operation:

  1. Reset the decoder via the reset sample code for java.nio.charset.CharsetDecoder.reset() definition code for java.nio.charset.CharsetDecoder.reset() method, unless it has not been used before;

  2. Invoke the decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) method zero or more times, as long as additional input may be available, passing false for the endOfInput argument and filling the input buffer and flushing the output buffer between invocations;

  3. Invoke the decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) method one final time, passing true for the endOfInput argument; and then

  4. Invoke the flush sample code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) method so that the decoder can flush any internal state to the output buffer.

Each invocation of the decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) method will decode as many bytes as possible from the input buffer, writing the resulting characters to the output buffer. The decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) method returns when more input is required, when there is not enough room in the output buffer, or when a decoding error has occurred. In each case a CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult object is returned to describe the reason for termination. An invoker can examine this object and fill the input buffer, flush the output buffer, or attempt to recover from a decoding error, as appropriate, and try again.

There are two general types of decoding errors. If the input byte sequence is not legal for this charset then the input is considered malformed. If the input byte sequence is legal but cannot be mapped to a valid Unicode character then an unmappable character has been encountered.

How a decoding error is handled depends upon the action requested for that type of error, which is described by an instance of the CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction class. The possible error actions are to ignore sample code for java.nio.charset.CodingErrorAction.IGNORE definition code for java.nio.charset.CodingErrorAction.IGNORE the erroneous input, report sample code for java.nio.charset.CodingErrorAction.REPORT definition code for java.nio.charset.CodingErrorAction.REPORT the error to the invoker via the returned CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult object, or replace sample code for java.nio.charset.CodingErrorAction.REPLACE definition code for java.nio.charset.CodingErrorAction.REPLACE the erroneous input with the current value of the replacement string. The replacement has the initial value "\uFFFD"; its value may be changed via the replaceWith sample code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String) method.

The default action for malformed-input and unmappable-character errors is to report sample code for java.nio.charset.CodingErrorAction.REPORT definition code for java.nio.charset.CodingErrorAction.REPORT them. The malformed-input error action may be changed via the onMalformedInput sample code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction) method; the unmappable-character action may be changed via the onUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction) method.

This class is designed to handle many of the details of the decoding process, including the implementation of error actions. A decoder for a specific charset, which is a concrete subclass of this class, need only implement the abstract decodeLoop sample code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) method, which encapsulates the basic decoding loop. A subclass that maintains internal state should, additionally, override the flush sample code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) and reset sample code for java.nio.charset.CharsetDecoder.reset() definition code for java.nio.charset.CharsetDecoder.reset() methods.

Instances of this class are not safe for use by multiple concurrent threads.

Since:
1.4
See Also:
ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer , CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer , Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset , CharsetEncoder sample code for java.nio.charset.CharsetEncoder definition code for java.nio.charset.CharsetEncoder

Constructor Summary
protected CharsetDecoder sample code for java.nio.charset.CharsetDecoder.CharsetDecoder(java.nio.charset.Charset, float, float) definition code for java.nio.charset.CharsetDecoder.CharsetDecoder(java.nio.charset.Charset, float, float) (Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset  cs, float averageCharsPerByte, float maxCharsPerByte)
          Initializes a new decoder.
 
Method Summary
 float averageCharsPerByte sample code for java.nio.charset.CharsetDecoder.averageCharsPerByte() definition code for java.nio.charset.CharsetDecoder.averageCharsPerByte() ()
          Returns the average number of characters that will be produced for each byte of input.
 Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset charset sample code for java.nio.charset.CharsetDecoder.charset() definition code for java.nio.charset.CharsetDecoder.charset() ()
          Returns the charset that created this decoder.
 CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer) (ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer  in)
          Convenience method that decodes the remaining content of a single input byte buffer into a newly-allocated character buffer.
 CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) (ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer  in, CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  out, boolean endOfInput)
          Decodes as many bytes as possible from the given input buffer, writing the results to the given output buffer.
protected abstract  CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult decodeLoop sample code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) (ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer  in, CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  out)
          Decodes one or more bytes into one or more characters.
 Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset detectedCharset sample code for java.nio.charset.CharsetDecoder.detectedCharset() definition code for java.nio.charset.CharsetDecoder.detectedCharset() ()
          Retrieves the charset that was detected by this decoder  (optional operation).
 CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult flush sample code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) (CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  out)
          Flushes this decoder.
protected  CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult implFlush sample code for java.nio.charset.CharsetDecoder.implFlush(java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.implFlush(java.nio.CharBuffer) (CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  out)
          Flushes this decoder.
protected  void implOnMalformedInput sample code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction) (CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
          Reports a change to this decoder's malformed-input action.
protected  void implOnUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction) (CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
          Reports a change to this decoder's unmappable-character action.
protected  void implReplaceWith sample code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newReplacement)
          Reports a change to this decoder's replacement value.
protected  void implReset sample code for java.nio.charset.CharsetDecoder.implReset() definition code for java.nio.charset.CharsetDecoder.implReset() ()
          Resets this decoder, clearing any charset-specific internal state.
 boolean isAutoDetecting sample code for java.nio.charset.CharsetDecoder.isAutoDetecting() definition code for java.nio.charset.CharsetDecoder.isAutoDetecting() ()
          Tells whether or not this decoder implements an auto-detecting charset.
 boolean isCharsetDetected sample code for java.nio.charset.CharsetDecoder.isCharsetDetected() definition code for java.nio.charset.CharsetDecoder.isCharsetDetected() ()
          Tells whether or not this decoder has yet detected a charset  (optional operation).
 CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction malformedInputAction sample code for java.nio.charset.CharsetDecoder.malformedInputAction() definition code for java.nio.charset.CharsetDecoder.malformedInputAction() ()
          Returns this decoder's current action for malformed-input errors.
 float maxCharsPerByte sample code for java.nio.charset.CharsetDecoder.maxCharsPerByte() definition code for java.nio.charset.CharsetDecoder.maxCharsPerByte() ()
          Returns the maximum number of characters that will be produced for each byte of input.
 CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder onMalformedInput sample code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction) (CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
          Changes this decoder's action for malformed-input errors.
 CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder onUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction) (CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
          Changes this decoder's action for unmappable-character errors.
 String sample code for java.lang.String definition code for java.lang.String replacement sample code for java.nio.charset.CharsetDecoder.replacement() definition code for java.nio.charset.CharsetDecoder.replacement() ()
          Returns this decoder's replacement value.
 CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder replaceWith sample code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  newReplacement)
          Changes this decoder's replacement value.
 CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder reset sample code for java.nio.charset.CharsetDecoder.reset() definition code for java.nio.charset.CharsetDecoder.reset() ()
          Resets this decoder, clearing any internal state.
 CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction unmappableCharacterAction sample code for java.nio.charset.CharsetDecoder.unmappableCharacterAction() definition code for java.nio.charset.CharsetDecoder.unmappableCharacterAction() ()
          Returns this decoder's current action for unmappable-character errors.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

CharsetDecoder sample code for java.nio.charset.CharsetDecoder(java.nio.charset.Charset, float, float) definition code for java.nio.charset.CharsetDecoder(java.nio.charset.Charset, float, float)

protected CharsetDecoder(Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset  cs,
                         float averageCharsPerByte,
                         float maxCharsPerByte)
Initializes a new decoder. The new decoder will have the given chars-per-byte values and its replacement will be the string "\uFFFD".

Parameters:
averageCharsPerByte - A positive float value indicating the expected number of characters that will be produced for each input byte
maxCharsPerByte - A positive float value indicating the maximum number of characters that will be produced for each input byte
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - If the preconditions on the parameters do not hold
Method Detail

charset sample code for java.nio.charset.CharsetDecoder.charset() definition code for java.nio.charset.CharsetDecoder.charset()

public final Charset sample code for java.nio.charset.Charset definition code for java.nio.charset.Charset  charset()
Returns the charset that created this decoder.

Returns:
This decoder's charset

replacement sample code for java.nio.charset.CharsetDecoder.replacement() definition code for java.nio.charset.CharsetDecoder.replacement()

public final String sample code for java.lang.String definition code for java.lang.String  replacement()
Returns this decoder's replacement value.

Returns:
This decoder's current replacement, which is never null and is never empty

replaceWith sample code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.replaceWith(java.lang.String)

public final CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder  replaceWith(String sample code for java.lang.String definition code for java.lang.String  newReplacement)
Changes this decoder's replacement value.

This method invokes the implReplaceWith sample code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String) method, passing the new replacement, after checking that the new replacement is acceptable.

Parameters:
newReplacement - The new replacement; must not be null and must have non-zero length
Returns:
This decoder
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - If the preconditions on the parameter do not hold

implReplaceWith sample code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String) definition code for java.nio.charset.CharsetDecoder.implReplaceWith(java.lang.String)

protected void implReplaceWith(String sample code for java.lang.String definition code for java.lang.String  newReplacement)
Reports a change to this decoder's replacement value.

The default implementation of this method does nothing. This method should be overridden by decoders that require notification of changes to the replacement.

Parameters:
newReplacement -

malformedInputAction sample code for java.nio.charset.CharsetDecoder.malformedInputAction() definition code for java.nio.charset.CharsetDecoder.malformedInputAction()

public CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  malformedInputAction()
Returns this decoder's current action for malformed-input errors.

Returns:
The current malformed-input action, which is never null

onMalformedInput sample code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onMalformedInput(java.nio.charset.CodingErrorAction)

public final CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder  onMalformedInput(CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
Changes this decoder's action for malformed-input errors.

This method invokes the implOnMalformedInput sample code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction) method, passing the new action.

Parameters:
newAction - The new action; must not be null
Returns:
This decoder
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - If the precondition on the parameter does not hold

implOnMalformedInput sample code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnMalformedInput(java.nio.charset.CodingErrorAction)

protected void implOnMalformedInput(CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
Reports a change to this decoder's malformed-input action.

The default implementation of this method does nothing. This method should be overridden by decoders that require notification of changes to the malformed-input action.


unmappableCharacterAction sample code for java.nio.charset.CharsetDecoder.unmappableCharacterAction() definition code for java.nio.charset.CharsetDecoder.unmappableCharacterAction()

public CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  unmappableCharacterAction()
Returns this decoder's current action for unmappable-character errors.

Returns:
The current unmappable-character action, which is never null

onUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.onUnmappableCharacter(java.nio.charset.CodingErrorAction)

public final CharsetDecoder sample code for java.nio.charset.CharsetDecoder definition code for java.nio.charset.CharsetDecoder  onUnmappableCharacter(CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
Changes this decoder's action for unmappable-character errors.

This method invokes the implOnUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction) method, passing the new action.

Parameters:
newAction - The new action; must not be null
Returns:
This decoder
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - If the precondition on the parameter does not hold

implOnUnmappableCharacter sample code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction) definition code for java.nio.charset.CharsetDecoder.implOnUnmappableCharacter(java.nio.charset.CodingErrorAction)

protected void implOnUnmappableCharacter(CodingErrorAction sample code for java.nio.charset.CodingErrorAction definition code for java.nio.charset.CodingErrorAction  newAction)
Reports a change to this decoder's unmappable-character action.

The default implementation of this method does nothing. This method should be overridden by decoders that require notification of changes to the unmappable-character action.


averageCharsPerByte sample code for java.nio.charset.CharsetDecoder.averageCharsPerByte() definition code for java.nio.charset.CharsetDecoder.averageCharsPerByte()

public final float averageCharsPerByte()
Returns the average number of characters that will be produced for each byte of input. This heuristic value may be used to estimate the size of the output buffer required for a given input sequence.

Returns:
The average number of characters produced per byte of input

maxCharsPerByte sample code for java.nio.charset.CharsetDecoder.maxCharsPerByte() definition code for java.nio.charset.CharsetDecoder.maxCharsPerByte()

public final float maxCharsPerByte()
Returns the maximum number of characters that will be produced for each byte of input. This value may be used to compute the worst-case size of the output buffer required for a given input sequence.

Returns:
The maximum number of characters that will be produced per byte of input

decode sample code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean) definition code for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean)

public final CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult  decode(ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer  in,
                                CharBuffer sample code for java.nio.CharBuffer definition code for java.nio.CharBuffer  out,
                                boolean endOfInput)
Decodes as many bytes as possible from the given input buffer, writing the results to the given output buffer.

The buffers are read from, and written to, starting at their current positions. At most in.remaining() sample code for java.nio.Buffer.remaining() definition code for java.nio.Buffer.remaining() bytes will be read and at most out.remaining() sample code for java.nio.Buffer.remaining() definition code for java.nio.Buffer.remaining() characters will be written. The buffers' positions will be advanced to reflect the bytes read and the characters written, but their marks and limits will not be modified.

In addition to reading bytes from the input buffer and writing characters to the output buffer, this method returns a CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult object to describe its reason for termination:

In any case, if this method is to be reinvoked in the same decoding operation then care should be taken to preserve any bytes remaining in the input buffer so that they are available to the next invocation.

The endOfInput parameter advises this method as to whether the invoker can provide further input beyond that contained in the given input buffer. If there is a possibility of providing additional input then the invoker should pass false for this parameter; if there is no possibility of providing further input then the invoker should pass true. It is not erroneous, and in fact it is quite common, to pass false in one invocation and later discover that no further input was actually available. It is critical, however, that the final invocation of this method in a sequence of invocations always pass true so that any remaining undecoded input will be treated as being malformed.

This method works by invoking the decodeLoop sample code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer) method, interpreting its results, handling error conditions, and reinvoking it as necessary.

Parameters:
in - The input byte buffer
out - The output character buffer
endOfInput - true if, and only if, the invoker can provide no additional input bytes beyond those in the given buffer
Returns:
A coder-result object describing the reason for termination
Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - If a decoding operation is already in progress and the previous step was an invocation neither of the reset sample code for java.nio.charset.CharsetDecoder.reset() definition code for java.nio.charset.CharsetDecoder.reset() method, nor of this method with a value of false for the endOfInput parameter, nor of this method with a value of true for the endOfInput parameter but a return value indicating an incomplete decoding operation
CoderMalfunctionError sample code for java.nio.charset.CoderMalfunctionError definition code for java.nio.charset.CoderMalfunctionError - If an invocation of the decodeLoop method threw an unexpected exception

flush sample code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer) definition code for java.nio.charset.CharsetDecoder.flush(java.nio.CharBuffer)

public final CoderResult sample code for java.nio.charset.CoderResult definition code for java.nio.charset.CoderResult  flush(CharBuffer