FileDocCategorySizeDatePackage
CoderResult.javaAPI DocAndroid 1.5 API11131Wed May 06 22:41:04 BST 2009java.nio.charset

CoderResult

public class CoderResult extends Object
Used to indicate the result of encoding/decoding. There are four types of results:
  1. UNDERFLOW indicates that all input has been processed but more input is required. It is represented by the unique object CoderResult.UNDERFLOW.
  2. OVERFLOW indicates an insufficient output buffer size. It is represented by the unique object CoderResult.OVERFLOW.
  3. 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.
  4. 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.
since
Android 1.0

Fields Summary
private static final int
TYPE_UNDERFLOW
private static final int
TYPE_OVERFLOW
private static final int
TYPE_MALFORMED_INPUT
private static final int
TYPE_UNMAPPABLE_CHAR
public static final CoderResult
UNDERFLOW
Result object indicating that there is insufficient data in the encoding/decoding buffer or that additional data is required.
public static final CoderResult
OVERFLOW
Result object used to indicate that the output buffer does not have enough space available to store the result of the encoding/decoding.
private static WeakHashMap
_malformedErrors
private static WeakHashMap
_unmappableErrors
private final int
type
private final int
length
Constructors Summary
private CoderResult(int type, int length)
Constructs a CoderResult object with its text description.

param
type the type of this result
param
length the length of the erroneous input


                                                       
         
        super();
        this.type = type;
        this.length = length;
    
Methods Summary
public booleanisError()
Returns true if this result represents a malformed-input error or an unmappable-character error.

return
true if this is a malformed-input error or an unmappable-character error, otherwise false.
since
Android 1.0

        return this.type == TYPE_MALFORMED_INPUT
                || this.type == TYPE_UNMAPPABLE_CHAR;
    
public booleanisMalformed()
Returns true if this result represents a malformed-input error.

return
true if this is a malformed-input error, otherwise false.
since
Android 1.0

        return this.type == TYPE_MALFORMED_INPUT;
    
public booleanisOverflow()
Returns true if this result is an overflow condition.

return
true if this is an overflow, otherwise false.
since
Android 1.0

        return this.type == TYPE_OVERFLOW;
    
public booleanisUnderflow()
Returns true if this result is an underflow condition.

return
true if an underflow, otherwise false.
since
Android 1.0

        return this.type == TYPE_UNDERFLOW;
    
public booleanisUnmappable()
Returns true if this result represents an unmappable-character error.

return
true if this is an unmappable-character error, otherwise false.
since
Android 1.0

        return this.type == TYPE_UNMAPPABLE_CHAR;
    
public intlength()
Gets the length of the erroneous input. The length is only meaningful to a malformed-input error or an unmappble character error.

return
the length, as an integer, of this object's erroneous input.
throws
UnsupportedOperationException if this result is an overflow or underflow.
since
Android 1.0

        if (this.type == TYPE_MALFORMED_INPUT
                || this.type == TYPE_UNMAPPABLE_CHAR) {
            return this.length;
        }
        // niochar.09=The length of the erroneous input is only meaningful to
        // a malformed-input error or an unmappble character error
        throw new UnsupportedOperationException(Messages
                .getString("niochar.09")); //$NON-NLS-1$
    
public static synchronized java.nio.charset.CoderResultmalformedForLength(int length)
Gets a CoderResult object indicating a malformed-input error.

param
length the length of the malformed-input.
return
a CoderResult object indicating a malformed-input error.
throws
IllegalArgumentException if length is non-positive.
since
Android 1.0

        if (length > 0) {
            Integer key = Integer.valueOf(length);
            synchronized (_malformedErrors) {
                CoderResult r = _malformedErrors.get(key);
                if (null == r) {
                    r = new CoderResult(TYPE_MALFORMED_INPUT, length);
                    _malformedErrors.put(key, r);
                }
                return r;
            }
        }
        // niochar.08=The length must be positive: {0}.
        throw new IllegalArgumentException(Messages.getString(
                "niochar.08", length)); //$NON-NLS-1$
    
public voidthrowException()
Throws an exception corresponding to this coder result.

throws
BufferUnderflowException in case this is an underflow.
throws
BufferOverflowException in case this is an overflow.
throws
UnmappableCharacterException in case this is an unmappable-character error.
throws
MalformedInputException in case this is a malformed-input error.
throws
CharacterCodingException the default exception.
since
Android 1.0

        switch (this.type) {
            case TYPE_UNDERFLOW:
                throw new BufferUnderflowException();
            case TYPE_OVERFLOW:
                throw new BufferOverflowException();
            case TYPE_UNMAPPABLE_CHAR:
                throw new UnmappableCharacterException(this.length);
            case TYPE_MALFORMED_INPUT:
                throw new MalformedInputException(this.length);
            default:
                throw new CharacterCodingException();
        }
    
public java.lang.StringtoString()
Returns a text description of this result.

return
a text description of this result.
since
Android 1.0

        String dsc = null;
        switch (this.type) {
            case TYPE_UNDERFLOW:
                dsc = "UNDERFLOW error"; //$NON-NLS-1$
                break;
            case TYPE_OVERFLOW:
                dsc = "OVERFLOW error"; //$NON-NLS-1$
                break;
            case TYPE_UNMAPPABLE_CHAR:
                dsc = "Unmappable-character error with erroneous input length " //$NON-NLS-1$
                        + this.length;
                break;
            case TYPE_MALFORMED_INPUT:
                dsc = "Malformed-input error with erroneous input length " //$NON-NLS-1$
                        + this.length;
                break;
            default:
                dsc = ""; //$NON-NLS-1$
                break;
        }
        return "CoderResult[" + dsc + "]"; //$NON-NLS-1$ //$NON-NLS-2$

    
public static synchronized java.nio.charset.CoderResultunmappableForLength(int length)
Gets a CoderResult object indicating an unmappable character error.

param
length the length of the input unit sequence denoting the unmappable character.
return
a CoderResult object indicating an unmappable character error.
throws
IllegalArgumentException if length is non-positive.
since
Android 1.0

        if (length > 0) {
            Integer key = Integer.valueOf(length);
            synchronized (_unmappableErrors) {
                CoderResult r = _unmappableErrors.get(key);
                if (null == r) {
                    r = new CoderResult(TYPE_UNMAPPABLE_CHAR, length);
                    _unmappableErrors.put(key, r);
                }
                return r;
            }
        }
        // niochar.08=The length must be positive: {0}.
        throw new IllegalArgumentException(Messages.getString(
                "niochar.08", length)); //$NON-NLS-1$