CharsetEncoder Class

Definition

An engine that can transform a sequence of sixteen-bit Unicode characters into a sequence of bytes in a specific charset.

[Android.Runtime.Register("java/nio/charset/CharsetEncoder", DoNotGenerateAcw=true)]
public abstract class CharsetEncoder : Java.Lang.Object
[<Android.Runtime.Register("java/nio/charset/CharsetEncoder", DoNotGenerateAcw=true)>]
type CharsetEncoder = class
    inherit Object
Inheritance
CharsetEncoder
Attributes

Remarks

An engine that can transform a sequence of sixteen-bit Unicode characters into a sequence of bytes in a specific charset.

"steps">

The input character sequence is provided in a character buffer or a series of such buffers. The output byte sequence is written to a byte buffer or a series of such buffers. An encoder should always be used by making the following sequence of method invocations, hereinafter referred to as an encoding operation:

<ol>

<li>

Reset the encoder via the #reset reset method, unless it has not been used before;

</li>

<li>

Invoke the #encode encode method zero or more times, as long as additional input may be available, passing false for the endOfInput argument and filling the input buffer and flushing the output buffer between invocations;

</li>

<li>

Invoke the #encode encode method one final time, passing true for the endOfInput argument; and then

</li>

<li>

Invoke the #flush flush method so that the encoder can flush any internal state to the output buffer.

</li>

</ol>

Each invocation of the #encode encode method will encode as many characters as possible from the input buffer, writing the resulting bytes to the output buffer. The #encode encode method returns when more input is required, when there is not enough room in the output buffer, or when an encoding error has occurred. In each case a CoderResult object is returned to describe the reason for termination. An invoker can examine this object and fill the input buffer, flush the output buffer, or attempt to recover from an encoding error, as appropriate, and try again.

"ce">

There are two general types of encoding errors. If the input character sequence is not a legal sixteen-bit Unicode sequence then the input is considered malformed. If the input character sequence is legal but cannot be mapped to a valid byte sequence in the given charset then an unmappable character has been encountered.

"cae">

How an encoding error is handled depends upon the action requested for that type of error, which is described by an instance of the CodingErrorAction class. The possible error actions are to CodingErrorAction#IGNORE ignore the erroneous input, CodingErrorAction#REPORT report the error to the invoker via the returned CoderResult object, or CodingErrorAction#REPLACE replace the erroneous input with the current value of the replacement byte array. The replacement

is initially set to the encoder's default replacement, which often (but not always) has the initial value&nbsp;{&nbsp;(byte)'?'&nbsp;};

its value may be changed via the #replaceWith(byte[]) replaceWith method.

The default action for malformed-input and unmappable-character errors is to CodingErrorAction#REPORT report them. The malformed-input error action may be changed via the #onMalformedInput(CodingErrorAction) onMalformedInput method; the unmappable-character action may be changed via the #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter method.

This class is designed to handle many of the details of the encoding process, including the implementation of error actions. An encoder for a specific charset, which is a concrete subclass of this class, need only implement the abstract #encodeLoop encodeLoop method, which encapsulates the basic encoding loop. A subclass that maintains internal state should, additionally, override the #implFlush implFlush and #implReset implReset methods.

Instances of this class are not safe for use by multiple concurrent threads.

Added in 1.4.

Java documentation for java.nio.charset.CharsetEncoder.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

CharsetEncoder(Charset, Single, Single)

Initializes a new encoder.

CharsetEncoder(Charset, Single, Single, Byte[])

Initializes a new encoder.

CharsetEncoder(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

AverageBytesPerChar()

Returns the average number of bytes that will be produced for each character of input.

CanEncode(Char)

Tells whether or not this encoder can encode the given character.

CanEncode(ICharSequence)

Tells whether or not this encoder can encode the given character sequence.

CanEncode(String)

Tells whether or not this encoder can encode the given character sequence.

Charset()

Returns the charset that created this encoder.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Encode(CharBuffer)

Convenience method that encodes the remaining content of a single input character buffer into a newly-allocated byte buffer.

Encode(CharBuffer, ByteBuffer, Boolean)

Encodes as many characters as possible from the given input buffer, writing the results to the given output buffer.

EncodeLoop(CharBuffer, ByteBuffer)

Encodes one or more characters into one or more bytes.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Flush(ByteBuffer)

Flushes this encoder.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
ImplFlush(ByteBuffer)

Flushes this encoder.

ImplOnMalformedInput(CodingErrorAction)

Reports a change to this encoder's malformed-input action.

ImplOnUnmappableCharacter(CodingErrorAction)

Reports a change to this encoder's unmappable-character action.

ImplReplaceWith(Byte[])

Reports a change to this encoder's replacement value.

ImplReset()

Resets this encoder, clearing any charset-specific internal state.

IsLegalReplacement(Byte[])

Tells whether or not the given byte array is a legal replacement value for this encoder.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
MalformedInputAction()

Returns this encoder's current action for malformed-input errors.

MaxBytesPerChar()

Returns the maximum number of bytes that will be produced for each character of input.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnMalformedInput(CodingErrorAction)

Changes this encoder's action for malformed-input errors.

OnUnmappableCharacter(CodingErrorAction)

Changes this encoder's action for unmappable-character errors.

Replacement()

Returns this encoder's replacement value.

ReplaceWith(Byte[])

Changes this encoder's replacement value.

Reset()

Resets this encoder, clearing any internal state.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnmappableCharacterAction()

Returns this encoder's current action for unmappable-character errors.

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to