source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDloadObject.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.FileInputStream;
4import java.io.IOException;
5import java.io.ObjectInputStream;
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 CMDloadObject 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                } catch (Exception e) {
24                        throw new InvalidParameterException();
25                }
26
27                Object data = null;
28                FileInputStream fis = null;
29                ObjectInputStream in = null;
30                try {
31                        fis = new FileInputStream(filename);
32                        in = new ObjectInputStream(fis);
33                        data = in.readObject();
34                        in.close();
35                } catch (IOException ex) {
36                        ex.printStackTrace();
37                } catch (ClassNotFoundException ex) {
38                        ex.printStackTrace();
39                }
40                if( GlobalDataContainer.getInstance().addData(objectName, data ) ) {
41                        Console.traceln("Old data \"" + objectName + "\" overwritten");
42                }
43        }
44
45        @Override
46        public void help() {
47                // TODO Auto-generated method stub
48                Console.println("Usage: loadObject <filename> <objectName>");
49        }
50
51}
Note: See TracBrowser for help on using the repository browser.