/** * Cleans the parent directory of this storage provider. This action will * delete all previous collection storages made in this directory, and thus * it should only be invoked either before any collections has been made or * when all collections are ensured to be unused. */ public void cleanDirectory() { final File[] directories = _parentDirectory.listFiles((dir, name) -> name.startsWith(DIRECTORY_PREFIX)); for (final File directory : directories) { delete(directory); } }
/** * Recursively deletes a directory and all it's files * * @param file */ private void delete(final File file) { if (file.isDirectory()) { final File[] children = file.listFiles(); for (final File child : children) { delete(child); } } if (!file.delete()) { if (!file.isDirectory()) { logger.warn("Unable to clean/delete file: {}", file); } else { logger.debug("Unable to clean/delete directory: {}", file); } } }