package de.ugoe.cs.autoquest.plugin.mfc; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.logging.Level; import org.apache.commons.codec.binary.Base64; import de.ugoe.cs.util.FileTools; import de.ugoe.cs.util.StringTools; import de.ugoe.cs.util.console.Console; /** *
* Pre-processes log files generated by the EventBench's MFCUsageMonitor. It * decodes Base64 encoding into UTF-16. It removes all lines of the log file, * that do not start with the prefix "UL:", end everything before the prefix and * the prefix itself. *
* * @author Steffen Herbold * @version 1.0 */ public class LogPreprocessor { /** ** Internal flag that monitors whether there is an open session-node in the * XML file to ensure that there is a closing session-node for each opening * session node and, thereby, ensure that the XML file is well formed. *
*/ private boolean sessionOpen = false; /** ** Internal flag that monitors whether a message node is longer than one * line, as the prefix handling is different in this case. *
*/ private boolean msgIncomplete = false; /** ** Flag that marks whether the log file is Base64 encoded. *
*/ private boolean base64; /** ** Constructor. Creates a new LogPreprocessor that does not decode Base64. *
*/ public LogPreprocessor() { this(false); } /** ** Constructor. Creates a new LogPreprocessor. *
* * @param base64 * if true, Base64 will be decoded. */ public LogPreprocessor(boolean base64) { this.base64 = base64; } /** ** Pre-processes a single log file. *
* * @param source * name and path of the source file * @param target * name and path of the target file * @throws IOException * thrown if there is a problem with reading from or writing to * the source, respectively target file * @throws FileNotFoundException * thrown if the source file is not found */ public void convertToXml(String source, String target) throws IOException, FileNotFoundException { OutputStreamWriter targetFile = new OutputStreamWriter( new FileOutputStream(target), "UTF-8"); targetFile.write("" + StringTools.ENDLINE); targetFile.write("* Pre-processes all files in a given source folder. *
* * @param path * path of the source folder * @param target * name and path of the target file * @throws IOException * thrown if there is a problem with reading from or writing to * the source, respectively target file * @throws FileNotFoundException * thrown if the source file is not found */ public void convertDirToXml(String path, String target) throws IOException, FileNotFoundException { OutputStreamWriter targetFile = new OutputStreamWriter( new FileOutputStream(target), "UTF-8"); targetFile.write("" + StringTools.ENDLINE); targetFile.write("* Internal function that pre-processes a log file. *
* * @param source * name and path of the source file * @param target * name and path of the target file * @throws IOException * thrown if there is a problem with reading from or writing to * the source, respectively target file * @throws FileNotFoundException * thrown if the source file is not found */ private void processFile(String source, OutputStreamWriter targetFile) throws FileNotFoundException, IOException { String[] lines = FileTools.getLinesFromFile(source, false); String incompleteLine = ""; for (String currentLine : lines) { if (currentLine.contains("UL: