Thursday, March 12, 2009

How can I create an ObjectInputStream from an ObjectOutputStream

Question :How can I create an ObjectInputStream from an ObjectOutputStream
without a file in between? (CoreJava)

Answer :ObjectOutputStream and ObjectInputStream work to/from any stream
object. You could use a ByteArrayOutputStream and then get the array
and insert it into a ByteArrayInputStream. You could also use the piped
stream classes as well. Any java.io class that extends the OutputStream
and InputStream classes can be used.
Alternatively, the ObjectOutputStream> class implements a reset method
that discards the memory of having sent an object, so sending an object
again will make a copy.

No comments: