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


Java Surrogate类代码示例

本文整理汇总了Java中sun.nio.cs.Surrogate的典型用法代码示例。如果您正苦于以下问题:Java Surrogate类的具体用法?Java Surrogate怎么用?Java Surrogate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: canEncode

import sun.nio.cs.Surrogate; //导入依赖的package包/类
/**
 * Returns true if the given character can be converted to the
 * target character encoding.
 */
public boolean canEncode(char ch) {
   int  index;
   int  theBytes;

   //The underneath data table returns a non-zero value for
   //some surrogates, here is the workaround.
   if (Surrogate.is(ch))
       return false;

   index = index1[((ch & mask1) >> shift)] + (ch & mask2);
   if (index < 15000)
     theBytes = (int)(index2.charAt(index));
   else
     theBytes = (int)(index2a.charAt(index-15000));

   if (theBytes != 0)
      return (true);

   // only return true if input char was unicode null - all others are
   //    undefined
   return( ch == '\u0000');
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:IBM970_OLD.java

示例2: decode

import sun.nio.cs.Surrogate; //导入依赖的package包/类
public int decode(byte[] src, int sp, int len, char[] dst) {
    int dp = 0;
    int sl = sp + len;
    char repl = replacement().charAt(0);
    while (sp < sl) {
        int b1 = src[sp++] & 0xff;
        char c = decodeSingle(b1);
        if (c == UNMAPPABLE_DECODING) {
            if (sl == sp) {
                c = repl;
            } else {
                int b2 = src[sp++] & 0xff;
                if (b2 < b2Min || b2 > b2Max) {
                    c = repl;
                } else if ((c = decodeDouble(b1, b2)) == UNMAPPABLE_DECODING) {
                    c = decodeDoubleEx(b1, b2);     //supp
                    if (c == UNMAPPABLE_DECODING) {
                        c = decodeBig5(b1, b2);     //big5
                        if (c == UNMAPPABLE_DECODING)
                            c = repl;
                    } else {
                        // supplementary character in u+2xxxx area
                        dst[dp++] = Surrogate.high(0x20000 + c);
                        dst[dp++] = Surrogate.low(0x20000 + c);
                        continue;
                    }
                }
            }
        }
        dst[dp++] = c;
    }
    return dp;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:HKSCS.java

示例3: encodeArrayLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
    char[] sa = src.array();
    int sp = src.arrayOffset() + src.position();
    int sl = src.arrayOffset() + src.limit();
    sp = (sp <= sl ? sp : sl);
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    dp = (dp <= dl ? dp : dl);

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (Surrogate.is(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());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:SingleByteEncoder.java

示例4: encodeBufferLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:SingleByteEncoder.java

示例5: encodeBufferLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
    int mark = src.position();

    try {
        while (src.hasRemaining()) {
            char c = src.get();
            if (Character.isSurrogate(c)) {
                int surr;
                if ((surr = sgp.parse(c, src)) < 0)
                    return sgp.error();
                char c2 = Surrogate.low(surr);
                byte[] outputBytes = new byte[2];
                outputBytes = encodeSurrogate(c, c2);

                if (outputBytes == null) {
                    return sgp.unmappableResult();
                } else {
                    if (dst.remaining() < 2)
                        return CoderResult.OVERFLOW;
                    mark += 2;
                    dst.put(outputBytes[0]);
                    dst.put(outputBytes[1]);
                    continue;
                }
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);
            int b = encodeSingle(c);

            if (b != -1) { // Single-byte character
                if (dst.remaining() < 1)
                    return CoderResult.OVERFLOW;
                mark++;
                dst.put((byte)b);
                continue;
            }
            // Double Byte character

            int ncode = encodeDouble(c);
            if (ncode != 0 && c != '\u0000') {
                if (dst.remaining() < 2)
                    return CoderResult.OVERFLOW;
                mark++;
                dst.put((byte) ((ncode & 0xff00) >> 8));
                dst.put((byte) ncode);
                continue;
            }
            return CoderResult.unmappableForLength(1);
        }

        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:56,代码来源:DoubleByteEncoder.java

示例6: encodeArrayLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
sp = (sp <= sl ? sp : sl);
byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
dp = (dp <= dl ? dp : dl);

try {
    while (sp < sl) {
	char c = sa[sp];
	if (Surrogate.is(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());
}
   }
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:41,代码来源:SingleByteEncoder.java

示例7: encodeBufferLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
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);
}
   }
 
开发者ID:tbepler,项目名称:LRPaGe,代码行数:32,代码来源:SingleByteEncoder.java

示例8: encode

import sun.nio.cs.Surrogate; //导入依赖的package包/类
private CoderResult encode(char[] sa, int spCurr, int sl, byte[] da, int dp, int dl) {
    lastSp = spCurr;
    int dlASCII = dp + Math.min(sl - lastSp, dl - dp);
    // handle ascii encoded strings in an optimised loop
    while (dp < dlASCII && sa[lastSp] < 128)
        da[dp++] = (byte) sa[lastSp++];

    /*
     * we are counting on the JVM array boundary checks to throw an exception rather then checking boundaries
     * ourselves... no nice, and potentially not that much of a performance enhancement.
     */
    while (lastSp < sl) {
        int c = sa[lastSp];
        if (c < 128) {
            da[dp++] = (byte) c;
        } else if (c < 2048) {
            da[dp++] = (byte) (0xC0 | (c >> 6));
            da[dp++] = (byte) (0x80 | (c & 0x3F));
        } else if (Surrogate.is(c)) {
            int uc = sgp.parse((char) c, sa, lastSp, sl);
            if (uc < 0) {
                lastDp = dp;
                return sgp.error();
            }
            da[dp++] = (byte) (0xF0 | uc >> 18);
            da[dp++] = (byte) (0x80 | uc >> 12 & 0x3F);
            da[dp++] = (byte) (0x80 | uc >> 6 & 0x3F);
            da[dp++] = (byte) (0x80 | uc & 0x3F);
            ++lastSp;
        } else {
            da[dp++] = (byte) (0xE0 | c >> 12);
            da[dp++] = (byte) (0x80 | c >> 6 & 0x3F);
            da[dp++] = (byte) (0x80 | c & 0x3F);
        }
        ++lastSp;
    }
    lastDp = dp;
    return CoderResult.UNDERFLOW;
}
 
开发者ID:nitsanw,项目名称:jmh-samples,代码行数:40,代码来源:CustomUtf8Encoder.java

示例9: sgp

import sun.nio.cs.Surrogate; //导入依赖的package包/类
Surrogate.Parser sgp() {
    if (sgp == null)
        sgp = new Surrogate.Parser();
    return sgp;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:DoubleByte.java

示例10: decodeArrayLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
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) {
            int b1 = sa[sp] & 0xff;
            char c = decodeSingle(b1);
            int inSize = 1, outSize = 1;
            char[] cc = null;
            if (c == UNMAPPABLE_DECODING) {
                if (sl - sp < 2)
                    return CoderResult.UNDERFLOW;
                int b2 = sa[sp + 1] & 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 {
                        // supplementary character in u+2xxxx area
                        outSize = 2;
                    }
                }
            }
            if (dl - dp < outSize)
                return CoderResult.OVERFLOW;
            if (outSize == 2) {
                // supplementary characters
                da[dp++] = Surrogate.high(0x20000 + c);
                da[dp++] = Surrogate.low(0x20000 + c);
            } else {
                da[dp++] = c;
            }
            sp += inSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:HKSCS.java

示例11: decodeBufferLoop

import sun.nio.cs.Surrogate; //导入依赖的package包/类
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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:43,代码来源:HKSCS.java


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