当前位置: 首页>>代码示例>>Java>>正文


Java CoderResult.malformedForLength方法代码示例

本文整理汇总了Java中java.nio.charset.CoderResult.malformedForLength方法的典型用法代码示例。如果您正苦于以下问题:Java CoderResult.malformedForLength方法的具体用法?Java CoderResult.malformedForLength怎么用?Java CoderResult.malformedForLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.charset.CoderResult的用法示例。


在下文中一共展示了CoderResult.malformedForLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeBufferLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:US_ASCII.java

示例2: parse

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
 * Parses a UCS-4 character from the given source buffer, handling
 * surrogates.
 *
 * @param  c    The first character
 * @param  in   The source buffer, from which one more character
 *              will be consumed if c is a high surrogate
 *
 * @returns  Either a parsed UCS-4 character, in which case the isPair()
 *           and increment() methods will return meaningful values, or
 *           -1, in which case error() will return a descriptive result
 *           object
 */
public int parse(char c, CharBuffer in) {
    if (Character.isHighSurrogate(c)) {
        if (!in.hasRemaining()) {
            error = CoderResult.UNDERFLOW;
            return -1;
        }
        char d = in.get();
        if (Character.isLowSurrogate(d)) {
            character = Character.toCodePoint(c, d);
            isPair = true;
            error = null;
            return character;
        }
        error = CoderResult.malformedForLength(1);
        return -1;
    }
    if (Character.isLowSurrogate(c)) {
        error = CoderResult.malformedForLength(1);
        return -1;
    }
    character = c;
    isPair = false;
    error = null;
    return character;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:Surrogate.java

示例3: lookupN

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private static CoderResult lookupN(ByteBuffer src, int n)
{
    for (int i = 1; i < n; i++) {
       if (isNotContinuation(src.get()))
           return CoderResult.malformedForLength(i);
    }
    return CoderResult.malformedForLength(n);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:UTF_8.java

示例4: malformedForLength

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private static CoderResult malformedForLength(ByteBuffer src,
                                              int sp,
                                              CharBuffer dst,
                                              int dp,
                                              int malformedNB)
{
    updatePositions(src, sp, dst, dp);
    return CoderResult.malformedForLength(malformedNB);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:CESU_8.java

示例5: generate

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
 * Generates one or two UTF-16 characters to represent the given UCS-4
 * character.
 *
 * @param  uc   The UCS-4 character
 * @param  len  The number of input bytes from which the UCS-4 value
 *              was constructed (used when creating result objects)
 * @param  da   The destination array, to which one or two UTF-16
 *              characters will be written
 * @param  dp   The destination position
 * @param  dl   The destination limit
 *
 * @returns  Either a positive count of the number of UTF-16 characters
 *           written to the destination buffer, or -1, in which case
 *           error() will return a descriptive result object
 */
public int generate(int uc, int len, char[] da, int dp, int dl) {
    if (Character.isBmpCodePoint(uc)) {
        char c = (char) uc;
        if (Character.isSurrogate(c)) {
            error = CoderResult.malformedForLength(len);
            return -1;
        }
        if (dl - dp < 1) {
            error = CoderResult.OVERFLOW;
            return -1;
        }
        da[dp] = c;
        error = null;
        return 1;
    } else if (Character.isValidCodePoint(uc)) {
        if (dl - dp < 2) {
            error = CoderResult.OVERFLOW;
            return -1;
        }
        da[dp] = Character.highSurrogate(uc);
        da[dp + 1] = Character.lowSurrogate(uc);
        error = null;
        return 2;
    } else {
        error = CoderResult.unmappableForLength(len);
        return -1;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:45,代码来源:Surrogate.java

示例6: encodeLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
    int mark = src.position();
    if (!doneBOM && src.hasRemaining()) {
        if (dst.remaining() < 4)
            return CoderResult.OVERFLOW;
        put(BOM_BIG, dst);
        doneBOM = true;
    }
    try {
        while (src.hasRemaining()) {
            char c = src.get();
            if (!Character.isSurrogate(c)) {
                if (dst.remaining() < 4)
                    return CoderResult.OVERFLOW;
                mark++;
                put(c, dst);
            } else if (Character.isHighSurrogate(c)) {
                if (!src.hasRemaining())
                    return CoderResult.UNDERFLOW;
                char low = src.get();
                if (Character.isLowSurrogate(low)) {
                    if (dst.remaining() < 4)
                        return CoderResult.OVERFLOW;
                    mark += 2;
                    put(Character.toCodePoint(c, low), dst);
                } else {
                    return CoderResult.malformedForLength(1);
                }
            } else {
                // assert Character.isLowSurrogate(c);
                return CoderResult.malformedForLength(1);
            }
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:UTF_32Coder.java

示例7: malformedForLength

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private static CoderResult malformedForLength(ByteBuffer src,
                                              int mark,
                                              int malformedNB)
{
    src.position(mark);
    return CoderResult.malformedForLength(malformedNB);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:CESU_8.java

示例8: generate

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
 * Generates one or two UTF-16 characters to represent the given UCS-4
 * character.
 *
 * @param  uc   The UCS-4 character
 * @param  len  The number of input bytes from which the UCS-4 value
 *              was constructed (used when creating result objects)
 * @param  da   The destination array, to which one or two UTF-16
 *              characters will be written
 * @param  dp   The destination position
 * @param  dl   The destination limit
 *
 * @return  Either a positive count of the number of UTF-16 characters
 *          written to the destination buffer, or -1, in which case
 *          error() will return a descriptive result object
 */
public int generate(int uc, int len, char[] da, int dp, int dl) {
    if (Character.isBmpCodePoint(uc)) {
        char c = (char) uc;
        if (Character.isSurrogate(c)) {
            error = CoderResult.malformedForLength(len);
            return -1;
        }
        if (dl - dp < 1) {
            error = CoderResult.OVERFLOW;
            return -1;
        }
        da[dp] = c;
        error = null;
        return 1;
    } else if (Character.isValidCodePoint(uc)) {
        if (dl - dp < 2) {
            error = CoderResult.OVERFLOW;
            return -1;
        }
        da[dp] = Character.highSurrogate(uc);
        da[dp + 1] = Character.lowSurrogate(uc);
        error = null;
        return 2;
    } else {
        error = CoderResult.unmappableForLength(len);
        return -1;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:Surrogate.java

示例9: decodeBufferLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            int byte1, byte2;
            int inputSize = 1;
            char outputChar = '\uFFFD';
            byte1 = src.get() & 0xff;

            if (byte1 == SS2) {
                if (src.remaining() < 3)
                    return CoderResult.UNDERFLOW;
                byte1 = src.get() & 0xff;
                inputSize = 2;
                if ( byte1 == 0xa2)
                    mappingTableG2 = mappingTableG2a2;
                else if ( byte1 == 0xac)
                    mappingTableG2 = mappingTableG2ac;
                else if ( byte1 == 0xad)
                  mappingTableG2 = mappingTableG2ad;
                else
                    return CoderResult.malformedForLength(2);
                byte1 = src.get() & 0xff;
                if ( byte1 < 0xa1 || byte1 > 0xfe)
                    return CoderResult.malformedForLength(3);
                byte2 = src.get() & 0xff;
                if ( byte2 < 0xa1 || byte2 > 0xfe)
                    return CoderResult.malformedForLength(4);
                inputSize = 4;
                outputChar = mappingTableG2.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
            } else if (byte1 == SS3 ) {
                return CoderResult.malformedForLength(1);
            } else if ( byte1 <= 0x9f ) {                // valid single byte
                outputChar = byteToCharTable.charAt(byte1);
            } else if (byte1 < 0xa1 || byte1 > 0xfe) {   // invalid range?
                return CoderResult.malformedForLength(1);
            } else {                                     // G1
                if (src.remaining() < 1)
                    return CoderResult.UNDERFLOW;
                byte2 = src.get() & 0xff;
                if ( byte2 < 0xa1 || byte2 > 0xfe) {
                    return CoderResult.malformedForLength(2);
                }
                inputSize = 2;
                outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
            }

            if (outputChar == '\uFFFD')
                return CoderResult.unmappableForLength(inputSize);
            if (!dst.hasRemaining())
                return CoderResult.OVERFLOW;
            dst.put(outputChar);
            mark += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
            src.position(mark);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:IBM964.java

示例10: crMalformedOrUnderFlow

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
protected CoderResult crMalformedOrUnderFlow(int b) {
    if (b == SS2 || b == SS3 )
        return CoderResult.malformedForLength(1);
    return CoderResult.UNDERFLOW;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:DoubleByte.java

示例11: implFlush

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
protected CoderResult implFlush(ByteBuffer out) {
return CoderResult.malformedForLength(1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:SerialWriterStringEncoderTest2.java

示例12: decodeNotHasArray

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private CoderResult decodeNotHasArray(ByteBuffer in, CharBuffer out) {
    int outRemaining = out.remaining();
    int pos = in.position();
    int limit = in.limit();
    try {
        while (pos < limit) {
            if (outRemaining == 0) {
                return CoderResult.OVERFLOW;
            }
            int jchar = in.get();
            if (jchar < 0) {
                jchar = jchar & 0x7F;
                int tail = remainingBytes[jchar];
                if (tail == -1) {
                    return CoderResult.malformedForLength(1);
                }
                if (limit - pos < 1 + tail) {
                    // No early test for invalid sequences here as peeking
                    // at the next byte is harder
                    return CoderResult.UNDERFLOW;
                }
                int nextByte;
                for (int i = 0; i < tail; i++) {
                    nextByte = in.get() & 0xFF;
                    if ((nextByte & 0xC0) != 0x80) {
                        return CoderResult.malformedForLength(1 + i);
                    }
                    jchar = (jchar << 6) + nextByte;
                }
                jchar -= remainingNumbers[tail];
                if (jchar < lowerEncodingLimit[tail]) {
                    // Should have been encoded in a fewer octets
                    return CoderResult.malformedForLength(1);
                }
                pos += tail;
            }
            // Apache Tomcat added test
            if (jchar >= 0xD800 && jchar <= 0xDFFF) {
                return CoderResult.unmappableForLength(3);
            }
            // Apache Tomcat added test
            if (jchar > 0x10FFFF) {
                return CoderResult.unmappableForLength(4);
            }
            if (jchar <= 0xffff) {
                out.put((char) jchar);
                outRemaining--;
            } else {
                if (outRemaining < 2) {
                    return CoderResult.OVERFLOW;
                }
                out.put((char) ((jchar >> 0xA) + 0xD7C0));
                out.put((char) ((jchar & 0x3FF) + 0xDC00));
                outRemaining -= 2;
            }
            pos++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        in.position(pos);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:63,代码来源:Utf8Decoder.java

示例13: decodeArrayLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
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());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:79,代码来源:DBCS_IBM_EBCDIC_Decoder.java

示例14: decodeBufferLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
    int mark = src.position();
    try {
        while (src.hasRemaining()) {
            int byte1, byte2;
            int inputSize = 1;
            char outputChar = '\uFFFD';
            byte1 = src.get() & 0xff;

            if (byte1 == SS2) {
                if (!src.hasRemaining())
                    return CoderResult.UNDERFLOW;
                byte1 = src.get() & 0xff;
                inputSize = 2;
                if ( byte1 < 0xa1 || byte1 > 0xfe) {   //valid first byte for G2
                    return CoderResult.malformedForLength(2);
                }
                outputChar = mappingTableG2.charAt(byte1 - 0xa1);
            } else if (byte1 == SS3 ) {                 //G3
                if (src.remaining() < 2)
                    return CoderResult.UNDERFLOW;

                byte1 = src.get() & 0xff;
                if ( byte1 < 0xa1 || byte1 > 0xfe) {
                    return CoderResult.malformedForLength(2);
                }
                byte2 = src.get() & 0xff;
                if ( byte2 < 0xa1 || byte2 > 0xfe) {
                    return CoderResult.malformedForLength(3);
                }
                inputSize = 3;
                outputChar = mappingTableG3.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
            } else if ( byte1 <= 0x9f ) {                // valid single byte
                outputChar = byteToCharTable.charAt(byte1);
            } else if (byte1 < 0xa1 || byte1 > 0xfe) {   // invalid range?
                return CoderResult.malformedForLength(1);
            } else {                                     // G1
                if (src.remaining() < 1)
                    return CoderResult.UNDERFLOW;
                byte2 = src.get() & 0xff;
                if ( byte2 < 0xa1 || byte2 > 0xfe) {
                    return CoderResult.malformedForLength(2);
                }
                inputSize = 2;
                outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
            }

            if (outputChar == '\uFFFD')
                return CoderResult.unmappableForLength(inputSize);
            if (!dst.hasRemaining())
                return CoderResult.OVERFLOW;
            dst.put(outputChar);
            mark += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
            src.position(mark);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:60,代码来源:IBM33722.java

示例15: decodeLoop

import java.nio.charset.CoderResult; //导入方法依赖的package包/类
protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
    if (src.remaining() < 4)
        return CoderResult.UNDERFLOW;
    int mark = src.position();
    int cp;
    try {
        if (currentBO == NONE) {
            cp = ((src.get() & 0xff) << 24) |
                 ((src.get() & 0xff) << 16) |
                 ((src.get() & 0xff) <<  8) |
                 (src.get() & 0xff);
            if (cp == BOM_BIG && expectedBO != LITTLE) {
                currentBO = BIG;
                mark += 4;
            } else if (cp == BOM_LITTLE && expectedBO != BIG) {
                currentBO = LITTLE;
                mark += 4;
            } else {
                if (expectedBO == NONE)
                    currentBO = BIG;
                else
                    currentBO = expectedBO;
                src.position(mark);
            }
        }
        while (src.remaining() >= 4) {
            cp = getCP(src);
            if (Character.isBmpCodePoint(cp)) {
                if (!dst.hasRemaining())
                    return CoderResult.OVERFLOW;
                mark += 4;
                dst.put((char) cp);
            } else if (Character.isValidCodePoint(cp)) {
                if (dst.remaining() < 2)
                    return CoderResult.OVERFLOW;
                mark += 4;
                dst.put(Character.highSurrogate(cp));
                dst.put(Character.lowSurrogate(cp));
            } else {
                return CoderResult.malformedForLength(4);
            }
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:48,代码来源:UTF_32Coder.java


注:本文中的java.nio.charset.CoderResult.malformedForLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。