source: trunk/JFCMonitor/src/de/ugoe/cs/eventbench/jfcmonitor/Runner.java @ 308

Last change on this file since 308 was 308, checked in by sherbold, 12 years ago
  • now specifies character encoding of file explicitly instead of assuming default encoding
  • Property svn:mime-type set to text/plain
File size: 2.4 KB
Line 
1package de.ugoe.cs.eventbench.jfcmonitor;
2
3import java.awt.AWTEvent;
4import java.awt.Toolkit;
5import java.awt.event.AWTEventListener;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.io.OutputStreamWriter;
9import java.io.UnsupportedEncodingException;
10import java.util.Arrays;
11
12/**
13 * <p>
14 * Start-up class of the application.
15 * </p>
16 * <p>
17 * Launches the application under test in the same JVM.
18 * </p>
19 *
20 * @author Steffen Herbold
21 * @version 1.0
22 */
23public class Runner {
24
25        /**
26         * <p>
27         * Debugging variable. If set to true, the logging is also written to the
28         * console.
29         * </p>
30         */
31        private final static boolean stdOutputWrite = true;
32
33        /**
34         * <p>
35         * Main method of the application.
36         * </p>
37         *
38         * @param args
39         *            the first parameter defines the Jar file that contains the
40         *            start-up information of the application under test. The
41         *            remaining parameters are passed on the toe application under
42         *            test.
43         */
44        public static void main(String[] args) {
45                String logfileName = "jfcmonitor_" + System.currentTimeMillis()
46                                + ".log";
47
48                FileOutputStream fis;
49                OutputStreamWriter writer;
50                try {
51                        // the writer is not closed explicitly!
52                        fis = new FileOutputStream(logfileName, true);
53                        writer = new OutputStreamWriter(fis, "UTF-16");
54                } catch (IOException e) {
55                        System.err.println("JFCMONITOR -- failure opening logfile: "
56                                        + e.getMessage());
57                        return;
58                }
59
60                AWTEventListener listenerFile = new JFCListener(writer);
61                Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
62                                AWTEvent.KEY_EVENT_MASK);
63                Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
64                                AWTEvent.MOUSE_EVENT_MASK);
65
66                if (stdOutputWrite) {
67                        AWTEventListener listenerStdOut;
68                        try {
69                                listenerStdOut = new JFCListener(new OutputStreamWriter(
70                                                System.out, "UTF-8"));
71                                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
72                                                AWTEvent.KEY_EVENT_MASK);
73                                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
74                                                AWTEvent.MOUSE_EVENT_MASK);
75                        } catch (UnsupportedEncodingException e) {
76                                System.err
77                                                .println("JFCMONITOR -- failure to create OutputStreamWriter with UTF-8 encoding to System.out");
78                        }
79                }
80
81                JarLauncher launcher = new JarLauncher(args[0], Arrays.copyOfRange(
82                                args, 1, args.length));
83                launcher.exec();
84        }
85}
Note: See TracBrowser for help on using the repository browser.