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


Java Surrogate.is方法代码示例

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


在下文中一共展示了Surrogate.is方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例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:tbepler,项目名称:LRPaGe,代码行数:32,代码来源:SingleByteEncoder.java

示例5: 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

示例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();
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    int outputSize = 0;             // size of output

    try {
        while (sp < sl) {
            int index;
            int theBytes;
            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);

            index = index1[((c & mask1) >> shift)]
                            + (c & mask2);
            if (index < 15000)
                theBytes = (int)(index2.charAt(index));
            else
                theBytes = (int)(index2a.charAt(index-15000));
            b1 = (byte)((theBytes & 0x0000ff00)>>8);
            b2 = (byte)(theBytes & 0x000000ff);

            if (b1 == 0x00 && b2 == 0x00
                && c != '\u0000') {
                    return CoderResult.unmappableForLength(1);
            }

            if (b1 == 0) {
                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte) b2;
            } else {
                if (dl - dp < 2)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte) b1;
                da[dp++] = (byte) b2;
            }
            sp++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:55,代码来源:DBCS_IBM_ASCII_Encoder.java

示例7: encodeBufferLoop

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

    try {
        while (src.hasRemaining()) {
            int index;
            int theBytes;
            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);

            index = index1[((c & mask1) >> shift)]
                            + (c & mask2);
            if (index < 15000)
                theBytes = (int)(index2.charAt(index));
            else
                theBytes = (int)(index2a.charAt(index-15000));
            b1 = (byte)((theBytes & 0x0000ff00)>>8);
            b2 = (byte)(theBytes & 0x000000ff);

            if (b1 == 0x00 && b2 == 0x00
                && c != '\u0000') {
                    return CoderResult.unmappableForLength(1);
            }

            if (b1 == 0) {
                if (dst.remaining() < 1)
                    return CoderResult.OVERFLOW;
                dst.put((byte) b2);
            } else {
                if (dst.remaining() < 2)
                    return CoderResult.OVERFLOW;
                dst.put((byte) b1);
                dst.put((byte) b2);
            }
            mark++;
         }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:49,代码来源:DBCS_IBM_ASCII_Encoder.java

示例8: 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();
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();
    int outputSize = 0;             // size of output
    int spaceNeeded;

    try {
        while (sp < sl) {
            int index;
            int theBytes;
            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);


            index = index1[((c & mask1) >> shift)]
                            + (c & mask2);
            if (index < 15000)
                theBytes = (int)(index2.charAt(index));
            else
                theBytes = (int)(index2a.charAt(index-15000));
            b1= (byte)((theBytes & 0x0000ff00)>>8);
            b2 = (byte)(theBytes & 0x000000ff);

            if (b1 == 0x00 && b2 == 0x00
                && c != '\u0000') {
                    return CoderResult.unmappableForLength(1);
            }

            if (currentState == DBCS && b1 == 0x00) {
                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                currentState = SBCS;
                da[dp++] = SI;
            } else if (currentState == SBCS && b1 != 0x00) {
                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                currentState = DBCS;
                da[dp++] = SO;
            }
            if (currentState == DBCS)
                spaceNeeded = 2;
            else
                spaceNeeded = 1;
            if (dl - dp < spaceNeeded)
                return CoderResult.OVERFLOW;

            if (currentState == SBCS)
                da[dp++] = b2;
            else {
                da[dp++] = b1;
                da[dp++] = b2;
            }
            sp++;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:71,代码来源:DBCS_IBM_EBCDIC_Encoder.java

示例9: encodeBufferLoop

import sun.nio.cs.Surrogate; //导入方法依赖的package包/类
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
    int mark = src.position();
    int outputSize = 0;             // size of output
    int spaceNeeded;

    try {
        while (src.hasRemaining()) {
            int index;
            int theBytes;
            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);

            index = index1[((c & mask1) >> shift)]
                            + (c & mask2);
            if (index < 15000)
                theBytes = (int)(index2.charAt(index));
            else
                theBytes = (int)(index2a.charAt(index-15000));
            b1 = (byte)((theBytes & 0x0000ff00)>>8);
            b2 = (byte)(theBytes & 0x000000ff);

            if (b1== 0x00 && b2 == 0x00
                && c != '\u0000') {
                    return CoderResult.unmappableForLength(1);
            }

            if (currentState == DBCS && b1 == 0x00) {
                if (dst.remaining() < 1)
                    return CoderResult.OVERFLOW;
                currentState = SBCS;
                dst.put(SI);
            } else if (currentState == SBCS && b1 != 0x00) {
                if (dst.remaining() < 1)
                    return CoderResult.OVERFLOW;
                currentState = DBCS;
                dst.put(SO);
            }

            if (currentState == DBCS)
                spaceNeeded = 2;
            else
                spaceNeeded = 1;

            if (dst.remaining() < spaceNeeded)
                return CoderResult.OVERFLOW;

            if (currentState == SBCS)
                dst.put(b2);
            else {
                dst.put(b1);
                dst.put(b2);
            }
            mark++;
         }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:66,代码来源:DBCS_IBM_EBCDIC_Encoder.java

示例10: 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();
    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;
    byte [] outputByte = new byte[4];

    try {
        while (sp < sl) {
            int inputSize = 1;

            if (Surrogate.is(sa[sp])) {
                char surr = sa[sp];
                if (sgp.parse(surr, sa, sp, sl) < 0)
                    return sgp.error();
                outputSize = unicodeToEUC(sa[sp], sa[sp+1], outputByte);
                inputSize = 2;
            } else if ( sa[sp] < 0x80) {  // ASCII
                outputSize = 1;
                outputByte[0] = (byte)sa[sp];
            } else {
                outputSize = unicodeToEUC(sa[sp], '\uFFFD', outputByte);
            }
            if (outputSize == -1)
               return CoderResult.unmappableForLength(inputSize);

            if ( dl - dp < outputSize)
                return CoderResult.OVERFLOW;
            for (int i = 0; i < outputSize; i++)
                da[dp++] = outputByte[i];
            sp  += inputSize;
            }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:49,代码来源:EUC_TW_OLD.java

示例11: encodeBufferLoop

import sun.nio.cs.Surrogate; //导入方法依赖的package包/类
private CoderResult encodeBufferLoop(CharBuffer src,
                                     ByteBuffer dst)
{
    int outputSize;
    int inputSize;
    byte [] outputByte = new byte[4];
    int mark = src.position();

    try {
        while (src.hasRemaining()) {
            inputSize = 1;
            char c = src.get();

            if (Surrogate.is(c)) {
                int surr;
                if ((surr=sgp.parse(c, src)) < 0)
                    return sgp.error();
                outputSize = unicodeToEUC(c,
                                          Surrogate.low(surr),
                                          outputByte);
                inputSize = 2;
            } else if ( c < 0x80) {   // ASCII
                outputSize = 1;
                outputByte[0] = (byte)c;
            } else {
                outputSize = unicodeToEUC(c, '\uFFFD',  outputByte);
            }
            if (outputSize == -1)
               return CoderResult.unmappableForLength(inputSize);

            if (dst.remaining() < outputSize)
                return CoderResult.OVERFLOW;

            for (int i = 0; i < outputSize; i++)
                dst.put((byte)outputByte[i]);
            mark += inputSize;
        }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(mark);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:EUC_TW_OLD.java

示例12: 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)) {
                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:vicmarcal,项目名称:JAVA_UNIT,代码行数:56,代码来源:DoubleByteEncoder.java

示例13: 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();
    byte[] da = dst.array();
    int dp = dst.arrayOffset() + dst.position();
    int dl = dst.arrayOffset() + dst.limit();

    try {
        while (sp < sl) {
            char c = sa[sp];
            if (Surrogate.is(c)) {
                if (sgp.parse(c, sa, sp, sl) < 0)
                    return sgp.error();
                if (sl - sp < 2)
                    return CoderResult.UNDERFLOW;
                char c2 = sa[sp + 1];

                byte[] outputBytes = new byte[2];
                outputBytes = encodeSurrogate(c, c2);

                if (outputBytes == null) {
                    return sgp.unmappableResult();
                }
                else {
                    if (dl - dp < 2)
                        return CoderResult.OVERFLOW;
                    da[dp++] = outputBytes[0];
                    da[dp++] = outputBytes[1];
                    sp += 2;
                    continue;
                }
            }
            if (c >= '\uFFFE')
                return CoderResult.unmappableForLength(1);

            int b = encodeSingle(c);
            if (b != -1) { // Single Byte
                if (dl - dp < 1)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte)b;
                sp++;
                continue;
            }

            int ncode  = encodeDouble(c);
            if (ncode != 0 && c != '\u0000' ) {
                if (dl - dp < 2)
                    return CoderResult.OVERFLOW;
                da[dp++] = (byte) ((ncode & 0xff00) >> 8);
                da[dp++] = (byte) (ncode & 0xff);
                sp++;
                continue;
            }
            return CoderResult.unmappableForLength(1);
            }
        return CoderResult.UNDERFLOW;
    } finally {
        src.position(sp - src.arrayOffset());
        dst.position(dp - dst.arrayOffset());
    }
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:63,代码来源:DoubleByteEncoder.java


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