/**
* Used when we know the max size will fit in the current buffer.
*/
private final void writeQuickFullUTF(String str, int strlen) throws IOException {
int utfSizeIdx = this.buffer.position();
// skip bytes reserved for length
this.buffer.position(utfSizeIdx + 2);
for (int i = 0; i < strlen; i++) {
int c = str.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
this.buffer.put((byte) c);
} else if (c > 0x07FF) {
this.buffer.put((byte) (0xE0 | ((c >> 12) & 0x0F)));
this.buffer.put((byte) (0x80 | ((c >> 6) & 0x3F)));
this.buffer.put((byte) (0x80 | ((c >> 0) & 0x3F)));
} else {
this.buffer.put((byte) (0xC0 | ((c >> 6) & 0x1F)));
this.buffer.put((byte) (0x80 | ((c >> 0) & 0x3F)));
}
}
int utflen = this.buffer.position() - (utfSizeIdx + 2);
if (utflen > 65535) {
// act as if we wrote nothing to this buffer
this.buffer.position(utfSizeIdx);
throw new UTFDataFormatException();
}
this.buffer.putShort(utfSizeIdx, (short) utflen);
}
MsgStreamer.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:monarch
作者:
评论列表
文章目录