CharsetDecoder (Java Platform SE 7 ) (original) (raw)
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() bytes will be read and at most out.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 object to describe its reason for termination:
- CoderResult.UNDERFLOW indicates that as much of the input buffer as possible has been decoded. If there is no further input then the invoker can proceed to the next step of thedecoding operation. Otherwise this method should be invoked again with further input.
- CoderResult.OVERFLOW indicates that there is insufficient space in the output buffer to decode any more bytes. This method should be invoked again with an output buffer that has more remaining characters. This is typically done by draining any decoded characters from the output buffer.
- A malformed-input result indicates that a malformed-input error has been detected. The malformed bytes begin at the input buffer's (possibly incremented) position; the number of malformed bytes may be determined by invoking the result object's length method. This case applies only if themalformed action of this decoder is CodingErrorAction.REPORT; otherwise the malformed input will be ignored or replaced, as requested.
- An unmappable-character result indicates that an unmappable-character error has been detected. The bytes that decode the unmappable character begin at the input buffer's (possibly incremented) position; the number of such bytes may be determined by invoking the result object's length method. This case applies only if the unmappable action of this decoder is CodingErrorAction.REPORT; otherwise the unmappable character will be ignored or replaced, as requested.
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 method, interpreting its results, handling error conditions, and reinvoking it as necessary.