当前位置: 代码迷 >> J2SE >> 代码重构~该如何解决
  详细解决方案

代码重构~该如何解决

热度:8668   发布时间:2013-02-25 00:00:00.0
代码重构~
package com.eetrust.cpm.IPparse;





public class Directory2 { 



//private static File[] strPath2;




public static String convertingStr(String lineStr) { 
  String retVal = ""; 
  return retVal; 




 
public static void recursion(String root, Vector<String> vecFile) {  
  File file = new File(root);  
  File[] subFile = file.listFiles();  
   
   
  if (subFile.length == 0) {
System.out.println(file.getAbsolutePath() + " is null");
}else{
   
  for (int i = 0; i < subFile.length; i++) {  
  if (subFile[i].isDirectory()) {  
 
 
 
 
  recursion(subFile[i].getAbsolutePath(), vecFile);
   
   
  } else {  
 
  String filename = subFile[i].getName();
   
  vecFile.add(subFile[i].getAbsolutePath());  
  }  
  }
  }  
   
}

  
  

public String GetNowDate(){
  String temp_str="";
  Date dt = new Date();
  //最后的aa表示“上午”或“下午” HH表示24小时制 如果换成hh表示12小时制
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
  temp_str=sdf.format(dt);
  return temp_str;




/** 
  * @param args 
  * @throws IOException 
  */ 
public static void main(String[] args) throws IOException { 
 



  
Map <String,Integer> map = new HashMap<String,Integer>(); 

IPtest ipTest = new IPtest();
String path = ipTest.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

//System.out.println(path);
// if (path.indexOf("WEB-INF") > 0) {
// path = path.substring(1, path.indexOf("/WEB-INF/"));
// }
path+="/qqwry";
// 指定纯真数据库的文件名,所在文件夹
IPSeeker ip = new IPSeeker("QQWry.Dat", path);
// 测试IP 58.20.43.13
System.out.println(path);



  Vector<String> vecFile = new Vector<String>();  
  recursion("/opt/haproxy_temp_log", vecFile);  

  for (String fileName : vecFile) {  
  System.out.println(fileName);  
  Pattern pattern = Pattern.compile("\\S*\\d+\\.\\d+\\.\\d+\\.\\d+$"); 
  Matcher m2 = pattern.matcher(fileName);
  if(m2.matches()!=false){

  System.out.println("不需要处理!@");
 
  }else if(fileName.indexOf("cache.rightgo.net")!=-1){

System.out.println("不需要分析!");
}else {




BufferedReader br = new BufferedReader(new FileReader(fileName)); 

//System.out.println(i);
  
  String line = null;

  while ((line = br.readLine()) != null){
 
  Pattern p = Pattern.compile(":\\s([^:]*):");//这个匹配还是有点取巧了。
  //可以这样":\\s*(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s*:"安全一点

  Matcher m = null;

  if(!"".equals(line)){
  m = p.matcher(line);
  while(m.find()){
  相关解决方案