I'm trying to send an object with a BufferedImage through a socket. I now realize that I have to make that it transient, the class implement serializable, and override the writeObject and readObject methods. I think my write is correct but my read I keeps giving my an EOFException. Here is my class:
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);
}
I think readInt() in readObject is throwing it.