Most visited

Recently visited

Added in API level 1

CoderResult

public class CoderResult
extends Object

java.lang.Object
   ↳ java.nio.charset.CoderResult


A description of the result state of a coder.

A charset coder, that is, either a decoder or an encoder, consumes bytes (or characters) from an input buffer, translates them, and writes the resulting characters (or bytes) to an output buffer. A coding process terminates for one of four categories of reasons, which are described by instances of this class:

For convenience, the isError method returns true for result objects that describe malformed-input and unmappable-character errors but false for those that describe underflow or overflow conditions.

Summary

Fields

public static final CoderResult OVERFLOW

Result object indicating overflow, meaning that there is insufficient room in the output buffer.

public static final CoderResult UNDERFLOW

Result object indicating underflow, meaning that either the input buffer has been completely consumed or, if the input buffer is not yet empty, that additional input is required.

Public methods

boolean isError()

Tells whether or not this object describes an error condition.

boolean isMalformed()

Tells whether or not this object describes a malformed-input error.

boolean isOverflow()

Tells whether or not this object describes an overflow condition.

boolean isUnderflow()

Tells whether or not this object describes an underflow condition.

boolean isUnmappable()

Tells whether or not this object describes an unmappable-character error.

int length()

Returns the length of the erroneous input described by this object  (optional operation).

static CoderResult malformedForLength(int length)

Static factory method that returns the unique object describing a malformed-input error of the given length.

void throwException()

Throws an exception appropriate to the result described by this object.

String toString()

Returns a string describing this coder result.

static CoderResult unmappableForLength(int length)

Static factory method that returns the unique result object describing an unmappable-character error of the given length.

Inherited methods

From class java.lang.Object

Fields

OVERFLOW

Added in API level 1
CoderResult OVERFLOW

Result object indicating overflow, meaning that there is insufficient room in the output buffer.

UNDERFLOW

Added in API level 1
CoderResult UNDERFLOW

Result object indicating underflow, meaning that either the input buffer has been completely consumed or, if the input buffer is not yet empty, that additional input is required.

Public methods

isError

Added in API level 1
boolean isError ()

Tells whether or not this object describes an error condition.

Returns
boolean true if, and only if, this object denotes either a malformed-input error or an unmappable-character error

isMalformed

Added in API level 1
boolean isMalformed ()

Tells whether or not this object describes a malformed-input error.

Returns
boolean true if, and only if, this object denotes a malformed-input error

isOverflow

Added in API level 1
boolean isOverflow ()

Tells whether or not this object describes an overflow condition.

Returns
boolean true if, and only if, this object denotes overflow

isUnderflow

Added in API level 1
boolean isUnderflow ()

Tells whether or not this object describes an underflow condition.

Returns
boolean true if, and only if, this object denotes underflow

isUnmappable

Added in API level 1
boolean isUnmappable ()

Tells whether or not this object describes an unmappable-character error.

Returns
boolean true if, and only if, this object denotes an unmappable-character error

length

Added in API level 1
int length ()

Returns the length of the erroneous input described by this object  (optional operation).

Returns
int The length of the erroneous input, a positive integer
Throws
UnsupportedOperationException If this object does not describe an error condition, that is, if the isError does not return true

malformedForLength

Added in API level 1
CoderResult malformedForLength (int length)

Static factory method that returns the unique object describing a malformed-input error of the given length.

Parameters
length int
Returns
CoderResult The requested coder-result object

throwException

Added in API level 1
void throwException ()

Throws an exception appropriate to the result described by this object.

Throws
BufferUnderflowException If this object is UNDERFLOW
BufferOverflowException If this object is OVERFLOW
MalformedInputException If this object represents a malformed-input error; the exception's length value will be that of this object
UnmappableCharacterException If this object represents an unmappable-character error; the exceptions length value will be that of this object
CharacterCodingException

toString

Added in API level 1
String toString ()

Returns a string describing this coder result.

Returns
String A descriptive string

unmappableForLength

Added in API level 1
CoderResult unmappableForLength (int length)

Static factory method that returns the unique result object describing an unmappable-character error of the given length.

Parameters
length int
Returns
CoderResult The requested coder-result object

Hooray!