Calendar

September 2010
S M T W T F S
« Jul    
 1234
567891011
12131415161718
19202122232425
2627282930  

Object serialization in groovy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// put this in a file named Name.groovy and compile using groovyc 
class Name implements Serializable  {
   def fname, lname
}
// Now run the code below to see the Object serialization and de-serialization.
def test1= new Name(fname: "fn1", lname : "ln1")
def test2 = new Name(fname: "fn2", lname: "ln2")
//serialization
new File("C:/config.txt").withObjectOutputStream { out ->
    out << test1
    out << test2
}
//de-serialization
new File("C:/config.txt").withObjectInputStream { instream ->
    instream.eachObject { 
        println it
    }
}

Source: satish.name

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Google Bookmarks
  • Live
  • MySpace
  • PDF
  • RSS
  • Twitter
  • Yahoo! Bookmarks
  • email

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">