Java StreamCorruptedException

吃可爱长大的小学妹 提交于 2020-06-09 05:19:09

问题


I have a client and server application that transfer message using serialization over TCP. I got the following error when deserializing an object:

Any ideas to the cause or possible next steps in analyzing this problem?

java.io.StreamCorruptedException: invalid stream header: 383D4649
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at com.aqua.NmsApi.ResiliantTCPServer$ServerThread.run(ResiliantTCPServer.java:248)
    at java.lang.Thread.run(Unknown Source)

回答1:


There's something wrong with the magic number at the head of the serialized data. You're probably going to need to capture the serialized data and look it over yourself to start with. That ascii stream is '8=FI'.




回答2:


There are two possible reasons for that:

  • The stream has actually been corrupted (i.e. what you are reading is different from what you wrote at the other end). In that case you should write in a local file each contents (emitted and received), and compare them.

  • The magic numbers required by the implementation(s) of ObjectInputStream you are using at are different at either end, for instance because you are using different versions of the Java base packages. Those constants are declared in ObjectStreamConstants, you should check them.




回答3:


are you using exactly one ObjectInput/OutputStream per socket Input/OutputStream? recreating these on the same input/output stream is a common cause of such an error.



来源:https://stackoverflow.com/questions/706592/java-streamcorruptedexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!