本文整理汇总了Java中org.msgpack.core.MessagePacker.close方法的典型用法代码示例。如果您正苦于以下问题:Java MessagePacker.close方法的具体用法?Java MessagePacker.close怎么用?Java MessagePacker.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.msgpack.core.MessagePacker
的用法示例。
在下文中一共展示了MessagePacker.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.msgpack.core.MessagePacker; //导入方法依赖的package包/类
void write(MessagePacker packer) throws IOException {
Visitor visitor = new Visitor(packer);
packer.packArrayHeader(3);
packer.packString(this.type);
if (this.data != null) {
packer.packMapHeader(this.data.size());
for (Map.Entry<String, Object> entry : this.data.entrySet()) {
packer.packString(entry.getKey());
visitor.visit(entry.getValue());
}
} else {
packer.packNil();
}
packer.packString(this.nodeId);
packer.close();
}
示例2: fromUniformObject
import org.msgpack.core.MessagePacker; //导入方法依赖的package包/类
@Override
public Object fromUniformObject(JUniformObject object) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
MessagePacker packer = _msgpack.newPacker(out);
try {
this._writeJUniformObjectToPacker(object, packer);
packer.close();
} catch (IOException ex) {
return null;
}
return out.toByteArray();
}
示例3: close
import org.msgpack.core.MessagePacker; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
try {
flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
MessagePacker messagePacker = getMessagePacker();
messagePacker.close();
}
}
示例4: write
import org.msgpack.core.MessagePacker; //导入方法依赖的package包/类
@Override
public void write(KeyValue keyValue) throws IOException {
byte[] kafkaKey = keyValue.hasKafkaKey() ? keyValue.getKafkaKey() : new byte[0];
long timestamp = keyValue.getTimestamp();
final int timestampLength = (keyValue.hasTimestamp()) ? 10 : 0;
// output size estimate
// 1 - map header
// 1 - message pack key
// 9 - max kafka offset
// 1 - message pack key
// 9 - kafka timestamp
// 1 - message pack key
// 5 - max (sane) kafka key size
// N - size of kafka key
// = 27 + N
ByteArrayOutputStream out = new ByteArrayOutputStream(17 + timestampLength + kafkaKey.length);
MessagePacker packer = MessagePack.newDefaultPacker(out)
.packMapHeader(numberOfFieldsMappedInHeader(keyValue))
.packInt(KAFKA_MESSAGE_OFFSET)
.packLong(keyValue.getOffset());
if (keyValue.hasTimestamp())
packer.packInt(KAFKA_MESSAGE_TIMESTAMP)
.packLong(timestamp);
if (keyValue.hasKafkaKey())
packer.packInt(KAFKA_HASH_KEY)
.packBinaryHeader(kafkaKey.length)
.writePayload(kafkaKey);
packer.close();
byte[] outBytes = out.toByteArray();
this.mKey.set(outBytes, 0, outBytes.length);
this.mValue.set(keyValue.getValue(), 0, keyValue.getValue().length);
this.mWriter.append(this.mKey, this.mValue);
}