Java IO ObjectOutputStream
1 posts in topic
Flat View  Flat View

Posted By:   Murali_L
Posted On:   Monday, April 16, 2001 06:59 AM

I am using replaceObject(Object obj) method of OjectOutputStream.. While calling this method where to mention the alternate object that replaced the specified one.. parameter only takes the object to be replaced

Re: Java IO ObjectOutputStream

Posted By:   Tim_Rohaly  
Posted On:   Thursday, April 19, 2001 02:19 PM

replaceObject() is a protected
method in ObjectOutputStream, and as such it
is only callable within ObjectOutputStream itself
or within subclasses of ObjectOutputStream. This
is probably not what you want to be using.

The proper way to designate and use replacement objects
is by defining the Object writeReplace()
method in your serializable class. Since this method is part
of each serializable class, it is implicit which object is being
replaced, while the replacement object is the return value of this
method. The replacement object must also be serializable
and define (if desired) a Object readResolve() method.
The return value of this read method can be used to restore the
original object.

The object streams for reading and writing know nothing about
which objects are replaced, and by what other objects they are
replaced. The output stream for instance automatically
invokes writeReplace() on every serializable object
that has that method defined, and simply writes the return
value to the stream.

This process is explained in great detail in the Serialization specification.

About | Sitemap | Contact