// implementation of canEncode private bool implCanEncode(java.nio.CharBuffer cb) { if (status == FLUSH || status == INIT) { status = READY; } if (status != READY) { throw new System.InvalidOperationException("encoding already in progress"); } java.nio.charset.CodingErrorAction malformBak = _malformedInputAction; java.nio.charset.CodingErrorAction unmapBak = _unmappableCharacterAction; onMalformedInput(java.nio.charset.CodingErrorAction.REPORT); onUnmappableCharacter(java.nio.charset.CodingErrorAction.REPORT); bool result = true; try { this.encode(cb); } catch (java.nio.charset.CharacterCodingException) { result = false; } onMalformedInput(malformBak); onUnmappableCharacter(unmapBak); reset(); return(result); }
internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1, float maxBytesPerChar_1, byte[] replacement_1, bool trusted) { // internal status indicates encode(CharBuffer) operation is finished // decoder instance for this encoder's charset, used for replacement value checking if (averageBytesPerChar_1 <= 0 || maxBytesPerChar_1 <= 0) { throw new System.ArgumentException("averageBytesPerChar and maxBytesPerChar must both be positive" ); } if (averageBytesPerChar_1 > maxBytesPerChar_1) { throw new System.ArgumentException("averageBytesPerChar is greater than maxBytesPerChar" ); } this.cs = cs; this._averageBytesPerChar = averageBytesPerChar_1; this._maxBytesPerChar = maxBytesPerChar_1; status = INIT; _malformedInputAction = java.nio.charset.CodingErrorAction.REPORT; _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT; if (trusted) { // The RI enforces unnecessary restrictions on the replacement bytes. We trust ICU to // know what it's doing. Doing so lets us support ICU's EUC-JP, SCSU, and Shift_JIS. this.replacementBytes = replacement_1; } else { replaceWith(replacement_1); } }
/// <summary>Sets this encoder's action on unmappable character error.</summary> /// <remarks> /// Sets this encoder's action on unmappable character error. /// This method will call the /// <see cref="implOnUnmappableCharacter(CodingErrorAction)">implOnUnmappableCharacter /// </see> /// method with the given new action as argument. /// </remarks> /// <param name="newAction">the new action on unmappable character error.</param> /// <returns>this encoder.</returns> /// <exception cref="System.ArgumentException">if the given newAction is null.</exception> public java.nio.charset.CharsetEncoder onUnmappableCharacter(java.nio.charset.CodingErrorAction newAction) { if (newAction == null) { throw new System.ArgumentException("newAction == null"); } _unmappableCharacterAction = newAction; implOnUnmappableCharacter(newAction); return(this); }
/// <summary>Sets this encoder's action on malformed input error.</summary> /// <remarks> /// Sets this encoder's action on malformed input error. /// This method will call the /// <see cref="implOnMalformedInput(CodingErrorAction)">implOnMalformedInput</see> /// method with the given new action as argument. /// </remarks> /// <param name="newAction">the new action on malformed input error.</param> /// <returns>this encoder.</returns> /// <exception cref="System.ArgumentException">if the given newAction is null.</exception> public java.nio.charset.CharsetEncoder onMalformedInput(java.nio.charset.CodingErrorAction newAction) { if (newAction == null) { throw new System.ArgumentException("newAction == null"); } _malformedInputAction = newAction; implOnMalformedInput(newAction); return(this); }
public virtual global::java.nio.charset.CharsetDecoder onMalformedInput(java.nio.charset.CodingErrorAction arg0) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; if (!IsClrObject) { return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::java.nio.charset.CharsetDecoder._onMalformedInput14702, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.nio.charset.CharsetDecoder); } else { return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::java.nio.charset.CharsetDecoder.staticClass, global::java.nio.charset.CharsetDecoder._onMalformedInput14702, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as java.nio.charset.CharsetDecoder); } }
protected virtual void implOnUnmappableCharacter(java.nio.charset.CodingErrorAction arg0) { global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv; if (!IsClrObject) { @__env.CallVoidMethod(this.JvmHandle, global::java.nio.charset.CharsetDecoder._implOnUnmappableCharacter14710, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)); } else { @__env.CallNonVirtualVoidMethod(this.JvmHandle, global::java.nio.charset.CharsetDecoder.staticClass, global::java.nio.charset.CharsetDecoder._implOnUnmappableCharacter14710, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)); } }
/// <summary> /// Constructs a new <code>CharsetDecoder</code> using the given /// <code>Charset</code>, average number and maximum number of characters /// created by this decoder for one input byte, and the default replacement /// string "\uFFFD". /// </summary> /// <remarks> /// Constructs a new <code>CharsetDecoder</code> using the given /// <code>Charset</code>, average number and maximum number of characters /// created by this decoder for one input byte, and the default replacement /// string "\uFFFD". /// </remarks> /// <param name="charset">the <code>Charset</code> to be used by this decoder.</param> /// <param name="averageCharsPerByte"> /// the average number of characters created by this decoder for /// one input byte, must be positive. /// </param> /// <param name="maxCharsPerByte"> /// the maximum number of characters created by this decoder for /// one input byte, must be positive. /// </param> /// <exception cref="System.ArgumentException"> /// if <code>averageCharsPerByte</code> or /// <code>maxCharsPerByte</code> is negative. /// </exception> protected internal CharsetDecoder(java.nio.charset.Charset charset_1, float averageCharsPerByte_1 , float maxCharsPerByte_1) { if (averageCharsPerByte_1 <= 0 || maxCharsPerByte_1 <= 0) { throw new System.ArgumentException("averageCharsPerByte and maxCharsPerByte must be positive" ); } if (averageCharsPerByte_1 > maxCharsPerByte_1) { throw new System.ArgumentException("averageCharsPerByte is greater than maxCharsPerByte" ); } this._averageCharsPerByte = averageCharsPerByte_1; this._maxCharsPerByte = maxCharsPerByte_1; cs = charset_1; status = INIT; _malformedInputAction = java.nio.charset.CodingErrorAction.REPORT; _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT; replacementChars = "\ufffd"; }
// default implementation is empty /// <summary> /// Notifies that this encoder's <code>CodingErrorAction</code> specified /// for unmappable character error has been changed. /// </summary> /// <remarks> /// Notifies that this encoder's <code>CodingErrorAction</code> specified /// for unmappable character error has been changed. The default /// implementation does nothing; this method can be overridden if needed. /// </remarks> /// <param name="newAction">the new action.</param> protected internal virtual void implOnUnmappableCharacter(java.nio.charset.CodingErrorAction newAction) { }
/// <summary> /// Notifies that this encoder's <code>CodingErrorAction</code> specified /// for malformed input error has been changed. /// </summary> /// <remarks> /// Notifies that this encoder's <code>CodingErrorAction</code> specified /// for malformed input error has been changed. The default implementation /// does nothing; this method can be overridden if needed. /// </remarks> /// <param name="newAction">the new action.</param> protected internal virtual void implOnMalformedInput(java.nio.charset.CodingErrorAction newAction) { }
/// <summary> /// Encodes characters starting at the current position of the given input /// buffer, and writes the equivalent byte sequence into the given output /// buffer from its current position. /// </summary> /// <remarks> /// Encodes characters starting at the current position of the given input /// buffer, and writes the equivalent byte 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>A /// <see cref="CoderResult.malformedForLength(int)">malformed input</see> /// result /// indicates that some malformed input error was encountered, and the /// erroneous characters 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> /// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see> /// indicates that /// as many characters as possible in the input buffer have been encoded. If /// there is no further input and no characters left in the input buffer then /// this task is complete. If this is not the case then the client should /// call this method again supplying some more input characters.</li> /// <li> /// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see> /// indicates that the /// output buffer has been filled, while there are still some characters /// remaining in the input buffer. This method should be invoked again with a /// non-full output buffer.</li> /// <li>A /// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see> /// result indicates that some unmappable character error was encountered, /// and the erroneous characters 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 on /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see> /// .</li> /// </ul> /// <p> /// The <code>endOfInput</code> parameter indicates if the invoker can /// provider further input. This parameter is true if and only if the /// characters in the current input buffer are all inputs for this encoding /// operation. Note that it is common and won't cause an error if the invoker /// sets false and then has no more input available, 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. /// input. /// <p> /// This method invokes the /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see> /// method to /// implement the basic encode 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 indicating the result.</returns> /// <exception cref="System.InvalidOperationException"> /// if the encoding operation has already started or no more /// input is needed in this encoding process. /// </exception> /// <exception cref="CoderMalfunctionError"> /// If the /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see> /// method threw an <code>BufferUnderflowException</code> or /// <code>BufferUnderflowException</code>. /// </exception> public java.nio.charset.CoderResult encode(java.nio.CharBuffer @in, java.nio.ByteBuffer @out, bool endOfInput) { // If the previous step is encode(CharBuffer), then no more input is needed // thus endOfInput should not be false if (status == READY && finished && !endOfInput) { throw new System.InvalidOperationException(); } if ((status == FLUSH) || (!endOfInput && status == END)) { throw new System.InvalidOperationException(); } java.nio.charset.CoderResult result; while (true) { try { result = encodeLoop(@in, @out); } catch (java.nio.BufferOverflowException e) { throw new java.nio.charset.CoderMalfunctionError(e); } catch (java.nio.BufferUnderflowException e) { throw new java.nio.charset.CoderMalfunctionError(e); } if (result == java.nio.charset.CoderResult.UNDERFLOW) { status = endOfInput ? END : ONGOING; if (endOfInput) { int remaining = @in.remaining(); if (remaining > 0) { result = java.nio.charset.CoderResult.malformedForLength(remaining); } else { return(result); } } else { return(result); } } else { if (result == java.nio.charset.CoderResult.OVERFLOW) { status = endOfInput ? END : ONGOING; return(result); } } java.nio.charset.CodingErrorAction action = _malformedInputAction; if (result.isUnmappable()) { action = _unmappableCharacterAction; } // If the action is IGNORE or REPLACE, we should continue // encoding. if (action == java.nio.charset.CodingErrorAction.REPLACE) { if (@out.remaining() < replacementBytes.Length) { return(java.nio.charset.CoderResult.OVERFLOW); } @out.put(replacementBytes); } else { if (action != java.nio.charset.CodingErrorAction.IGNORE) { return(result); } } @in.position(@in.position() + result.length()); } }
/// <summary>Sets this decoder's action on unmappable character errors.</summary> /// <remarks> /// Sets this decoder's action on unmappable character errors. /// This method will call the /// <see cref="implOnUnmappableCharacter(CodingErrorAction)">implOnUnmappableCharacter /// </see> /// method with the given new action as argument. /// </remarks> /// <param name="newAction">the new action on unmappable character error.</param> /// <returns>this decoder.</returns> /// <exception cref="System.ArgumentException"> /// if /// <code>newAction</code> /// is /// <code>null</code> /// . /// </exception> public java.nio.charset.CharsetDecoder onUnmappableCharacter(java.nio.charset.CodingErrorAction newAction) { if (newAction == null) { throw new System.ArgumentException(); } _unmappableCharacterAction = newAction; implOnUnmappableCharacter(newAction); return this; }
/// <summary>Sets this decoder's action on malformed input errors.</summary> /// <remarks> /// Sets this decoder's action on malformed input errors. /// This method will call the /// <see cref="implOnMalformedInput(CodingErrorAction)">implOnMalformedInput</see> /// method with the given new action as argument. /// </remarks> /// <param name="newAction">the new action on malformed input error.</param> /// <returns>this decoder.</returns> /// <exception cref="System.ArgumentException"> /// if /// <code>newAction</code> /// is /// <code>null</code> /// . /// </exception> public java.nio.charset.CharsetDecoder onMalformedInput(java.nio.charset.CodingErrorAction newAction) { if (newAction == null) { throw new System.ArgumentException(); } _malformedInputAction = newAction; implOnMalformedInput(newAction); return this; }
/// <summary> /// Constructs a new <code>CharsetDecoder</code> using the given /// <code>Charset</code>, average number and maximum number of characters /// created by this decoder for one input byte, and the default replacement /// string "\uFFFD". /// </summary> /// <remarks> /// Constructs a new <code>CharsetDecoder</code> using the given /// <code>Charset</code>, average number and maximum number of characters /// created by this decoder for one input byte, and the default replacement /// string "\uFFFD". /// </remarks> /// <param name="charset">the <code>Charset</code> to be used by this decoder.</param> /// <param name="averageCharsPerByte"> /// the average number of characters created by this decoder for /// one input byte, must be positive. /// </param> /// <param name="maxCharsPerByte"> /// the maximum number of characters created by this decoder for /// one input byte, must be positive. /// </param> /// <exception cref="System.ArgumentException"> /// if <code>averageCharsPerByte</code> or /// <code>maxCharsPerByte</code> is negative. /// </exception> protected internal CharsetDecoder(java.nio.charset.Charset charset_1, float averageCharsPerByte_1 , float maxCharsPerByte_1) { if (averageCharsPerByte_1 <= 0 || maxCharsPerByte_1 <= 0) { throw new System.ArgumentException("averageCharsPerByte and maxCharsPerByte must be positive" ); } if (averageCharsPerByte_1 > maxCharsPerByte_1) { throw new System.ArgumentException("averageCharsPerByte is greater than maxCharsPerByte" ); } this._averageCharsPerByte = averageCharsPerByte_1; this._maxCharsPerByte = maxCharsPerByte_1; cs = charset_1; status = INIT; _malformedInputAction = java.nio.charset.CodingErrorAction.REPORT; _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT; replacementChars = "\ufffd"; }
internal CharsetEncoder(java.nio.charset.Charset cs, float averageBytesPerChar_1, float maxBytesPerChar_1, byte[] replacement_1, bool trusted) { // internal status indicates encode(CharBuffer) operation is finished // decoder instance for this encoder's charset, used for replacement value checking if (averageBytesPerChar_1 <= 0 || maxBytesPerChar_1 <= 0) { throw new System.ArgumentException("averageBytesPerChar and maxBytesPerChar must both be positive" ); } if (averageBytesPerChar_1 > maxBytesPerChar_1) { throw new System.ArgumentException("averageBytesPerChar is greater than maxBytesPerChar" ); } this.cs = cs; this._averageBytesPerChar = averageBytesPerChar_1; this._maxBytesPerChar = maxBytesPerChar_1; status = INIT; _malformedInputAction = java.nio.charset.CodingErrorAction.REPORT; _unmappableCharacterAction = java.nio.charset.CodingErrorAction.REPORT; if (trusted) { // The RI enforces unnecessary restrictions on the replacement bytes. We trust ICU to // know what it's doing. Doing so lets us support ICU's EUC-JP, SCSU, and Shift_JIS. this.replacementBytes = replacement_1; } else { replaceWith(replacement_1); } }
/// <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()); } }