source: trunk/j/src/bsh/commands/save.bsh @ 2

Last change on this file since 2 was 2, checked in by piso, 18 years ago

Initial checkin.

File size: 750 bytes
Line 
1
2bsh.help.save = "usage: save( object, filename )";
3
4save( Object obj, String filename ) {
5  file = pathToFile( filename );
6
7  if ( !(obj instanceof Serializable) ) {
8    print("Type "+obj.getClass()+" is not serializable");
9    return;
10  }
11
12  // Detach bsh objects from the caller's namespace during serialization
13  // NOTE: THIS IS NOT THREAD SAFE
14  if ( obj instanceof bsh.This ) {
15    super.parent = obj.namespace.getParent();
16    obj.namespace.prune();
17  }
18 
19  out = new FileOutputStream( file );
20  oout = new ObjectOutputStream(out);
21  oout.writeObject( obj );
22  oout.close();
23
24  // Reattach bsh objects to the caller's namespace after serialization
25  // NOTE: THIS IS NOT THREAD SAFE
26  if ( obj instanceof bsh.This )
27    obj.namespace.setParent( super.parent );
28}
29
30
Note: See TracBrowser for help on using the repository browser.