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); }
public virtual int read(java.nio.CharBuffer target) { int length = target.Length; char[] buf = new char[length]; length = System.Math.Min(length, read(buf)); if (length > 0) { target.put(buf, 0, length); } return(length); }
/// <summary> /// Decodes bytes starting at the current position of the given input buffer, /// and writes the equivalent character sequence into the given output buffer /// from its current position. /// </summary> /// <remarks> /// Decodes bytes starting at the current position of the given input buffer, /// and writes the equivalent character sequence into the given output buffer /// from its current position. /// <p> /// The buffers' position will be changed with the reading and writing /// operation, but their limits and marks will be kept intact. /// <p> /// A <code>CoderResult</code> instance will be returned according to /// following rules: /// <ul> /// <li> /// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see> /// indicates that /// even though not all of the input has been processed, the buffer the /// output is being written to has reached its capacity. In the event of this /// code being returned this method should be called once more with an /// <code>out</code> argument that has not already been filled.</li> /// <li> /// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see> /// indicates that /// as many bytes as possible in the input buffer have been decoded. If there /// is no further input and no remaining bytes in the input buffer then this /// operation may be regarded as complete. Otherwise, this method should be /// called once more with additional input.</li> /// <li>A /// <see cref="CoderResult.malformedForLength(int)">malformed input</see> /// result /// indicates that some malformed input error has been encountered, and the /// erroneous bytes start at the input buffer's position and their number can /// be got by result's /// <see cref="CoderResult.length()">length</see> /// . This kind of /// result can be returned only if the malformed action is /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// . </li> /// <li>A /// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see> /// result indicates that some unmappable character error has been /// encountered, and the erroneous bytes start at the input buffer's position /// and their number can be got by result's /// <see cref="CoderResult.length()">length</see> /// . This kind of result can be returned /// only if the unmappable character action is /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// . </li> /// </ul> /// <p> /// The <code>endOfInput</code> parameter indicates that the invoker cannot /// provide further input. This parameter is true if and only if the bytes in /// current input buffer are all inputs for this decoding operation. Note /// that it is common and won't cause an error if the invoker sets false and /// then can't provide more input, while it may cause an error if the invoker /// always sets true in several consecutive invocations. This would make the /// remaining input to be treated as malformed input. /// <p> /// This method invokes the /// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see> /// method to /// implement the basic decode logic for a specific charset. /// </remarks> /// <param name="in">the input buffer.</param> /// <param name="out">the output buffer.</param> /// <param name="endOfInput">true if all the input characters have been provided.</param> /// <returns> /// a <code>CoderResult</code> instance which indicates the reason /// of termination. /// </returns> /// <exception cref="System.InvalidOperationException"> /// if decoding has started or no more input is needed in this /// decoding progress. /// </exception> /// <exception cref="CoderMalfunctionError"> /// if the /// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see> /// method threw an <code>BufferUnderflowException</code> or /// <code>BufferOverflowException</code>. /// </exception> public java.nio.charset.CoderResult decode(java.nio.ByteBuffer @in, java.nio.CharBuffer @out, bool endOfInput) { if ((status == FLUSH) || (!endOfInput && status == END)) { throw new System.InvalidOperationException(); } java.nio.charset.CoderResult result = null; // begin to decode while (true) { java.nio.charset.CodingErrorAction action = null; try { result = decodeLoop(@in, @out); } catch (java.nio.BufferOverflowException ex) { // unexpected exception throw new java.nio.charset.CoderMalfunctionError(ex); } catch (java.nio.BufferUnderflowException ex) { // unexpected exception throw new java.nio.charset.CoderMalfunctionError(ex); } if (result.isUnderflow()) { int remaining = @in.remaining(); status = endOfInput ? END : ONGOING; if (endOfInput && remaining > 0) { result = java.nio.charset.CoderResult.malformedForLength(remaining); } else { return(result); } } if (result.isOverflow()) { return(result); } // set coding error handle action action = _malformedInputAction; if (result.isUnmappable()) { action = _unmappableCharacterAction; } // If the action is IGNORE or REPLACE, we should continue decoding. if (action == java.nio.charset.CodingErrorAction.REPLACE) { if (@out.remaining() < replacementChars.Length) { return(java.nio.charset.CoderResult.OVERFLOW); } @out.put(replacementChars); } else { if (action != java.nio.charset.CodingErrorAction.IGNORE) { return(result); } } @in.position(@in.position() + result.length()); } }