<commit_before>package com.debuglife.codelabs.fileIO;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * This is a tool for creating and deleting files in multiple threads, which
 * is faster than os file system generally in case there are a large amount of
 * little fileis scatterring in the diffent and many folders. when deleting them
 * in file system, generally it takes a lot of times.
 * So far, 
 * 
 * changelog
 * <----------------------------------------------------------------->
 * v0.0.1；
 *      CREATE FILE: not support recursive folder.
 *      DELETE FILE: not support recursive folder.
 * v0.1.1:
 *      CREATE FILE: not support recursive folder.
 *      DELETE FILE: support recursive folder.
 *
 *
 *
 *
 *todo
 *<------------------------------------------------------------------>
 * 1. improve it in linux command style.
 */
public class TestFastCreateAndDeleteFiles {
    // config info
    private static String suffix = ".HL7";
    private static String fileSize_1k = "D:\\test\\ADT_A01.hl7";
    private static String fileSize_2M = "D:\\test\\MDM_T02_pat_JPG.hl7";
    private static String desFilePath = "D:\\test\\medavis\\service\\gateway4med\\in\\10w\\ADT_A01_";
    private static String testFilePath = "D:\\test\\manyFiles\\";
    private static int totalNum = 100000;
    private static int numOfGroup = 4;
    
    // thread list
    private static List<Thread> threadList = new ArrayList<Thread>();

    public static void main(String[] args) throws Exception{
        //createFiles(fileSize_1k, testFilePath, suffix);
        //deleteFiles(desFilePath, suffix);
        deleteFilesRecurisively(testFilePath);
        calExecuteTime();
    }
    
    /**
     * create files in one folder.
     * @param srcFilePath
     * @param desFilePath
     * @param suffix
     */
    public static void createFiles(String srcFilePath, String desFilePath, String suffix) {
        int x[] = groupData(totalNum, numOfGroup);
        printArray(x);
        
        int temp = 0;
        for(int i=0; i<x.length; i++){
            FileCreator w = null;
            if(i != x.length-1){
                w = new FileCreator((i+1)*x[i], i*x[i], "thread-"+i);
                temp = x[i];
            } else{
                w = new FileCreator(totalNum, i*temp, "thread-"+i);
            }
            
            w.setSrcFilePath(srcFilePath);
            w.setDesFilePath(desFilePath);
            w.setSuffix(suffix);
            
            w.start();
            threadList.add(w);
        }
    }
    
    /**
     * delete files in one folder.
     * @param desFilePath
     * @param suffix
     */
    public static void deleteFiles(String desFilePath,String suffix){
        int x[] = groupData(totalNum, numOfGroup);
        for(int i=0; i<x.length; i++){
            FileDeletor w = new FileDeletor(i, x[i], "thread-"+i);
            w.setDesFilePath(desFilePath);
            w.setSuffix(suffix);
            
            w.start();
            threadList.add(w);
        }
    }
    
    /**
     * delete files in resurisive way.
     * @param filePath
     */
    public static void deleteFilesRecurisively(String filePath){
        if(filePath == null) return;
        File f = new File(filePath);
        if(!f.exists()) return;
        if(f.isFile()){
            f.delete();
        }
        if(f.isDirectory()){
            File[] files = f.listFiles();
            int x[] = groupData(files.length, numOfGroup);
            int temp=0;
            for(int k=0;k<x.length;k++){
                String[] fileStrArray = new String[x[k]];
                if(x.length > 1){
                    temp = x[x.length - 2];
                }else{
                    temp = x[k];
                }
                int m=0;
                while(m<fileStrArray.length){                    
                    for(int i=temp*(k);i<files.length;i++){<commit_msg>add some log info into the class-level comments.<commit_after>package com.debuglife.codelabs.fileIO;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * This is a tool for creating and deleting files in multiple threads, which
 * is faster than os file system generally in case there are a large amount of
 * little fileis scatterring in the diffent and many folders. when deleting them
 * in file system, generally it takes a lot of times.
 * So far, 
 * 
 * changelog
 * <----------------------------------------------------------------->
 * v0.0.1；
 *      CREATE FILE: not support recursive folder.
 *      DELETE FILE: not support recursive folder.
 * v0.1.1:
 *      CREATE FILE: not support recursive folder.
 *      DELETE FILE: support recursive folder.
 *
 *
 *
 *
 *todo
 *<------------------------------------------------------------------>
 * 1. improve it in linux command style.
 */
public class TestFastCreateAndDeleteFiles {
    // config info
    private static String suffix = ".HL7";
    private static String fileSize_1k = "D:\\test\\ADT_A01.hl7";
    private static String fileSize_2M = "D:\\test\\MDM_T02_pat_JPG.hl7";
    private static String desFilePath = "D:\\test\\medavis\\service\\gateway4med\\in\\10w\\ADT_A01_";
    private static String testFilePath = "D:\\test\\manyFiles\\";
    private static int totalNum = 100000;
    private static int numOfGroup = 4;
    
    // thread list
    private static List<Thread> threadList = new ArrayList<Thread>();

    public static void main(String[] args) throws Exception{
        //createFiles(fileSize_1k, testFilePath, suffix);
        //deleteFiles(desFilePath, suffix);
        deleteFilesRecurisively(testFilePath);
        calExecuteTime();
    }
    
    /**
     * create files in one folder.
     * @param srcFilePath
     * @param desFilePath
     * @param suffix
     */
    public static void createFiles(String srcFilePath, String desFilePath, String suffix) {
        int x[] = groupData(totalNum, numOfGroup);
        printArray(x);
        
        int temp = 0;
        for(int i=0; i<x.length; i++){
            FileCreator w = null;
            if(i != x.length-1){
                w = new FileCreator((i+1)*x[i], i*x[i], "thread-"+i);
                temp = x[i];
            } else{
                w = new FileCreator(totalNum, i*temp, "thread-"+i);
            }
            
            w.setSrcFilePath(srcFilePath);
            w.setDesFilePath(desFilePath);
            w.setSuffix(suffix);
            
            w.start();
            threadList.add(w);
        }
    }
    
    /**
     * delete files in one folder.
     * @param desFilePath
     * @param suffix
     */
    public static void deleteFiles(String desFilePath,String suffix){
        int x[] = groupData(totalNum, numOfGroup);
        for(int i=0; i<x.length; i++){
            FileDeletor w = new FileDeletor(i, x[i], "thread-"+i);
            w.setDesFilePath(desFilePath);
            w.setSuffix(suffix);
            
            w.start();
            threadList.add(w);
        }
    }
    
    /**
     * delete files in a resurisive way.
     * @param filePath
     */
    public static void deleteFilesRecurisively(String filePath){
        if(filePath == null) return;
        File f = new File(filePath);
        if(!f.exists()) return;
        if(f.isFile()){
            f.delete();
        }
        if(f.isDirectory()){
            File[] files = f.listFiles();
            int x[] = groupData(files.length, numOfGroup);
            int temp=0;
            for(int k=0;k<x.length;k++){
                String[] fileStrArray = new String[x[k]];
                if(x.length > 1){
                    temp = x[x.length - 2];
                }else{
                    temp = x[k];
                }
                int m=0;
                while(m<fileStrArray.length){                    
                    for(int i=temp*(k);i<files.length;i++){
{'fraction_non_alphanumeric': 0.14805425275700343, 'fraction_numerical': 0.009887184687539612, 'mean_word_length': 1.7048337332876242, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6350740', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2232, 'n_words': 599}