Sdílet prostřednictvím


CharsetDecoder.Decode Method

Definition

Overloads

Decode(ByteBuffer)

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

Decode(ByteBuffer, CharBuffer, Boolean)

Decodes as many bytes as possible from the given input buffer, writing the results to the given output buffer.

Decode(ByteBuffer)

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

[Android.Runtime.Register("decode", "(Ljava/nio/ByteBuffer;)Ljava/nio/CharBuffer;", "")]
public Java.Nio.CharBuffer? Decode (Java.Nio.ByteBuffer? in);
[<Android.Runtime.Register("decode", "(Ljava/nio/ByteBuffer;)Ljava/nio/CharBuffer;", "")>]
member this.Decode : Java.Nio.ByteBuffer -> Java.Nio.CharBuffer

Parameters

in
ByteBuffer

The input byte buffer

Returns

A newly-allocated character buffer containing the result of the decoding operation. The buffer's position will be zero and its limit will follow the last character written.

Attributes

Exceptions

if another decoding operation is ongoing.

if an illegal input byte sequence for this charset was encountered, and the action for malformed error is Report

if a legal but unmappable input byte sequence for this charset was encountered, and the action for unmappable character error is Report. Unmappable means the byte sequence at the input buffer's current position cannot be mapped to a Unicode character sequence.

if another exception happened during the decode operation.

Remarks

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

This method implements an entire decoding operation; that is, it resets this decoder, then it decodes the bytes in the given byte buffer, and finally it flushes this decoder. This method should therefore not be invoked if a decoding operation is already in progress.

Java documentation for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer).

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.

Applies to

Decode(ByteBuffer, CharBuffer, Boolean)

Decodes as many bytes as possible from the given input buffer, writing the results to the given output buffer.

[Android.Runtime.Register("decode", "(Ljava/nio/ByteBuffer;Ljava/nio/CharBuffer;Z)Ljava/nio/charset/CoderResult;", "")]
public Java.Nio.Charset.CoderResult? Decode (Java.Nio.ByteBuffer? in, Java.Nio.CharBuffer? out, bool endOfInput);
[<Android.Runtime.Register("decode", "(Ljava/nio/ByteBuffer;Ljava/nio/CharBuffer;Z)Ljava/nio/charset/CoderResult;", "")>]
member this.Decode : Java.Nio.ByteBuffer * Java.Nio.CharBuffer * bool -> Java.Nio.Charset.CoderResult

Parameters

in
ByteBuffer

The input byte buffer

out
CharBuffer

The output character buffer

endOfInput
Boolean

true if, and only if, the invoker can provide no additional input bytes beyond those in the given buffer

Returns

A coder-result object describing the reason for termination

Attributes

Exceptions

if decoding has started or no more input is needed in this decoding progress.

if the DecodeLoop(ByteBuffer, CharBuffer) method threw an BufferUnderflowException or BufferOverflowException.

Remarks

Decodes as many bytes as possible from the given input buffer, writing the results to the given output buffer.

The buffers are read from, and written to, starting at their current positions. At most Buffer#remaining in.remaining() bytes will be read and at most Buffer#remaining out.remaining() characters will be written. The buffers' positions will be advanced to reflect the bytes read and the characters written, but their marks and limits will not be modified.

In addition to reading bytes from the input buffer and writing characters to the output buffer, this method returns a CoderResult object to describe its reason for termination:

<ul>

<li>

CoderResult#UNDERFLOW indicates that as much of the input buffer as possible has been decoded. If there is no further input then the invoker can proceed to the next step of the decoding operation. Otherwise this method should be invoked again with further input.

</li>

<li>

CoderResult#OVERFLOW indicates that there is insufficient space in the output buffer to decode any more bytes. This method should be invoked again with an output buffer that has more Buffer#remaining remaining characters. This is typically done by draining any decoded characters from the output buffer.

</li>

<li>

A CoderResult#malformedForLength malformed-input result indicates that a malformed-input error has been detected. The malformed bytes begin at the input buffer's (possibly incremented) position; the number of malformed bytes may be determined by invoking the result object's CoderResult#length() length method. This case applies only if the #onMalformedInput malformed action of this decoder is CodingErrorAction#REPORT; otherwise the malformed input will be ignored or replaced, as requested.

</li>

<li>

An CoderResult#unmappableForLength unmappable-character result indicates that an unmappable-character error has been detected. The bytes that decode the unmappable character begin at the input buffer's (possibly incremented) position; the number of such bytes may be determined by invoking the result object's CoderResult#length() length method. This case applies only if the #onUnmappableCharacter unmappable action of this decoder is CodingErrorAction#REPORT; otherwise the unmappable character will be ignored or replaced, as requested.

</li>

</ul>

In any case, if this method is to be reinvoked in the same decoding operation then care should be taken to preserve any bytes remaining in the input buffer so that they are available to the next invocation.

The endOfInput parameter advises this method as to whether the invoker can provide further input beyond that contained in the given input buffer. If there is a possibility of providing additional input then the invoker should pass false for this parameter; if there is no possibility of providing further input then the invoker should pass true. It is not erroneous, and in fact it is quite common, to pass false in one invocation and later discover that no further input was actually available. It is critical, however, that the final invocation of this method in a sequence of invocations always pass true so that any remaining undecoded input will be treated as being malformed.

This method works by invoking the #decodeLoop decodeLoop method, interpreting its results, handling error conditions, and reinvoking it as necessary.

Java documentation for java.nio.charset.CharsetDecoder.decode(java.nio.ByteBuffer, java.nio.CharBuffer, boolean).

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.

Applies to