Java 类com.esotericsoftware.kryo.io.KryoObjectOutput 实例源码

项目:jnetrobust    文件:ProtocolHost.java   
public ProtocolHost(String hostName, Class<T> dataClass, SocketAddress localAddress) throws IOException {
    // setup network communication
    channel = DatagramChannel.open();
    channel.configureBlocking(false);
    channel.socket().bind(localAddress);

    // setup serialization
    kryo = new Kryo();
    kryo.register(Packet.class); // add argument `new ExternalizableSerializer()` if needed
    kryo.register(Metadata.class); // add argument `new ExternalizableSerializer()` if needed
    kryo.register(dataClass);
    objectInput = new KryoObjectInput(kryo, bufferInput);
    objectOutput = new KryoObjectOutput(kryo, bufferOutput);

    this.hostName = hostName;
}
项目:rpc    文件:KryoSerialization.java   
@Override
public byte[] serialize(Object data) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Kryo kryo = kryoThreadMap.get();
    KryoObjectOutput out = new KryoObjectOutput(kryo, new FastOutput(bos));
    out.writeObject(data);
    out.flush();
    return bos.toByteArray();
}