java.nio.charset.CoderResult# UNDERFLOW 源码实例Demo

下面列出了java.nio.charset.CoderResult# UNDERFLOW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: SingleByte.java

private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            char c = decode(src.get());
            if (c == UNMAPPABLE_DECODING)
                return CoderResult.unmappableForLength(1);
            if (!dst.hasRemaining())
                return CoderResult.OVERFLOW;
            dst.put(c);
            mark++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码2 项目: TencentKona-8   文件: US_ASCII.java

private CoderResult decodeBufferLoop(ByteBuffer src,
                                     CharBuffer dst)
{
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            byte b = src.get();
            if (b >= 0) {
                if (!dst.hasRemaining())
                    return CoderResult.OVERFLOW;
                dst.put((char)b);
                mark++;
                continue;
            }
            return CoderResult.malformedForLength(1);
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码3 项目: jdk8u-dev-jdk   文件: US_ASCII.java

private CoderResult encodeBufferLoop(CharBuffer src,
                                     ByteBuffer dst)
{
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            char c = src.get();
            if (c < 0x80) {
                if (!dst.hasRemaining())
                    return CoderResult.OVERFLOW;
                dst.put((byte)c);
                mark++;
                continue;
            }
            if (sgp.parse(c, src) < 0)
                return sgp.error();
            return sgp.unmappableResult();
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码4 项目: openjdk-8   文件: SJIS_0213.java

protected CoderResult implFlush(ByteBuffer dst) {
    if (leftoverBase > 0) {
        if (dst.remaining() < 2)
            return CoderResult.OVERFLOW;
        int db = encodeChar(leftoverBase);
        dst.put((byte)(db >> 8));
        dst.put((byte)(db));
        leftoverBase = 0;
    }
    return CoderResult.UNDERFLOW;
}
 
源代码5 项目: uavstack   文件: UTF8Decoder.java

public static CoderResult malformedN(ByteBuffer src, int nb) {
    switch (nb) {
        case 1:
            int b1 = src.get();
            if ((b1 >> 2) == -2) {
                // 5 bytes 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                if (src.remaining() < 4) return CoderResult.UNDERFLOW;
                return lookupN(src, 5);
            }
            if ((b1 >> 1) == -2) {
                // 6 bytes 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
                if (src.remaining() < 5) {
                    return CoderResult.UNDERFLOW;
                }
                return lookupN(src, 6);
            }
            return CoderResult.malformedForLength(1);
        case 2: // always 1
            return CoderResult.malformedForLength(1);
        case 3:
            b1 = src.get();
            int b2 = src.get(); // no need to lookup b3
            return CoderResult.malformedForLength(((b1 == (byte) 0xe0 && (b2 & 0xe0) == 0x80) || isNotContinuation(b2)) ? 1 : 2);
        case 4: // we don't care the speed here
            b1 = src.get() & 0xff;
            b2 = src.get() & 0xff;
            if (b1 > 0xf4 || (b1 == 0xf0 && (b2 < 0x90 || b2 > 0xbf)) || (b1 == 0xf4 && (b2 & 0xf0) != 0x80) || isNotContinuation(b2)) return CoderResult.malformedForLength(1);
            if (isNotContinuation(src.get())) return CoderResult.malformedForLength(2);
            return CoderResult.malformedForLength(3);
        default:
            throw new IllegalStateException();
    }
}
 
源代码6 项目: TencentKona-8   文件: DoubleByte.java

protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();

    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();

    try {
        while (sp < sl && dp < dl) {
            // inline the decodeSingle/Double() for better performance
            int inSize = 1;
            int b1 = sa[sp] & 0xff;
            char c = b2cSB[b1];
            if (c == UNMAPPABLE_DECODING) {
                if (sl - sp < 2)
                    return crMalformedOrUnderFlow(b1);
                int b2 = sa[sp + 1] & 0xff;
                if (b2 < b2Min || b2 > b2Max ||
                    (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
                    return crMalformedOrUnmappable(b1, b2);
                }
                inSize++;
            }
            da[dp++] = c;
            sp += inSize;
        }
        return (sp >= sl) ? CoderResult.UNDERFLOW
                          : CoderResult.OVERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
源代码7 项目: jdk8u_jdk   文件: US_ASCII.java

private CoderResult encodeArrayLoop(CharBuffer src,
                                    ByteBuffer dst)
{
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (c < 0x80) {
                if (dp >= dl)
                    return CoderResult.OVERFLOW;
                da[dp] = (byte)c;
                sp++; dp++;
                continue;
            }
            if (sgp.parse(c, sa, sp, sl) < 0)
                return sgp.error();
            return sgp.unmappableResult();
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
源代码8 项目: openjdk-8   文件: SingleByteEncoder.java

private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            char c = src.get();
            if (Surrogate.is(c)) {
                if (sgp.parse(c, src) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);
            if (!dst.hasRemaining())
                return CoderResult.OVERFLOW;

            char e = index2.charAt(index1[(c & mask1) >> shift]
                                   + (c & mask2));

            // If output byte is zero because input char is zero
            // then character is mappable, o.w. fail
            if (e == '\u0000' && c != '\u0000')
                return CoderResult.unmappableForLength(1);

            mark++;
            dst.put((byte)e);
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 

private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            int b1, b2;
            b1 = sa[sp];
            int inputSize = 1;
            int v = 0;
            char outputChar = REPLACE_CHAR;
            if (b1 < 0)
                b1 += 256;

            if (!leadByte[b1])
            {
              outputChar = singleByteToChar.charAt(b1);
            } else {
                if (sl - sp < 2)
                    return CoderResult.UNDERFLOW;
                b2 = sa[sp + 1];
                if (b2 < 0)
                    b2 += 256;

                inputSize++;

                // Lookup in the two level index
                v = b1 * 256 + b2;
                outputChar = index2.charAt(index1[((v & mask1) >> shift)]
                                            + (v & mask2));
            }
            if (outputChar == '\uFFFD')
                return CoderResult.unmappableForLength(inputSize);

            if (dl - dp < 1)
                return CoderResult.OVERFLOW;
            da[dp++] = outputChar;
            sp += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: UTF_8.java

private CoderResult encodeBufferLoop(CharBuffer src,
                                     ByteBuffer dst)
{
    int mark = src.position();
    while (src.hasRemaining()) {
        char c = src.get();
        if (c < 0x80) {
            // Have at most seven bits
            if (!dst.hasRemaining())
                return overflow(src, mark);
            dst.put((byte)c);
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            if (dst.remaining() < 2)
                return overflow(src, mark);
            dst.put((byte)(0xc0 | (c >> 6)));
            dst.put((byte)(0x80 | (c & 0x3f)));
        } else if (Character.isSurrogate(c)) {
            // Have a surrogate pair
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, src);
            if (uc < 0) {
                src.position(mark);
                return sgp.error();
            }
            if (dst.remaining() < 4)
                return overflow(src, mark);
            dst.put((byte)(0xf0 | ((uc >> 18))));
            dst.put((byte)(0x80 | ((uc >> 12) & 0x3f)));
            dst.put((byte)(0x80 | ((uc >>  6) & 0x3f)));
            dst.put((byte)(0x80 | (uc & 0x3f)));
            mark++;  // 2 chars
        } else {
            // 3 bytes, 16 bits
            if (dst.remaining() < 3)
                return overflow(src, mark);
            dst.put((byte)(0xe0 | ((c >> 12))));
            dst.put((byte)(0x80 | ((c >>  6) & 0x3f)));
            dst.put((byte)(0x80 | (c & 0x3f)));
        }
        mark++;
    }
    src.position(mark);
    return CoderResult.UNDERFLOW;
}
 
源代码11 项目: jdk8u-jdk   文件: EUC_JP_OLD.java

private CoderResult encodeArrayLoop(CharBuffer src,
                                    ByteBuffer dst)
{
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    int outputSize = 0;
    byte[]  outputByte;
    int     inputSize = 0;                 // Size of input
    byte[]  tmpBuf = new byte[3];

    try {
        while (sp < sl) {
            outputByte = tmpBuf;
            char c = sa[sp];

            if (Character.isSurrogate(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }

            outputSize = encodeSingle(c, outputByte);

            if (outputSize == 0) { // DoubleByte
                int ncode = encodeDouble(c);
                if (ncode != 0 ) {
                    if ((ncode & 0xFF0000) == 0) {
                        outputByte[0] = (byte) ((ncode & 0xff00) >> 8);
                        outputByte[1] = (byte) (ncode & 0xff);
                        outputSize = 2;
                    } else {
                        outputByte[0] = (byte) 0x8f;
                        outputByte[1] = (byte) ((ncode & 0xff00) >> 8);
                        outputByte[2] = (byte) (ncode & 0xff);
                        outputSize = 3;
                    }
                } else {
                        return CoderResult.unmappableForLength(1);
                }
            }
            if (dl - dp < outputSize)
                return CoderResult.OVERFLOW;
            // Put the byte in the output buffer
            for (int i = 0; i < outputSize; i++) {
                da[dp++] = outputByte[i];
            }
            sp++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
源代码12 项目: jdk8u_jdk   文件: ISO2022.java

private CoderResult encodeArrayLoop(CharBuffer src,
                                    ByteBuffer dst)
{
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    int outputSize = 0;
    byte[]  outputByte = new byte[8];
    newshiftout = shiftout;
    newSODesDefined = SODesDefined;
    newSS2DesDefined = SS2DesDefined;
    newSS3DesDefined = SS3DesDefined;

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (Character.isSurrogate(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }

            if (c < 0x80) {     // ASCII
                if (shiftout){
                    newshiftout = false;
                    outputSize = 2;
                    outputByte[0] = ISO_SI;
                    outputByte[1] = (byte)(c & 0x7f);
                } else {
                    outputSize = 1;
                    outputByte[0] = (byte)(c & 0x7f);
                }
                if(sa[sp] == '\n'){
                    newSODesDefined = false;
                    newSS2DesDefined = false;
                    newSS3DesDefined = false;
                }
            } else {
                outputSize = unicodeToNative(c, outputByte);
                if (outputSize == 0) {
                    return CoderResult.unmappableForLength(1);
                }
            }
            if (dl - dp < outputSize)
                return CoderResult.OVERFLOW;

            for (int i = 0; i < outputSize; i++)
                da[dp++] = outputByte[i];
            sp++;
            shiftout = newshiftout;
            SODesDefined = newSODesDefined;
            SS2DesDefined = newSS2DesDefined;
            SS3DesDefined = newSS3DesDefined;
        }
        return CoderResult.UNDERFLOW;
     } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
     }
}
 
源代码13 项目: jdk8u60   文件: DBCS_IBM_ASCII_Decoder.java

private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
    int mark = src.position();


    try {
        while (src.hasRemaining()) {
            char outputChar = REPLACE_CHAR;
            int inputSize = 1;
            int b1, b2;
            int v = 0;
            b1 = src.get();
            if (b1 < 0)
                b1 += 256;

            if (!leadByte[b1])
            {
              outputChar = singleByteToChar.charAt(b1);
            } else {
                if (src.remaining() < 1)
                    return CoderResult.UNDERFLOW;
                b2 = src.get();
                if (b2 < 0)
                    b2 += 256;
                inputSize++;

                // Lookup in the two level index
                v = b1 * 256 + b2;
                outputChar = index2.charAt(index1[((v & mask1) >> shift)]
                                                    + (v & mask2));
            }
            if (outputChar == REPLACE_CHAR)
                return CoderResult.unmappableForLength(inputSize);

            if (!dst.hasRemaining())
                return CoderResult.OVERFLOW;
            mark += inputSize;
            dst.put(outputChar);
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: EUC_JP.java

private CoderResult decodeArrayLoop(ByteBuffer src,
                                    CharBuffer dst)
{
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);

    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    int b1 = 0, b2 = 0;
    int inputSize = 0;
    char outputChar = UNMAPPABLE_DECODING;
    try {
        while (sp < sl) {
            b1 = sa[sp] & 0xff;
            inputSize = 1;

            if ((b1 & 0x80) == 0) {
                outputChar = (char)b1;
            } else {                        // Multibyte char
                if (b1 == 0x8f) {           // JIS0212
                    if (sp + 3 > sl)
                       return CoderResult.UNDERFLOW;
                    b1 = sa[sp + 1] & 0xff;
                    b2 = sa[sp + 2] & 0xff;
                    inputSize += 2;
                    if (dec0212 == null)    // JIS02012 not supported
                        return CoderResult.unmappableForLength(inputSize);
                    outputChar = dec0212.decodeDouble(b1-0x80, b2-0x80);
                } else {                     // JIS0201, JIS0208
                    if (sp + 2 > sl)
                       return CoderResult.UNDERFLOW;
                    b2 = sa[sp + 1] & 0xff;
                    inputSize++;
                    outputChar = decodeDouble(b1, b2);
                }
            }
            if (outputChar == UNMAPPABLE_DECODING) { // can't be decoded
                return CoderResult.unmappableForLength(inputSize);
            }
            if (dp + 1 > dl)
                return CoderResult.OVERFLOW;
            da[dp++] = outputChar;
            sp += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
源代码15 项目: openjdk-8-source   文件: ISCII91.java

private CoderResult encodeBufferLoop(CharBuffer src,
                                     ByteBuffer dst)
{
    int mark = src.position();

    try {
        char inputChar;
        while (src.hasRemaining()) {
            int index = Integer.MIN_VALUE;
            inputChar = src.get();

            if (inputChar >= 0x0000 && inputChar <= 0x007f) {
                if (dst.remaining() < 1)
                    return CoderResult.OVERFLOW;
                dst.put((byte) inputChar);
                mark++;
                continue;
            }

            // if inputChar == ZWJ replace it with halant
            // if inputChar == ZWNJ replace it with Nukta

            if (inputChar == 0x200c) {
                inputChar = HALANT_CHAR;
            }
            else if (inputChar == 0x200d) {
                inputChar = NUKTA_CHAR;
            }

            if (inputChar >= 0x0900 && inputChar <= 0x097f) {
                index = ((int)(inputChar) - 0x0900)*2;
            }

            if (Character.isSurrogate(inputChar)) {
                if (sgp.parse(inputChar, src) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }

            if (index == Integer.MIN_VALUE ||
                encoderMappingTable[index] == NO_CHAR) {
                return CoderResult.unmappableForLength(1);
            } else {
                if(encoderMappingTable[index + 1] == NO_CHAR) {
                    if(dst.remaining() < 1)
                        return CoderResult.OVERFLOW;
                    dst.put(encoderMappingTable[index]);
                } else {
                    if(dst.remaining() < 2)
                        return CoderResult.OVERFLOW;
                    dst.put(encoderMappingTable[index]);
                    dst.put(encoderMappingTable[index + 1]);
                }
            }
            mark++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码16 项目: hottub   文件: EUC_TW.java

private CoderResult encodeBufferLoop(CharBuffer src,
                                     ByteBuffer dst)
{
    int outSize;
    int inSize;
    int mark = src.position();

    try {
        while (src.hasRemaining()) {
            inSize = 1;
            char c = src.get();
            if (c < 0x80) {   // ASCII
                outSize = 1;
                bb[0] = (byte)c;
            } else {
                outSize = toEUC(c, bb);
                if (outSize == -1) {
                    if (Character.isHighSurrogate(c)) {
                        if (!src.hasRemaining())
                            return CoderResult.UNDERFLOW;
                        char c2 = src.get();
                        if (!Character.isLowSurrogate(c2))
                            return CoderResult.malformedForLength(1);
                        outSize = toEUC(c, c2, bb);
                        inSize = 2;
                    } else if (Character.isLowSurrogate(c)) {
                        return CoderResult.malformedForLength(1);
                    }
                }
            }
            if (outSize == -1)
                return CoderResult.unmappableForLength(inSize);
            if (dst.remaining() < outSize)
                return CoderResult.OVERFLOW;
            for (int i = 0; i < outSize; i++)
                dst.put(bb[i]);
            mark += inSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码17 项目: jdk8u_jdk   文件: DoubleByte.java

protected CoderResult crMalformedOrUnderFlow(int b) {
    return CoderResult.UNDERFLOW;
}
 
源代码18 项目: openjdk-8-source   文件: HKSCS.java

protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            char[] cc = null;
            int b1 = src.get() & 0xff;
            int inSize = 1, outSize = 1;
            char c = decodeSingle(b1);
            if (c == UNMAPPABLE_DECODING) {
                if (src.remaining() < 1)
                    return CoderResult.UNDERFLOW;
                int b2 = src.get() & 0xff;
                inSize++;
                if (b2 < b2Min || b2 > b2Max)
                    return CoderResult.unmappableForLength(2);
                c = decodeDouble(b1, b2);           //bmp
                if (c == UNMAPPABLE_DECODING) {
                    c = decodeDoubleEx(b1, b2);     //supp
                    if (c == UNMAPPABLE_DECODING) {
                        c = decodeBig5(b1, b2);     //big5
                        if (c == UNMAPPABLE_DECODING)
                            return CoderResult.unmappableForLength(2);
                    } else {
                        outSize = 2;
                    }
                }
            }
            if (dst.remaining() < outSize)
                return CoderResult.OVERFLOW;
            if (outSize == 2) {
                dst.put(Surrogate.high(0x20000 + c));
                dst.put(Surrogate.low(0x20000 + c));
            } else {
                dst.put(c);
            }
            mark += inSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
源代码19 项目: openjdk-jdk8u   文件: SingleByteEncoder.java

private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (Character.isSurrogate(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                return sgp.unmappableResult();
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);
            if (dl - dp < 1)
                return CoderResult.OVERFLOW;

            char e = index2.charAt(index1[(c & mask1) >> shift]
                                   + (c & mask2));

            // If output byte is zero because input char is zero
            // then character is mappable, o.w. fail
            if (e == '\u0000' && c != '\u0000')
                return CoderResult.unmappableForLength(1);

            sp++;
            da[dp++] = (byte)e;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 

private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
    byte[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    assert (sp <= sl);
    sp = (sp <= sl ? sp : sl);
    char[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    assert (dp <= dl);
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            int b1, b2;
            b1 = sa[sp];
            int inputSize = 1;
            int v = 0;
            char outputChar = REPLACE_CHAR;

            if (b1 < 0)
                b1 += 256;

            if (b1 == SO) {  // Shift out
                // For SO characters - simply validate the state and if OK
                //    update the state and go to the next byte

                if (currentState != SBCS)
                    return CoderResult.malformedForLength(1);
                else
                    currentState = DBCS;
            } else if (b1 == SI) {
                // For SI characters - simply validate the state and if OK
                //    update the state and go to the next byte

                if (currentState != DBCS) {
                    return CoderResult.malformedForLength(1);
                } else {
                    currentState = SBCS;
                }
            } else {
                if (currentState == SBCS) {
                    outputChar = singleByteToChar.charAt(b1);
                } else {
                if (sl - sp < 2)
                    return CoderResult.UNDERFLOW;
                b2 = sa[sp + 1];
                if (b2 < 0)
                    b2 += 256;

                inputSize++;

                // Check validity of dbcs ebcdic byte pair values
                if ((b1 != 0x40 || b2 != 0x40) &&
                  (b2 < 0x41 || b2 > 0xfe)) {
                  return CoderResult.malformedForLength(2);
                }

                // Lookup in the two level index
                v = b1 * 256 + b2;
                outputChar = index2.charAt(index1[((v & mask1) >> shift)]
                                            + (v & mask2));
                }
                if (outputChar == '\uFFFD')
                    return CoderResult.unmappableForLength(inputSize);

                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                da[dp++] = outputChar;
            }
            sp += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}