sockets - ObjectOutputStream throws java.io.StreamCorruptedException -
i'm trying load object via objectoutputstream using sockets.
i'm testing on same machine.
i receive error:
java.io.streamcorruptedexception: invalid type code: 00 @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.defaultreadfields(unknown source) @ java.io.objectinputstream.readserialdata(unknown source) @ java.io.objectinputstream.readordinaryobject(unknown source) @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.readarray(unknown source) @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.defaultreadfields(unknown source) @ java.io.objectinputstream.readserialdata(unknown source) @ java.io.objectinputstream.readordinaryobject(unknown source) @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.readobject(unknown source)
i use code create objectoutputstream:
inputstream in = new bytearrayinputstream(bytes); objectinputstream objectinputstream = new objectinputstream(in); object readobject = objectinputstream.readobject();
the more strange there no probleam when pass objects not big.
the size in bytes of object read returns probleam about: 73423 bytes.
i pass java.util.vector via objectoutputstream.
if pass amount greater 5 throws above exception.
i created simple test (without passing through socket) ensure object serializable, works without problems. nntraining class i'm serializing:
vector<nntraining> nn = new vector<nntraining>(); bytearrayoutputstream b = new bytearrayoutputstream(); objectoutputstream o = new objectoutputstream(b); o.writeobject(nn); o.close(); bytearrayinputstream bb = new bytearrayinputstream(b.tobytearray()); objectinputstream oo = new objectinputstream(bb); vector<nntraining> v2 = (vector<nntraining>) oo.readobject();
you don't need mucking around byte arrays , bytearrayinputstreams. attach objectinputstream directly socket,once, , call readobject() every time want to. @ sender, attach objectoutputstream directly socket, once, , call writeobject() every time need to.
the problem you're getting because aren't doing this.
Comments
Post a Comment