source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsaveObject.java @ 88

Last change on this file since 88 was 87, checked in by sherbold, 14 years ago
  • made event implementations serializable

+ added commands saveObject and loadObject to save data stored in the global data container

  • Property svn:mime-type set to text/plain
File size: 1.3 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.io.FileOutputStream;
4import java.io.IOException;
5import java.io.ObjectOutputStream;
6import java.security.InvalidParameterException;
7import java.util.List;
8
9import de.ugoe.cs.eventbench.data.GlobalDataContainer;
10import de.ugoe.cs.util.console.Command;
11import de.ugoe.cs.util.console.Console;
12
13public class CMDsaveObject implements Command {
14
15        @Override
16        public void run(List<Object> parameters) {
17                // TODO Auto-generated method stub
18                String filename;
19                String objectName;
20                try {
21                        filename = (String) parameters.get(0);
22                        objectName = (String) parameters.get(1);
23                }
24                catch (Exception e) {
25                        throw new InvalidParameterException();
26                }
27               
28                Object dataObject = GlobalDataContainer.getInstance().getData(objectName);
29                if( dataObject==null ) {
30                        Console.println("Object " + objectName + " not found in storage.");
31                }
32               
33                FileOutputStream fos = null;
34                ObjectOutputStream out = null;
35                try {
36                        fos = new FileOutputStream(filename);
37                        out = new ObjectOutputStream(fos);
38                        out.writeObject(dataObject);
39                        out.close();
40                } catch (IOException ex) {
41                        ex.printStackTrace();
42                }
43        }
44
45        @Override
46        public void help() {
47                // TODO Auto-generated method stub
48                Console.println("Usage: saveObject <filename> <objectName>");
49        }
50
51}
Note: See TracBrowser for help on using the repository browser.