我正在序列化:
private byte[] serialize()
{
KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
Kryo kryo = pool.borrow();
Output output = new Output(0, 1024);
kryo.writeClassAndObject(output, readsSetNode);
byte[] bytes = output.toBytes();
output.close();
pool.release(kryo);
return bytes;
}
和反序列化:
KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
Kryo kryo = pool.borrow();
Input input = new Input(bytes);
HashMap<NodeStorage, NodeStorage> deserialized = (HashMap<NodeStorage, NodeStorage>) kryo.readClassAndObject(input);
input.close();
pool.release(kryo);
hashmap“deserialized”包含正确的对象,但不幸的是,日志被垃圾邮件带有缓冲区下溢异常:似乎只有在我尝试调试应用程序时才会发生这种情况 . 这是否会导致任何问题,或者这种行为是否正常?
com.esotericsoftware.kryo.KryoException:缓冲区下溢 . 在com.esotericsoftware.kryo.io.Input.require(Input.java:199)在com.esotericsoftware.kryo.io.Input.readVarInt(Input.java:373)在com.esotericsoftware.kryo.util.DefaultClassResolver.readClass (DefaultClassResolver.java:127)位于com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:693)的com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:804)at main.java.com.bag . server.TestServer.appExecuteUnordered(TestServer.java:78)在bftsmart.tom.server.defaultservices.DefaultRecoverable.executeUnordered(DefaultRecoverable.java:417)在bftsmart.tom.ServiceReplica.receiveReadonlyMessage(ServiceReplica.java:214)在bftsmart.tom在bftsmart.tom.core.TOMLayer.requestReceived(TOMLayer.java:290)在bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.channelRead0(NettyClientServerCommunicationSystemServerSide.java:184).core.DeliveryThread.deliverUnordered(DeliveryThread.java:289)在bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.cha nnelRead0(NettyClientServerCommunicationSystemServerSide.java:61)at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)at io.netty.channel.AbstractChannelHandlerContext .fireChannelRead(AbstractChannelHandlerContext.java:278)在io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:277)在io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:264)在IO . neto.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962)at io io.netty.channel.nio.NioEventL上的.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:131) oo.processSelectedKey(NioEventLoop.java:528)at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399)at io .netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371)维持在io.netty.util.concurrent.DefaultThreadFactory $ DefaultRunnableDecorator io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:112) . 在java.lang.Thread.run上运行(DefaultThreadFactory.java:137)(Thread.java:745)
1 回答
我遇到了同样的问题,你应该像这样修改你的序列化函数: