This is a facade method for the decoding operation. This method decodes the remaining byte sequence of the given byte buffer into a new character buffer. This method performs a complete decoding operation, resets at first, then decodes, and flushes at last. This method should not be invoked
(ByteBuffer in)
| 208 | * if another exception happened during the decode operation. |
| 209 | */ |
| 210 | public final CharBuffer decode(ByteBuffer in) |
| 211 | throws CharacterCodingException { |
| 212 | reset(); |
| 213 | int length = (int) (in.remaining() * averChars); |
| 214 | CharBuffer output = CharBuffer.allocate(length); |
| 215 | CoderResult result = null; |
| 216 | while (true) { |
| 217 | result = decode(in, output, false); |
| 218 | checkCoderResult(result); |
| 219 | if (result.isUnderflow()) { |
| 220 | break; |
| 221 | } else if (result.isOverflow()) { |
| 222 | output = allocateMore(output); |
| 223 | } |
| 224 | } |
| 225 | result = decode(in, output, true); |
| 226 | checkCoderResult(result); |
| 227 | |
| 228 | while (true) { |
| 229 | result = flush(output); |
| 230 | checkCoderResult(result); |
| 231 | if (result.isOverflow()) { |
| 232 | output = allocateMore(output); |
| 233 | } else { |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | output.flip(); |
| 239 | status = FLUSH; |
| 240 | return output; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * checks the result whether it needs to throw CharacterCodingException. |
nothing calls this directly
no test coverage detected