source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/commands/CMDpreprocessJFC.java @ 424

Last change on this file since 424 was 392, checked in by sherbold, 13 years ago
  • JFC pre-processors (commands preprocessDirJFC, preprocessJFC) now generate UTF-8 XML files instead of UTF-16.
  • de.ugoe.cs.eventbench.jfc.JFCLogParser adapted to read UTF-8 XML files instead of UTF-16.
  • parseDirJFC and parseJFC commands now both pre-compute all JFC event target equalities and furthermore compare all loaded events to a dummy event before the precomputation to make sure the events are known by de.ugoe.cs.eventbench.jfc.data.JFCTargetComparator.
  • Property svn:mime-type set to text/plain
File size: 2.5 KB
Line 
1package de.ugoe.cs.eventbench.jfc.commands;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.FileNotFoundException;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.io.InputStreamReader;
9import java.io.OutputStreamWriter;
10import java.io.UnsupportedEncodingException;
11import java.security.InvalidParameterException;
12import java.util.List;
13
14import de.ugoe.cs.util.console.Command;
15import de.ugoe.cs.util.console.Console;
16
17/**
18 * <p>
19 * Command to pre-process files written by EventBench's JFCMonitor. The only
20 * task of the pre-processing is checking if the session was closed properly,
21 * i.e., if the XML file ends with a {@code </sessions>} tag. If this is not the
22 * case, the tag will be appended to the file.
23 * </p>
24 *
25 * @author Steffen Herbold
26 * @version 1.0
27 */
28public class CMDpreprocessJFC implements Command {
29
30        /*
31         * (non-Javadoc)
32         *
33         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
34         */
35        @Override
36        public void run(List<Object> parameters) {
37                String source;
38                String target;
39                try {
40                        source = (String) parameters.get(0);
41                        target = (String) parameters.get(1);
42                } catch (Exception e) {
43                        throw new InvalidParameterException();
44                }
45
46                File file = new File(source);
47                InputStreamReader reader;
48                try {
49                        FileInputStream fis = new FileInputStream(file);
50                        reader = new InputStreamReader(fis, "UTF-16");
51                } catch (FileNotFoundException e) {
52                        Console.printerrln(e.getMessage());
53                        return;
54                } catch (UnsupportedEncodingException e) {
55                        Console.printerrln(e.getMessage());
56                        return;
57                }
58                char[] buffer = new char[(int) file.length()];
59                try {
60                        reader.read(buffer);
61                        reader.close();
62                } catch (IOException e) {
63                        Console.printerrln(e.getMessage());
64                        return;
65                }
66
67                String content = new String(buffer).trim();
68
69                OutputStreamWriter writer;
70                try {
71                        FileOutputStream fos = new FileOutputStream(target);
72                        writer = new OutputStreamWriter(fos, "UTF-8");
73                } catch (IOException e) {
74                        Console.printerrln(e.getMessage());
75                        return;
76                }
77                try {
78                        writer.write(content);
79                        if (!content.endsWith("</sessions>")) {
80                                writer.write("</sessions>");
81                        }
82                        writer.close();
83                } catch (IOException e) {
84                        Console.printerrln(e.getMessage());
85                }
86        }
87
88        /*
89         * (non-Javadoc)
90         *
91         * @see de.ugoe.cs.util.console.Command#help()
92         */
93        @Override
94        public void help() {
95                Console.println("Usage: preprocessJFC <sourceFile> <targetFile>");
96        }
97
98}
Note: See TracBrowser for help on using the repository browser.