Thursday, January 12, 2006
Serializing a Stream
We start by declaring _actualDocument to be transient. transient is a Java keyword that
tells the serialization mechanism not to serialize the variable's value out. We then implement
writeObject( ), which does two things:
· Calls out.defaultWriteObject( ). This invokes the generic serialization
mechanism (which is the default) to write out all nontransient objects. That is, when
out.defaultWriteObject( ) is called, everything but _actualDocument has been
encoded in the stream.
· Copies _actualDocument to the stream, exactly as we did for the socket-based version
of the program.
Similarly, in readObject( ), we first call defaultReadObject( ), which retrieves all the
nontransient values, including _length, from the stream. We then read _actualDocument
from the stream.