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

Last change on this file since 96 was 90, checked in by sherbold, 13 years ago
  • renamed getReplayXML to getReplay in de.ugoe.cs.eventbench.data.IReplayable and implementing classes
  • minor changes
  • Property svn:mime-type set to text/plain
File size: 1.2 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                String filename;
18                String objectName;
19                try {
20                        filename = (String) parameters.get(0);
21                        objectName = (String) parameters.get(1);
22                }
23                catch (Exception e) {
24                        throw new InvalidParameterException();
25                }
26               
27                Object dataObject = GlobalDataContainer.getInstance().getData(objectName);
28                if( dataObject==null ) {
29                        Console.println("Object " + objectName + " not found in storage.");
30                }
31               
32                FileOutputStream fos = null;
33                ObjectOutputStream out = null;
34                try {
35                        fos = new FileOutputStream(filename);
36                        out = new ObjectOutputStream(fos);
37                        out.writeObject(dataObject);
38                        out.close();
39                } catch (IOException ex) {
40                        ex.printStackTrace();
41                }
42        }
43
44        @Override
45        public void help() {
46                Console.println("Usage: saveObject <filename> <objectName>");
47        }
48
49}
Note: See TracBrowser for help on using the repository browser.