?? logfileparser.java
字號:
package cn.ac.siat.dswatcher.toolkit;
import cn.ac.siat.dswatcher.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Iterator;
import java.sql.Date;
import java.awt.*;
public class LogFileParser {
private static File fLogFile;
private static LogFileParser instance;
private LogFileParser() {
}
public static LogFileParser getInstance() {
if (instance == null)
instance = new LogFileParser();
return instance;
}
public static void setLogFile(File logFile) {
fLogFile = logFile;
}
public static List parse(File logFile) throws IOException {
MotionPanel.nodeNum = 0;
MotionPanel.processMap.clear();
MotionPanel.processList.clear();
MotionPanel.nodeList.clear();
MotionPanel.nodeMap.clear();
MotionPanel.processRecordList.clear();
LogViewerPlayer.allDisplayEdgeMap.clear();
LogViewerPlayer.informationList.clear();
List resultList = new ArrayList(100);
BufferedReader br = new BufferedReader(new FileReader(logFile));
String line;
for (int i = 0; (line = br.readLine()) != null; i++) {
if (i == 0) {
if (!line.startsWith("#")) {
System.err.println("The first line of log file should be started with '#'!");
break;
} else {
int index = line.indexOf(":");
String nodes = (line.substring(index + 1)).trim();
String [] node = nodes.split(";");
MotionPanel.nodeNum = node.length;
for (int j = 0; j < MotionPanel.nodeNum; j++) {
MotionPanel.nodeList.add(node[j]);
Node n = new Node(node[j], "", 0, 0, Color.yellow);
MotionPanel.mp.computeXY(n,j);
MotionPanel.nodeMap.put(node[j], n);
}
}
}
else if (i == 1) {
if (!line.startsWith("#")) {
System.err.println("The second line of log file should be started with '#'!");
break;
} else {
int index = line.indexOf(":");
String processes = (line.substring(index + 1)).trim();
String [] process = processes.split(";");
MotionPanel.processNum = process.length;
for (int j = 0; j < MotionPanel.processNum; j++) {
MotionPanel.processList.add(process[j]);
ArrayList aList = new ArrayList();
MotionPanel.processMap.put(process[j],aList);
}
}
} else {
//parse time
String[] eventLine = line.split("<->");
if (eventLine.length == 2) {
String time = eventLine[0].trim();
String event = eventLine[1].trim();
java.util.Date d = null;
try {
d = TimeTool.getDate(time, "yyyy-MM-dd HH:mm:ss");
} catch (Exception e) {
e.printStackTrace();
}
long ltime = d.getTime();
// System.out.println(ltime);
String [] str = event.split(":");
String processName = str[0].trim();
String [] nodes = str[1].trim().split("->");
Node from = ((Node) MotionPanel.nodeMap.get(nodes[0].trim()));
Node to = null;
if(!nodes[1].trim().equals("!"))
to = ((Node) MotionPanel.nodeMap.get(nodes[1].trim()));
PlayFrame pf = new PlayFrame(ltime,processName, from, to);
LogViewerPanel.frameList.add(pf);
resultList.add(pf);
}
}
}
br.close();
LogViewerPlayer.end = false;
System.out.println("Parse: Successful!");
return resultList;
}
private static String parseFromSentence(String line) {
StringTokenizer st = new StringTokenizer(line, " ");
String result = "";
st.nextToken();
st.nextToken();
result = st.nextToken();
int i = result.lastIndexOf(".");
result = result.substring(i + 1);
return result;
}
private static List parseToSentence(String line) throws Exception {
List list = new ArrayList(2);
StringTokenizer st = new StringTokenizer(line, ":");
st.nextToken();
st.nextToken();
String to = st.nextToken();
StringTokenizer st2 = new StringTokenizer(to, " ");
st2.nextToken();
to = st2.nextToken();
list.add(to);
int ii = line.indexOf("TimeScale:");
to = line.substring(ii + 10);
list.add(to);
return list;
}
public static void main(String[] args) {
String line = "a b cc.abc";
String r = parseFromSentence(line);
System.out.println("r=" + r);
String to = "a: b :cc abc:dd:21:a:b:TimeScale:342134";
List r12 = null;
try {
r12 = parseToSentence(to);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
System.out.println("r12=" + r12.get(1));
System.out.println("1170920653921=" + TimeTool.dateToString(new Date(1170920653921l), "yyyy-MM-dd HH:mm:ss"));
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -