source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/misc/CMDsave.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.commands.misc;
16
17import java.io.FileOutputStream;
18import java.io.IOException;
19import java.io.ObjectOutputStream;
20import java.util.List;
21
22import de.ugoe.cs.util.console.Command;
23import de.ugoe.cs.util.console.Console;
24import de.ugoe.cs.util.console.GlobalDataContainer;
25
26/**
27 * <p>
28 * Command to save the {@link GlobalDataContainer} through serialization.
29 * </p>
30 *
31 * @author Steffen Herbold
32 * @version 1.0
33 */
34public class CMDsave implements Command {
35
36        /*
37         * (non-Javadoc)
38         *
39         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
40         */
41        @Override
42        public void run(List<Object> parameters) {
43                String filename;
44                try {
45                        filename = (String) parameters.get(0);
46                } catch (Exception e) {
47                        throw new IllegalArgumentException();
48                }
49
50                FileOutputStream fos = null;
51                ObjectOutputStream out = null;
52                try {
53                        fos = new FileOutputStream(filename);
54                        out = new ObjectOutputStream(fos);
55                        out.writeObject(GlobalDataContainer.getInstance());
56                        out.close();
57                } catch (IOException ex) {
58                        Console.logException(ex);
59                }
60        }
61
62        /*
63         * (non-Javadoc)
64         *
65         * @see de.ugoe.cs.util.console.Command#help()
66         */
67        @Override
68        public String help() {
69                return "save <filename>";
70        }
71
72}
Note: See TracBrowser for help on using the repository browser.