java - Correct way to send BufferedImage in object with serialization. writeObject readObject -
i'm trying send object bufferedimage through socket. realize have make transient, class implement serializable, , override writeobject , readobject methods. think write correct read keeps giving eofexception. here class:
private void writeobject(objectoutputstream out)throws ioexception{ out.defaultwriteobject(); //write buff imageio out bytearrayoutputstream baos = new bytearrayoutputstream(); imageio.write(image, "jpg", baos); } private void readobject(objectinputstream in) throws ioexception, classnotfoundexception{ in.defaultreadobject(); //read buff imageio 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 throwing it.
your writeobject never writes out. writes bytearrayoutputstream not used later
update see e.g. post how list of images serialized. can skip count writing/reading
Comments
Post a Comment