• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we want to store something in a file...we basically use Serialization and the steps we write for that are :

1. FileOutputStream fs = new FileOutputStream("abc.txt"); //connect to the file.

2. ObjectOutputStream os = new ObjectOutputStream(fs);

3. os.writeObject(object1)

Can anyone explain the 2nd point...i mean what does it actually do....

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second line uses a pattern called Decorator pattern which adds some extra functionallity to the FileOutputStream at the runtime but still acting on the same object.

Generally FileOutputStream is used to write some data to the file but in your case you want to write the object into a file...FileOutputStream itself can not do it,so you decorating the FileOutputStream using ObjectOutputStream and telling that whatever the ObjectOutputStream is sending send it to the file.

You can read about the Decorator pattern here
 
Vasiq Molvizadah
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basically when i write the code which i had written above ...what it'll do is:

It'll write the data into a buffer and then it'll send the data to the FileOutputStream to connect to the file.

I've also attached an image file which i've created after reading the Decorator pattern 4 times...correct me if i'm wrong

And thanks a lot for the info....i didn't knw about this topic before....
Untitled.jpg
[Thumbnail for Untitled.jpg]
Decorator
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.

you are right.
 
Whatever. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic