问题
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