纳品小工具(根据文件一览从工程中取文件,包括testcase和testcase数据文件)

import java.io.BufferedInputStream;


public class testNouhinTool {

 /**
  * @param args
  */
 public static void main(String[] args) {
  
  String ORG_DIRECTORY = "F:\\testNouhiuTool";
  String ORG_PATH = "F:\\";
  String DEST_PATH = "E:\\";
  String READ_FILE = "F:\\test.txt";
  
  // Create Directory
  createDirectory(ORG_DIRECTORY, ORG_PATH, DEST_PATH);
  
  // Copy File
  copyAllFileInOrgdirectory(ORG_DIRECTORY, ORG_PATH, DEST_PATH, READ_FILE);
 }

 private static void copyAllFileInOrgdirectory(String ORG_DIRECTORY,
   String ORG_PATH, String DEST_PATH, String READ_FILE) {
  
  String testcase = "";
  String testcaseFolder = "";
  boolean fileFoundFlg = false;
  boolean testcaseFoundFlg = false;
  boolean folderFoundFlg = false;
  
  try {
   BufferedReader bf = new BufferedReader(new FileReader(READ_FILE));
   String line = bf.readLine();
   
   while(line != null) {
    
    // System.out.println(line + "  is in file");
    if (line.indexOf("\\") != -1) {
     
     line = line.substring(line.lastIndexOf("\\")+1);
    } else if (line.indexOf("/") != -1) {
     
     line = line.substring(line.lastIndexOf("/")+1);
    }
    
    if (isRule(line)) {
     
     testcase = line.substring(0, line.indexOf(".")).concat("Test.java");
     testcaseFolder = line.substring(0, line.indexOf("."));
    }
    
    File findParentPath = new File(ORG_DIRECTORY);
    Stack<File> findByStack = new Stack<File>();
    findByStack.add(findParentPath);
    
    while(!findByStack.isEmpty()){
     
     File tmpFilePath = findByStack.pop();
     File[] tmpFileNameArray = tmpFilePath.listFiles();
     
     for(File tmpFileName : tmpFileNameArray){
      
      if(tmpFileName.isDirectory()){
       
       findByStack.push(tmpFileName);
       
       if (!"".equals(testcaseFolder) && tmpFileName.getName().equals(testcaseFolder)) {
        
        // System.out.println(tmpFileName.getName() + "  is data directory");
        Stack<File> dataStack = new Stack<File>();
        dataStack.add(tmpFileName);
        
        while (!dataStack.isEmpty()) {
         
         File dataFolderPath = dataStack.pop();
         File[] dataFiles = dataFolderPath.listFiles();
         
         for (File dataFile : dataFiles) {
          
          if (dataFile.isDirectory()) {
           
           dataStack.push(dataFile);
           
          } else if (dataFile.isFile()) {
           
           copyFile(ORG_PATH, DEST_PATH, dataFile);
          }
         }
        }
        folderFoundFlg = true;
       }
       
      } else if (tmpFileName.isFile()){
       
       // find rulefile
       if(tmpFileName.getName().equals(line)){
        
        copyFile(ORG_PATH, DEST_PATH, tmpFileName);
           fileFoundFlg = true;
       }
       
       // find testcase
                            if(tmpFileName.getName().equals(testcase)){
        
        copyFile(ORG_PATH, DEST_PATH, tmpFileName);
           testcaseFoundFlg = true;
       }
      }
     }
    }
    
    if (isRule(line)) {
     
     if (!testcaseFoundFlg) {
      System.out.println(testcase + "  is not in directory");
     }
     
     if (!folderFoundFlg) {
      System.out.println(testcaseFolder + " data folder is not in directory");
     }
     
     testcase = "";
     testcaseFolder = "";
    }
    
    if (!fileFoundFlg) {
     System.out.println(line + " is not in directory");
    }
    
    fileFoundFlg = false;
    testcaseFoundFlg = false;
    folderFoundFlg = false;
    line = bf.readLine();
   }
   bf.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 private static void createDirectory(String ORG_DIRECTORY, String ORG_PATH,
   String DEST_PATH) {
  
  File path = new File(ORG_DIRECTORY);
  Stack<File> tmpStack = new Stack<File>();
  tmpStack.add(path);
  
  while(!tmpStack.isEmpty()){
   
   File tmpStackFile = tmpStack.pop();
   
   if(tmpStackFile.isDirectory()){
    
    // System.out.println(tmpFile.getAbsolutePath());
    if(!new File(tmpStackFile.getAbsolutePath().replace(ORG_PATH, DEST_PATH)).exists()){
     
     new File(tmpStackFile.getAbsolutePath().replace(ORG_PATH, DEST_PATH)).mkdirs();
    }
   }
   File[] files = tmpStackFile.listFiles();
   
   for (File tmpFile : files ) {
    if(tmpFile.isDirectory()){
     // System.out.println(files[i].getAbsolutePath());
     tmpStack.push(tmpFile);
    }
   }
  }
 }

 private static void copyFile(String ORG_PATH, String DEST_PATH,
   File tmpFileName) throws FileNotFoundException, IOException {
  
  // System.out.println(tmpFileName.getName() + "  is in directory");
  // tmpFileName.renameTo(
  //  new File(tmpFileName.getAbsolutePath().replace("F:", "E:\\testNouhiuTool")
  BufferedInputStream bin = new BufferedInputStream(
    new FileInputStream(tmpFileName));
  BufferedOutputStream bout = new BufferedOutputStream(
    new FileOutputStream(
      new File(tmpFileName.getAbsolutePath().replace(ORG_PATH, DEST_PATH))));
  int b = 0;
  
  while ((b = bin.read()) != -1) {
   bout.write(b);
  }
  
  bout.flush();
  bin.close();
  bout.close();
 }

 private static boolean isRule(String line) {
  return (line.indexOf("CHRCAL") != -1 || line.indexOf("CHRCHK") != -1 || line.indexOf("CHRSEL") != -1) &&
    line.indexOf("IF") == -1 && line.indexOf("Cib") == -1;
 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值