com.github.diceproject.qt.logs.ExtractDataFromLog Maven / Gradle / Ivy
package com.github.diceproject.qt.logs;
//author: yifan
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
public class ExtractDataFromLog {
/**
* @param args
*/
private static FileReader fileReader;
private static BufferedReader br;
private static BufferedWriter bw;
private static FileWriter fw;
private static BufferedWriter bw1;
private static FileWriter fw2;
private static BufferedWriter bw2;
private static FileWriter fw1;
private static Map dataMap;
private static Map dataSizeMap;
public static Map ExtractData(File file1, File file2, File extractDatafile, String spoutName, String[] logPathList) {
// TODO Auto-generated method stub
try {
if (!file1.exists()) {
file1.createNewFile();
}
fw1 = new FileWriter(file1.getAbsoluteFile());
bw1 = new BufferedWriter(fw1);
if (!file2.exists()) {
file2.createNewFile();
}
fw2 = new FileWriter(file2.getAbsoluteFile());
bw2 = new BufferedWriter(fw2);
dataMap = new TreeMap();
dataSizeMap =new TreeMap();
int i=0;
while(i> entries = dataSizeMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = entries.next();
bw1.append(entry.getKey() + " " + entry.getValue()+"\r\n");
}
Iterator> entries1 = dataMap.entrySet().iterator();
while (entries1.hasNext()) {
Map.Entry entry = entries1.next();
bw2.append( entry.getKey() + " " + entry.getValue()+"\r\n");
}
bw1.close();
bw2.close();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return dataMap;
}
public static Map sortMapByKey(Map map) {
if (map == null || map.isEmpty()) {
return null;
}
Map sortMap = new TreeMap(new Comparator(){
public int compare(Date o1, Date o2) {
// TODO Auto-generated method stub
return o1.compareTo(o2);
}
});
sortMap.putAll(map);
return sortMap;
}
public static Map sortMapByKey1(Map map) {
if (map == null || map.isEmpty()) {
return null;
}
Map sortMap = new TreeMap(new Comparator(){
public int compare(Date o1, Date o2) {
// TODO Auto-generated method stub
return o1.compareTo(o2);
}
});
sortMap.putAll(map);
return sortMap;
}
}