Question

I was wondering, why does refill() throw a StreamCorrruptedException when it finds an unexpected EOF in the middle of a data block? (ObjectInputStream.java:2538)

Wouldn't it be better if it throws an EOFException or is there a different reason to throw a StreamCorrruptedException in this case?

Était-ce utile?

La solution

There is distinction between reaching the end of a well-formed stream and reaching the end of stream mid-object. if i'm reading a stream with an unknown number of objects, i can just keep calling readObject() until getting EOFException, and i know i have read everything successfully. if i got the same exception if readObject() was part way through reading an object, i wouldn't know that the last object was corrupted.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top