APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.nio.charset

public final Class CoderResult

extends Object
Class Inheritance
Imports
java.nio.BufferOverflowException, .BufferUnderflowException, java.util.concurrent.ConcurrentHashMap, java.util.Map

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.

Authors
Mark Reinhold, JSR-51 Expert Group
Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int
private static final int
private final int
private static final CoderResult[]
private static final String[]
public static final CoderResult
OVERFLOW

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

private final int
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.

private static final CoderResult[]

Constructor Summary

AccessConstructor and Description
private
CoderResult(int type, int length)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if, and only if, this object denotes either a malformed-input error or an unmappable-character error
isError
()

Tells whether or not this object describes an error condition.

public boolean

Returns:

true if, and only if, this object denotes a malformed-input error
isMalformed
()

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

public boolean

Returns:

true if, and only if, this object denotes overflow
isOverflow
()

Tells whether or not this object describes an overflow condition.

public boolean

Returns:

true if, and only if, this object denotes underflow
isUnderflow
()

Tells whether or not this object describes an underflow condition.

public boolean

Returns:

true if, and only if, this object denotes an unmappable-character error
isUnmappable
()

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

public int

Returns:

The length of the erroneous input, a positive integer
length
()

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

public static CoderResult

Returns:

The requested coder-result object
malformedForLength
(int
The given length
length
)

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

public void
throwException()

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

public String

Returns:

A descriptive string
toString
()

Overrides java.lang.Object.toString.

Returns a string describing this coder result.

public static CoderResult

Returns:

The requested coder-result object
unmappableForLength
(int
The given length
length
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CR_ERROR_MINback to summary
private static final int CR_ERROR_MIN
CR_MALFORMEDback to summary
private static final int CR_MALFORMED
CR_OVERFLOWback to summary
private static final int CR_OVERFLOW
CR_UNDERFLOWback to summary
private static final int CR_UNDERFLOW
CR_UNMAPPABLEback to summary
private static final int CR_UNMAPPABLE
lengthback to summary
private final int length
malformed4back to summary
private static final CoderResult[] malformed4
namesback to summary
private static final String[] names
OVERFLOWback to summary
public static final CoderResult OVERFLOW

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

typeback to summary
private final int type
UNDERFLOWback to summary
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.

unmappable4back to summary
private static final CoderResult[] unmappable4

Constructor Detail

CoderResultback to summary
private CoderResult(int type, int length)

Method Detail

isErrorback to summary
public 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

isMalformedback to summary
public 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

isOverflowback to summary
public boolean isOverflow()

Tells whether or not this object describes an overflow condition.

Returns:boolean

true if, and only if, this object denotes overflow

isUnderflowback to summary
public boolean isUnderflow()

Tells whether or not this object describes an underflow condition.

Returns:boolean

true if, and only if, this object denotes underflow

isUnmappableback to summary
public 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

lengthback to summary
public 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

Exceptions
UnsupportedOperationException:
If this object does not describe an error condition, that is, if the isError does not return true
malformedForLengthback to summary
public static CoderResult malformedForLength(int length)

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

Parameters
length:int

The given length

Returns:CoderResult

The requested coder-result object

throwExceptionback to summary
public void throwException() throws CharacterCodingException

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

Exceptions
CharacterCodingException:
MalformedInputException if this object represents a malformed-input error; UnmappableCharacterException if this object represents an unmappable-character error
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 exception's length value will be that of this object
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string describing this coder result.

Returns:String

A descriptive string

unmappableForLengthback to summary
public static 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

The given length

Returns:CoderResult

The requested coder-result object

java.nio.charset back to summary

private final Class CoderResult.Cache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final CoderResult.Cache
pack-priv final Map<Integer, CoderResult>
pack-priv final Map<Integer, CoderResult>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
pack-priv static final CoderResult.Cache INSTANCE
malformedback to summary
pack-priv final Map<Integer, CoderResult> malformed
unmappableback to summary
pack-priv final Map<Integer, CoderResult> unmappable

Constructor Detail

Cacheback to summary
private Cache()