/**
* Emulates {@link DataOutput#writeUTF(String)} without using it method.
* @param output the target {@link DataOutput}
* @param value the target value
* @throws IOException if failed to write String into {@link DataOutput}
*/
public static void writeUTF(DataOutput output, String value) throws IOException {
int size = computeUtfBodySize(value);
if (size >>> Short.SIZE != 0) {
throw new UTFDataFormatException("too long UTF string");
}
output.writeShort(size);
for (int i = 0, n = value.length(); i < n; i++) {
char c = value.charAt(i);
if (c != CHAR_ZERO && c <= CHAR_MAX1) {
output.write(c);
} else if (c <= CHAR_MAX2) {
output.write(MASK_HEAD2 | ((c >> 6) & MASK_BODY5));
output.write(MASK_HEAD1 | (c & MASK_BODY6));
} else {
output.write(MASK_HEAD3 | ((c >> 12) & MASK_BODY4));
output.write(MASK_HEAD1 | ((c >> 6) & MASK_BODY6));
output.write(MASK_HEAD1 | (c & MASK_BODY6));
}
}
}
DataIoUtils.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:asakusafw-compiler
作者:
评论列表
文章目录