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

Last change on this file since 230 was 211, checked in by sherbold, 13 years ago
  • adapted Console usage to renamed methods (see previous commit)
  • Property svn:mime-type set to text/plain
File size: 1.6 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
13/**
14 * <p>
15 * Command to load a previously serialized object and store it in the
16 * {@link GlobalDataContainer}.
17 * </p>
18 *
19 * @author Steffen Herbold
20 * @version 1.0
21 */
22public class CMDloadObject implements Command {
23
24        /*
25         * (non-Javadoc)
26         *
27         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
28         */
29        @Override
30        public void run(List<Object> parameters) {
31                String filename;
32                String objectName;
33                try {
34                        filename = (String) parameters.get(0);
35                        objectName = (String) parameters.get(1);
36                } catch (Exception e) {
37                        throw new InvalidParameterException();
38                }
39
40                Object data = null;
41                FileInputStream fis = null;
42                ObjectInputStream in = null;
43                try {
44                        fis = new FileInputStream(filename);
45                        in = new ObjectInputStream(fis);
46                        data = in.readObject();
47                        in.close();
48                } catch (IOException ex) {
49                        Console.logException(ex);
50                } catch (ClassNotFoundException ex) {
51                        Console.logException(ex);
52                }
53                if (GlobalDataContainer.getInstance().addData(objectName, data)) {
54                        Console.traceln("Old data \"" + objectName + "\" overwritten");
55                }
56        }
57
58        /*
59         * (non-Javadoc)
60         *
61         * @see de.ugoe.cs.util.console.Command#help()
62         */
63        @Override
64        public void help() {
65                Console.println("Usage: loadObject <filename> <objectName>");
66        }
67
68}
Note: See TracBrowser for help on using the repository browser.