Example usage for java.nio.charset CoderResult isUnmappable

List of usage examples for java.nio.charset CoderResult isUnmappable

Introduction

In this page you can find the example usage for java.nio.charset CoderResult isUnmappable.

Prototype

public boolean isUnmappable() 

Source Link

Document

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

Usage

From source file:org.openbel.framework.ws.utils.Converter.java

private static Byte encode(final CharsetEncoder encoder, final char c) {
    encoder.reset();//from  w w w .j a  va 2s.com
    if (!encoder.canEncode(c)) {
        return null;
    }
    encoder.reset();
    ByteBuffer buffer = ByteBuffer.allocate(1);
    CharBuffer charBuffer = CharBuffer.allocate(1).put(c);
    charBuffer.flip();
    CoderResult result = null;

    result = encoder.encode(charBuffer, buffer, false);
    if (!result.isUnderflow()) {
        return null;
    }
    result = encoder.encode(charBuffer, buffer, true);
    if (result.isMalformed() || result.isUnmappable()) {
        return null;
    }
    result = encoder.flush(buffer);
    if (!result.isUnderflow()) {
        return null;
    }
    buffer.flip();
    return buffer.get(0);
}