Someone has answered this for me now. The constructor for ObjectOutputStream creates the header.
public ObjectOutputStream(OutputStream out) throws IOException {
verifySubclass();
bout = new BlockDataOutputStream(out);
handles = new HandleTable(10, (float) 3.00);
subs = new ReplaceTable(10, (float) 3.00);
enableOverride = false;
writeStreamHeader();
bout.setBlockDataMode(true);
}
protected void writeStreamHeader() throws IOException {
bout.writeShort(STREAM_MAGIC);
bout.writeShort(STREAM_VERSION);
}
So when we create an instance of the ReuseobjectOutputStream class, the constructor for ObjectOutputStream is called but when it gets to the line writeStreamHeader(), this method has been overriden in the subclass. Hence the version of this method in the ReuseobjectOutputStream class is used instead and no header is written.
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.IOException;
public class ReuseObjectOutputStream extends ObjectOutputStream {
public ReuseObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
protected void writeStreamHeader() throws IOException {
reset();
}
}
Gill BC
|