package com.platform.utils;

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

import org.apache.log4j.Logger;

import com.platform.controller.FilePackageController;

/** 删除文件
 * @author chen
 *
 */
public class ThreadRemoveFile extends Thread {
	
	@SuppressWarnings("static-access")
	public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FilePackageController.class);
	
	private List<String> path4Delete = new ArrayList<String>();
	
	public ThreadRemoveFile(List<String> paths) {
		this.path4Delete = paths;
	}
	
	@Override
	public void run() {
		while (true) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				log.error(e.getStackTrace());
			}
			List<String> tmpPathArr = new ArrayList<String>(); 
			if (null != path4Delete && path4Delete.size() > 0) {
				for (String path : path4Delete) {
					File f = new File(path);
					if (f.exists()) {
						if (!f.delete()) {
							tmpPathArr.add(path);
						}
					}
				}
			}
			else {
				break;
			}
			path4Delete = tmpPathArr;
		}
	}

}
