protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
            int b,c;
            int[] table;
            int remaining = in.remaining();

            while (remaining-- > 0) {
                if (out.remaining() < 2)
                    return CoderResult.OVERFLOW;
                c = in.get();
                table = CHAR_TO_BYTE[c >> 8];
                b =  table == null ? -1 : table[c & 0xFF];
                if (b == -1) { // maybe escapable char?
                    table = CHAR_TO_BYTE_ESCAPED[c >> 8];
                    b =  table == null ? -1 : table[c & 0xFF];
                    if (b == -1) {
                        in.position(in.position() - 1);
                        return CoderResult.unmappableForLength(1);
                    }
                    out.put(ESCAPE);
                }
                out.put((byte)(b & 0xFF));
            }
            return CoderResult.UNDERFLOW;
        }