Desclaimer My question is different from two following links
public class AppendableObjectOutputStream extends ObjectOutputStream {
public AppendableObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {}
}
- The problem with above solutions is that they do not support writing multiple objects to appendable stream w/o closing the stream.
- If I open appendable stream, write multiple objects - then at time of reading I can read only first object properly and on trying to read second object, I get EOF exception.
If I proceed the way like write on object to appendable stream, close stream. Then again open stream, write another object close and so on. This way I am able to read multiple objects properly.
fileOutputStream = new FileOutputStream("abc.dat",true); outputBuffer = new BufferedOutputStream(fileOutputStream); objectStream = new AppendableObjectOutputStream(outputBuffer); BucketUpdate b1 = new BucketUpdate("getAllProducts1",null,"1",null); BucketUpdate b2 = new BucketUpdate("getAllProducts2",null,"2",null); BucketUpdate b3 = new BucketUpdate("getAllProducts3",null,"3",null); objectStream.writeObject(b1); objectStream.writeObject(b2); objectStream.writeObject(b3); objectStream.close();