|
Last change
on this file since 89 was
87,
checked in by sherbold, 15 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 | |
|---|
| 1 | package de.ugoe.cs.eventbench.commands;
|
|---|
| 2 |
|
|---|
| 3 | import java.io.FileOutputStream;
|
|---|
| 4 | import java.io.IOException;
|
|---|
| 5 | import java.io.ObjectOutputStream;
|
|---|
| 6 | import java.security.InvalidParameterException;
|
|---|
| 7 | import java.util.List;
|
|---|
| 8 |
|
|---|
| 9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
|---|
| 10 | import de.ugoe.cs.util.console.Command;
|
|---|
| 11 | import de.ugoe.cs.util.console.Console;
|
|---|
| 12 |
|
|---|
| 13 | public 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.