【发布时间】:2015-04-25 08:47:44
【问题描述】:
我正在尝试通过套接字发送带有 BufferedImage 的对象。我现在意识到我必须让它瞬态,类实现可序列化,并覆盖 writeObject 和 readObject 方法。我认为我的写作是正确的,但我的阅读我一直给我一个 EOFException。这是我的课:
private void writeObject(ObjectOutputStream out)throws IOException{
out.defaultWriteObject();
//write buff with imageIO to out
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
in.defaultReadObject();
//read buff with imageIO from in
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
image= ImageIO.read(ian);
}
我认为 readObject 中的 readInt() 正在抛出它。
【问题讨论】:
-
请发布完整的堆栈跟踪。
-
@Turing85 奇怪的是它没有给我一个堆栈跟踪。当我点击它时,Eclipse 说找不到源
-
我很确定它是 readInt() 虽然
标签: java sockets serialization