We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › serialization of processing objects
Page Index Toggle Pages: 1
serialization of processing objects (Read 810 times)
serialization of processing objects
Sep 19th, 2007, 3:31pm
 
Hi .. this be my first post ..
I am wondering if there is some sagely knowledge on what the best method for object serialization in processing might be , like one can do in python with the pickle module .. i think there is proXML maybe but i don't know if this is the most efficient solution,

thankyouvmuch

thomasgreg
Re: serialization of processing objects
Reply #1 - Sep 19th, 2007, 3:57pm
 
Jaav supports serialisation naturally, you don't need any library to do it. All you have to do is say that a class implements serializable.

Then to serialise to disc, you can do something simple like:

Code:
import java.io.*;

// serialise an object to disc..

FileOutputStream f=new FileOutputStream(dataPath("data.ser"));
ObjectOutputStream o=new ObjectOutputStream(f);
o.writeObject(MyObj);
o.close();

// read it back in

FileInputStream f=new FileInputStream(dataPath("data.ser"));
ObjectInputStream o=new ObjectInputStream(f);
MyClass MyObj=(MyClass)o.readObject();
o.close();



It should be noted however that you can't necessarily serialise everything, as some pre-packaged classes may not have declared "implements serializable" and so you'll not be able to serialize them.

Page Index Toggle Pages: 1