• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can an outputstream be serialised?

 
Moin Khatri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am Moin.Please can anyone explain me whether an Output Stream be serialized or no and why.

Thanks in advance,
Moin
 
Amir Alagic
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, it is not possible to serialize OutputStream.
 
Moin Khatri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply Amir.any explaination this context would be really helpful for me

Cheers,
Moieen
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The short answer is, because no OutputStream (that I know of) implements the Serializable interface. Therefore, if you try to serialize it, you will get an exception. They didn't design these classes to be serializable because they didn't think it would be useful to anyone.

I think you probably need to serialize the data written to the OutputStream. Can you tell us anything about the OutputStream you're using? Where did it come from? Did you create it, or did it come from some other class? What sort of data is being written to it?

One possibly useful technique is to us a ByteArrayOutputStream for the OutputStream. When you are done writing to the stream, close() it, and then call toByteArray(). Now you have a byte[] which can be serialized.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic