source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDloadObject.java @ 138

Last change on this file since 138 was 89, checked in by sherbold, 13 years ago
  • minor changes
  • 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                String filename;
18                String objectName;
19                try {
20                        filename = (String) parameters.get(0);
21                        objectName = (String) parameters.get(1);
22                } catch (Exception e) {
23                        throw new InvalidParameterException();
24                }
25
26                Object data = null;
27                FileInputStream fis = null;
28                ObjectInputStream in = null;
29                try {
30                        fis = new FileInputStream(filename);
31                        in = new ObjectInputStream(fis);
32                        data = in.readObject();
33                        in.close();
34                } catch (IOException ex) {
35                        ex.printStackTrace();
36                } catch (ClassNotFoundException ex) {
37                        ex.printStackTrace();
38                }
39                if( GlobalDataContainer.getInstance().addData(objectName, data ) ) {
40                        Console.traceln("Old data \"" + objectName + "\" overwritten");
41                }
42        }
43
44        @Override
45        public void help() {
46                Console.println("Usage: loadObject <filename> <objectName>");
47        }
48
49}
Note: See TracBrowser for help on using the repository browser.