• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

can an outputstream be serialised?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no, it is not possible to serialize OutputStream.
 
Moin Khatri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply Amir.any explaination this context would be really helpful for me

Cheers,
Moieen
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic