001/* 002 * Copyright 2011 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.skincommons; 017 018import java.io.File; 019import java.io.IOException; 020 021import org.apache.commons.io.FileUtils; 022 023/** 024 * Thread for asynchronous file deletion 025 * 026 */ 027public class AsynchronousFileDeletion implements Runnable 028{ 029 File _file; 030 031 /** 032 * Constructor 033 * @param file The file to delete 034 */ 035 public AsynchronousFileDeletion (File file) 036 { 037 _file = file; 038 } 039 040 @Override 041 public void run() 042 { 043 if (_file != null) 044 { 045 try 046 { 047 if (_file.isDirectory()) 048 { 049 FileUtils.deleteDirectory(_file); 050 } 051 else 052 { 053 _file.delete(); 054 } 055 } 056 catch (IOException e) 057 { 058 try 059 { 060 FileUtils.forceDeleteOnExit(_file); 061 } 062 catch (IOException ioe) 063 { 064 // Nothing 065 } 066 } 067 068 } 069 070 } 071 072}