Package java.nio.charset
Class CoderResult
java.lang.Object
java.nio.charset.CoderResult
public class CoderResult extends Object
Used to indicate the result of encoding/decoding. There are four types of
results:
- UNDERFLOW indicates that all input has been processed but more input is
required. It is represented by the unique object
CoderResult.UNDERFLOW. - OVERFLOW indicates an insufficient output buffer size. It is represented
by the unique object
CoderResult.OVERFLOW. - A malformed-input error indicates that an unrecognizable sequence of
input units has been encountered. Get an instance of this type of result by
calling
CoderResult.malformedForLength(int)with the length of the malformed-input. - An unmappable-character error indicates that a sequence of input units
can not be mapped to the output charset. Get an instance of this type of
result by calling
CoderResult.unmappableForLength(int)with the input sequence size indicating the identity of the unmappable character.
-
Field Summary
Fields Modifier and Type Field Description static CoderResultOVERFLOWResult object used to indicate that the output buffer does not have enough space available to store the result of the encoding/decoding.static CoderResultUNDERFLOWResult object indicating that there is insufficient data in the encoding/decoding buffer or that additional data is required. -
Method Summary
Modifier and Type Method Description booleanisError()Returns true if this result represents a malformed-input error or an unmappable-character error.booleanisMalformed()Returns true if this result represents a malformed-input error.booleanisOverflow()Returns true if this result is an overflow condition.booleanisUnderflow()Returns true if this result is an underflow condition.booleanisUnmappable()Returns true if this result represents an unmappable-character error.intlength()Returns the length of the erroneous input.static CoderResultmalformedForLength(int length)Gets aCoderResultobject indicating a malformed-input error.voidthrowException()Throws an exception corresponding to this coder result.StringtoString()Returns a text description of this result.static CoderResultunmappableForLength(int length)Gets aCoderResultobject indicating an unmappable character error.
-
Field Details
-
UNDERFLOW
Result object indicating that there is insufficient data in the encoding/decoding buffer or that additional data is required. -
OVERFLOW
Result object used to indicate that the output buffer does not have enough space available to store the result of the encoding/decoding.
-
-
Method Details
-
malformedForLength
Gets aCoderResultobject indicating a malformed-input error.- Parameters:
length- the length of the malformed-input.- Returns:
- a
CoderResultobject indicating a malformed-input error. - Throws:
IllegalArgumentException- iflengthis non-positive.
-
unmappableForLength
Gets aCoderResultobject indicating an unmappable character error.- Parameters:
length- the length of the input unit sequence denoting the unmappable character.- Returns:
- a
CoderResultobject indicating an unmappable character error. - Throws:
IllegalArgumentException- iflengthis non-positive.
-
isUnderflow
public boolean isUnderflow()Returns true if this result is an underflow condition. -
isError
public boolean isError()Returns true if this result represents a malformed-input error or an unmappable-character error. -
isMalformed
public boolean isMalformed()Returns true if this result represents a malformed-input error. -
isOverflow
public boolean isOverflow()Returns true if this result is an overflow condition. -
isUnmappable
public boolean isUnmappable()Returns true if this result represents an unmappable-character error. -
length
Returns the length of the erroneous input. The length is only meaningful for a malformed-input error or an unmappable character error.- Throws:
UnsupportedOperationException- if this result is an overflow or underflow.
-
throwException
public void throwException() throws BufferUnderflowException, BufferOverflowException, UnmappableCharacterException, MalformedInputException, CharacterCodingExceptionThrows an exception corresponding to this coder result.- Throws:
BufferUnderflowException- in case this is an underflow.BufferOverflowException- in case this is an overflow.UnmappableCharacterException- in case this is an unmappable-character error.MalformedInputException- in case this is a malformed-input error.CharacterCodingException- the default exception.
-
toString
Returns a text description of this result.
-