CoderResultpublic class CoderResult extends Object 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:
Underflow is reported when there is no more input to be
processed, or there is insufficient input and additional input is
required. This condition is represented by the unique result object
{@link #UNDERFLOW}, whose {@link #isUnderflow() isUnderflow} method
returns true.
Overflow is reported when there is insufficient room
remaining in the output buffer. This condition is represented by the
unique result object {@link #OVERFLOW}, whose {@link #isOverflow()
isOverflow} method returns true.
A malformed-input error is reported when a sequence of
input units is not well-formed. Such errors are described by instances of
this class whose {@link #isMalformed() isMalformed} method returns
true and whose {@link #length() length} method returns the length
of the malformed sequence. There is one unique instance of this class for
all malformed-input errors of a given length.
An unmappable-character error is reported when a sequence
of input units denotes a character that cannot be represented in the
output charset. Such errors are described by instances of this class
whose {@link #isUnmappable() isUnmappable} method returns true and
whose {@link #length() length} method returns the length of the input
sequence denoting the unmappable character. There is one unique instance
of this class for all unmappable-character errors of a given length.
For convenience, the {@link #isError() 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. |
Fields Summary |
---|
private static final int | CR_UNDERFLOW | private static final int | CR_OVERFLOW | private static final int | CR_ERROR_MIN | private static final int | CR_MALFORMED | private static final int | CR_UNMAPPABLE | private static final String[] | names | private final int | type | private final int | length | public static final CoderResult | UNDERFLOWResult 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 static final CoderResult | OVERFLOWResult object indicating overflow, meaning that there is insufficient
room in the output buffer. | private static Cache | malformedCache | private static Cache | unmappableCache |
Constructors Summary |
---|
private CoderResult(int type, int length)
this.type = type;
this.length = length;
|
Methods Summary |
---|
public boolean | isError()Tells whether or not this object describes an error condition.
return (type >= CR_ERROR_MIN);
| public boolean | isMalformed()Tells whether or not this object describes a malformed-input error.
return (type == CR_MALFORMED);
| public boolean | isOverflow()Tells whether or not this object describes an overflow condition.
return (type == CR_OVERFLOW);
| public boolean | isUnderflow()Tells whether or not this object describes an underflow condition.
return (type == CR_UNDERFLOW);
| public boolean | isUnmappable()Tells whether or not this object describes an unmappable-character
error.
return (type == CR_UNMAPPABLE);
| public int | length()Returns the length of the erroneous input described by this
object (optional operation).
if (!isError())
throw new UnsupportedOperationException();
return length;
| public static java.nio.charset.CoderResult | malformedForLength(int length)Static factory method that returns the unique object describing a
malformed-input error of the given length.
return malformedCache.get(length);
| public void | throwException()Throws an exception appropriate to the result described by this object.
switch (type) {
case CR_UNDERFLOW: throw new BufferUnderflowException();
case CR_OVERFLOW: throw new BufferOverflowException();
case CR_MALFORMED: throw new MalformedInputException(length);
case CR_UNMAPPABLE: throw new UnmappableCharacterException(length);
default:
assert false;
}
| public java.lang.String | toString()Returns a string describing this coder result.
String nm = names[type];
return isError() ? nm + "[" + length + "]" : nm;
| public static java.nio.charset.CoderResult | unmappableForLength(int length)Static factory method that returns the unique result object describing
an unmappable-character error of the given length.
return unmappableCache.get(length);
|
|