private java.nio.CharBuffer allocateMore(java.nio.CharBuffer output) { if (output.capacity() == 0) { return(java.nio.CharBuffer.allocate(1)); } java.nio.CharBuffer result = java.nio.CharBuffer.allocate(output.capacity() * 2); output.flip(); result.put(output); return(result); }
/// <summary>This is a facade method for the decoding operation.</summary> /// <remarks> /// This is a facade method for the decoding operation. /// <p> /// 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. /// <p> /// This method should not be invoked while another /// <code>decode</code> /// operation /// is ongoing. /// </remarks> /// <param name="in">the input buffer.</param> /// <returns> /// a new <code>CharBuffer</code> containing the the characters /// produced by this decoding operation. The buffer's limit will be /// the position of the last character in the buffer, and the /// position will be zero. /// </returns> /// <exception cref="System.InvalidOperationException">if another decoding operation is ongoing. /// </exception> /// <exception cref="MalformedInputException"> /// if an illegal input byte sequence for this charset was /// encountered, and the action for malformed error is /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// </exception> /// <exception cref="UnmappableCharacterException"> /// if a legal but unmappable input byte sequence for this /// charset was encountered, and the action for unmappable /// character error is /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// . /// Unmappable means the byte sequence at the input buffer's /// current position cannot be mapped to a Unicode character /// sequence. /// </exception> /// <exception cref="CharacterCodingException">if another exception happened during the decode operation. /// </exception> /// <exception cref="java.nio.charset.CharacterCodingException"></exception> public java.nio.CharBuffer decode(java.nio.ByteBuffer @in) { reset(); int length = (int)(@in.remaining() * _averageCharsPerByte); java.nio.CharBuffer output = java.nio.CharBuffer.allocate(length); java.nio.charset.CoderResult result = null; while (true) { result = decode(@in, output, false); checkCoderResult(result); if (result.isUnderflow()) { break; } else { if (result.isOverflow()) { output = allocateMore(output); } } } result = decode(@in, output, true); checkCoderResult(result); while (true) { result = flush(output); checkCoderResult(result); if (result.isOverflow()) { output = allocateMore(output); } else { break; } } output.flip(); status = FLUSH; return(output); }