java StreamCorruptedException: invalid type code: 77040000, what the ObjectInputStream expects?

前端 未结 2 1732
野性不改
野性不改 2021-01-29 02:15

i\'m working on a network java code, and i can\'t seem to understand what are the prerequisites an ObjectInputStream needs to interpret bytes. Here is a part of the code :

相关标签:
2条回答
  • 2021-01-29 02:28

    Your read() method is broken. It is supposed to return a single byte. You should read the javadoc for InputStream thoroughly if you intend to write your own implementation.

    0 讨论(0)
  • 2021-01-29 02:30

    Yes you are right, i was reading the ObjectInputStream$BlockDataInputStream.readBlockHeader implementation when i realized that it uses read() to get a byte. The fact read() returns an integer made me implement it to read 4 bytes... I should have read more thorougly the javadoc of InputStream.

    Thanks for your help !

    0 讨论(0)
提交回复
热议问题