source: trunk/autoquest-plugin-genericevents/src/main/java/de/ugoe/cs/autoquest/plugin/genericevents/commands/CMDsplitDirGenericEvents.java @ 2165

Last change on this file since 2165 was 2165, checked in by pharms, 7 years ago
  • changes for first VR oriented usability evaluation
  • Property svn:mime-type set to text/plain
File size: 4.0 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.plugin.genericevents.commands;
16
17import java.io.File;
18import java.util.Arrays;
19import java.util.List;
20import java.util.logging.Level;
21
22import de.ugoe.cs.autoquest.plugin.genericevents.GenericEventLogSplitter;
23import de.ugoe.cs.util.console.Command;
24import de.ugoe.cs.util.console.Console;
25
26/**
27 * <p>
28 * TODO comment
29 * </p>
30 *
31 * @author Patrick Harms
32 * @version 1.0
33 */
34public class CMDsplitDirGenericEvents 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 source = null;
44        String dest = null;
45        long timediff = 0;
46       
47        try {
48            for (int i = 0; i < parameters.size(); i++) {
49                String param = (String) parameters.get(i);
50                if (source == null) {
51                    source = param;
52                }
53                else if (dest == null) {
54                    dest = param;
55                }
56                else {
57                    timediff = Long.parseLong(param);
58                }
59            }
60        }
61        catch (Exception e) {
62            throw new IllegalArgumentException("illegal parameters provided: " + e);
63        }
64
65        File sourceFolder = new File(source);
66        if (!sourceFolder.isDirectory()) {
67            Console.printerrln(sourceFolder + " is not a directory");
68            return;
69        }
70
71        File destFolder = new File(dest);
72        if (destFolder.exists() && !destFolder.isDirectory()) {
73            Console.printerrln(destFolder + " is not a directory");
74            return;
75        }
76       
77        if (sourceFolder.equals(destFolder)) {
78            Console.printerrln("source and destination must not be the same");
79            return;
80        }
81
82        splitFile(sourceFolder, destFolder, timediff);
83    }
84
85    /**
86     * <p>
87     * recursive method for parsing a directory structures
88     * </p>
89     *
90     * @param file   the file object to be parsed. If the file is a folder, the method calls itself
91     *               for all children
92     * @param parser the parser to use for parsing the files.
93     */
94    private void splitFile(File source, File dest, long timediff) {
95        if (source.isDirectory()) {
96            String[] children = source.list();
97            Arrays.sort(children);
98           
99            for (String child : children) {
100                File childFile = new File(source, child);
101                File childDestination = new File(dest, child);
102                splitFile(childFile, childDestination, timediff);
103            }
104        }
105        else if (source.isFile()) {
106            Console.traceln(Level.INFO, "Processing file: " + source.getAbsolutePath());
107
108            try {
109                new GenericEventLogSplitter().splitLogFile(source, dest.getParentFile(), timediff);
110            }
111            catch (Exception e) {
112                Console.printerrln("Could not split " + source.getAbsolutePath() + ": " + e.getMessage());
113            }
114        }
115    }
116
117    /*
118     * (non-Javadoc)
119     *
120     * @see de.ugoe.cs.util.console.Command#help()
121     */
122    @Override
123    public String help() {
124        return "splitDirGenericEvents <directory>";
125    }
126
127}
Note: See TracBrowser for help on using the repository browser.