serialization - java.io.StreamCorruptedException:unexpected reset; recursion depth 1 -


i'm trying write , read 1 file objectinputstream , objectoutputstream, in 2 threads. since have append file, according online advise, implement class:

public class appendableobjectoutputstream extends objectoutputstream {  public appendableobjectoutputstream(outputstream out) throws ioexception {     super(out); }  protected void writestreamheader() throws ioexception {     reset(); } } 

and write logic like:

synchronized (sdklogger.failoverfile) {         fileoutputstream fos = null;         objectoutputstream oos = null;         try {             if (failoverfile.exists()) {                 fos = new fileoutputstream(sdklogger.failoverfile, true);                 oos = new appendableobjectoutputstream(fos);             } else {                 fos = new fileoutputstream(sdklogger.failoverfile, true);                 oos = new objectoutputstream(fos);             }             (logmodel log : logs)                 oos.writeobject(log); 

because have synchronized on global file used purpose, not referenced anywhere else, don't understand why meet exception always.

java.io.streamcorruptedexception: unexpected reset; recursion depth: 1 @ java.io.objectinputstream.handlereset(unknown source) @ java.io.objectinputstream.access$600(unknown source) @ java.io.objectinputstream$blockdatainputstream.readblockheader(unknown source) @ java.io.objectinputstream$blockdatainputstream.refill(unknown source) @ java.io.objectinputstream$blockdatainputstream.skipblockdata(unknown source) @ java.io.objectinputstream.skipcustomdata(unknown source) @ java.io.objectinputstream.readnonproxydesc(unknown source) @ java.io.objectinputstream.readclassdesc(unknown source) @ java.io.objectinputstream.readordinaryobject(unknown source) @ java.io.objectinputstream.readobject0(unknown source) @ java.io.objectinputstream.readobject(unknown source)  

after searching web, find nothing on error , why 1 come cross error.

thanks in advance.

calling reset() in writestreamheader() pointless. still constructing object stream @ point: there nothing in reset yet. source of problem. remove it.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -