本文整理了Java中org.apache.kafka.common.utils.Utils.utf8Length()
方法的一些代码示例,展示了Utils.utf8Length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.utf8Length()
方法的具体详情如下:
包路径:org.apache.kafka.common.utils.Utils
类名称:Utils
方法名:utf8Length
[英]Get the length for UTF8-encoding a string without encoding it first
[中]获取UTF8编码字符串的长度,而不首先对其进行编码
代码示例来源:origin: apache/kafka
@Override
public int sizeOf(Object o) {
if (o == null)
return 2;
return 2 + Utils.utf8Length((String) o);
}
代码示例来源:origin: apache/kafka
@Override
public int sizeOf(Object o) {
return 2 + Utils.utf8Length((String) o);
}
代码示例来源:origin: apache/kafka
/**
* Get the length of the UTF8 representation of a string, without allocating
* a byte buffer for the string.
*/
public static short serializedUtf8Length(CharSequence input) {
int count = Utils.utf8Length(input);
if (count > Short.MAX_VALUE) {
throw new RuntimeException("String " + input + " is too long to serialize.");
}
return (short) count;
}
代码示例来源:origin: apache/kafka
private static int sizeOf(int keySize, int valueSize, Header[] headers) {
int size = 0;
if (keySize < 0)
size += NULL_VARINT_SIZE_BYTES;
else
size += ByteUtils.sizeOfVarint(keySize) + keySize;
if (valueSize < 0)
size += NULL_VARINT_SIZE_BYTES;
else
size += ByteUtils.sizeOfVarint(valueSize) + valueSize;
if (headers == null)
throw new IllegalArgumentException("Headers cannot be null");
size += ByteUtils.sizeOfVarint(headers.length);
for (Header header : headers) {
String headerKey = header.key();
if (headerKey == null)
throw new IllegalArgumentException("Invalid null header key found in headers");
int headerKeySize = Utils.utf8Length(headerKey);
size += ByteUtils.sizeOfVarint(headerKeySize) + headerKeySize;
byte[] headerValue = header.value();
if (headerValue == null) {
size += NULL_VARINT_SIZE_BYTES;
} else {
size += ByteUtils.sizeOfVarint(headerValue.length) + headerValue.length;
}
}
return size;
}
代码示例来源:origin: apache/kafka
@Test
public void utf8ByteArraySerde() {
String utf8String = "A\u00ea\u00f1\u00fcC";
byte[] utf8Bytes = utf8String.getBytes(StandardCharsets.UTF_8);
assertArrayEquals(utf8Bytes, Utils.utf8(utf8String));
assertEquals(utf8Bytes.length, Utils.utf8Length(utf8String));
assertEquals(utf8String, Utils.utf8(utf8Bytes));
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
@Override
public int sizeOf(Object o) {
return 2 + Utils.utf8Length((String) o);
}
内容来源于网络,如有侵权,请联系作者删除!