开发者

Recovering a crashed InputStream

开发者 https://www.devze.com 2023-03-09 09:51 出处:网络
I\'m writing a server and I\'m using an ObjectInputStream to handle proprietary packets. I\'ve recently been sometimes getting some unexpected ClassCastExceptions when I want call objectInputStream.re

I'm writing a server and I'm using an ObjectInputStream to handle proprietary packets. I've recently been sometimes getting some unexpected ClassCastExceptions when I want call objectInputStream.readObject() and then trying casting them into the proprietary packets. I've been开发者_如何学编程 trying to trace the problem and I've been wondering whether it's because the objectInputStream is crashing due to some problem. According to the documentation for the method objectInputStream.readObject()... "All exceptions are fatal to the InputStream and leave it in an indeterminate state; it is up to the caller to ignore or recover the stream state."

I'm wondering what they mean by "recover the stream state"... is there a proper way for me to recover the objectInputStream or should I do a socket.getInputStream()?


If I understand correctly, your exceptions aren't caused by objectInputStream.readObject(), but by casting the (successfully returned) object to whatever it is you're trying to read, so the exception shouldn't affect the stream.

0

精彩评论

暂无评论...
验证码 换一张
取 消