本文整理汇总了Java中com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar.isHighSurrogate方法的典型用法代码示例。如果您正苦于以下问题:Java XMLChar.isHighSurrogate方法的具体用法?Java XMLChar.isHighSurrogate怎么用?Java XMLChar.isHighSurrogate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar
的用法示例。
在下文中一共展示了XMLChar.isHighSurrogate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeUTF8String
import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Encode a string using the UTF-8 encoding.
*
* @param ch the array of characters.
* @param offset the offset into the array of characters.
* @param length the length of characters.
*/
protected final int encodeUTF8String(char[] ch, int offset, int length) throws IOException {
int bpos = 0;
// Make sure buffer is large enough
ensureEncodingBufferSizeForUtf8String(length);
final int end = offset + length;
int c;
while (end != offset) {
c = ch[offset++];
if (c < 0x80) {
// 1 byte, 7 bits
_encodingBuffer[bpos++] = (byte) c;
} else if (c < 0x800) {
// 2 bytes, 11 bits
_encodingBuffer[bpos++] =
(byte) (0xC0 | (c >> 6)); // first 5
_encodingBuffer[bpos++] =
(byte) (0x80 | (c & 0x3F)); // second 6
} else if (c <= '\uFFFF') {
if (!XMLChar.isHighSurrogate(c) && !XMLChar.isLowSurrogate(c)) {
// 3 bytes, 16 bits
_encodingBuffer[bpos++] =
(byte) (0xE0 | (c >> 12)); // first 4
_encodingBuffer[bpos++] =
(byte) (0x80 | ((c >> 6) & 0x3F)); // second 6
_encodingBuffer[bpos++] =
(byte) (0x80 | (c & 0x3F)); // third 6
} else {
// 4 bytes, high and low surrogate
encodeCharacterAsUtf8FourByte(c, ch, offset, end, bpos);
bpos += 4;
offset++;
}
}
}
return bpos;
}