/** * Deletes all files and directories in the specified directory. Nothing * happens when the specified File is not a directory. * * @return true when all children were successfully deleted, when there were * no children or when the file was not a directory. */ public static boolean deleteChildren(File directory) { boolean result = true; if (directory.isDirectory()) { File[] list = directory.listFiles(); for (int i = list.length; i-- > 0;) { result = result && deltree(list[i]); } } return result; }
/** * Deletes the given file and everything under it. * * @return Whether all files were deleted succesfully. */ public static boolean deltree(File directory) { if (directory == null || !directory.exists()) { return true; } boolean result = true; if (directory.isFile()) { result = directory.delete(); } else { File[] list = directory.listFiles(); for (int i = list.length; i-- > 0;) { if (!deltree(list[i])) { result = false; } } if (!directory.delete()) { result = false; } } return result; }
@Override protected void finalize() throws Throwable { if (disk == this) { try { if (connection != null) { connection.commit(); connection.close(); } repository.shutDown(); } catch (RepositoryException e) { logger.error(e.toString(), e); } finally { FileUtil.deltree(repository.getDataDir()); repository = null; connection = null; disk = null; } } super.finalize(); } };