Kryo反序列化失败,出现“KryoException:Buffer underflow” [英] Kryo Deserialization fails with "KryoException: Buffer underflow"

查看:7169
本文介绍了Kryo反序列化失败,出现“KryoException:Buffer underflow”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Kryo将对象写入字节数组。它工作正常。但是当字节数组转换为Objects时,它会抛出, com.esotericsoftware.kryo.KryoException:Buffer underflow。 exception。

I use Kryo to write Objects into byte arrays. It works fine. But when the byte arrays are converted into the Objects, it throws, com.esotericsoftware.kryo.KryoException: Buffer underflow. exception.

这是我的反序列化:

        Kryo k=new Kryo();
        Input input=new Input(byteArrayOfObject);           
        Object o=k.readObject(input,ObjectClass.class);

此外,始终无法在我的应用程序中定义对象类型。在最后的过程中,类转换发生。因此,

Furthermore, always the object type cannot be defined in my application. At the final process, the class conversion happens. Therefore,


  • 如何解决上述反序列化错误

  • How can I solve above deserialization error

有没有办法创建Object而不将类赋入
readObject(...,ClassName)?

Is there a way to create Object without giving the class into readObject(...,ClassName) ?

推荐答案

当我没有正确关闭输出/输入类型时,这发生在我身上。你需要确保Kryo冲洗除了 output.flush() output.close()

This happened to me when I was not correctly closing the Output / Input types. You need to make sure Kryo flushes everything but doing output.flush() or output.close().

其次,查看 kryo.writeClassAndObject()。然后,您可以执行 kryo.readClassAndObject()并将对象转换为它应该的类型。

Second, look into kryo.writeClassAndObject(). You can then do kryo.readClassAndObject() and cast your object to the type it is supposed to be.

这篇关于Kryo反序列化失败,出现“KryoException:Buffer underflow”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆