public static boolean delete(@Nullable File file) {
        if (file == null) {
            LOGGER.warn("cannot delete null File");
            return false;
        }

        try (Stream<Path> paths = Files.walk(file.toPath())) {
            paths.sorted(Comparator.reverseOrder())
            .map(Path::toFile)
            .forEach(File::delete);
        } catch (IOException ex) {
            LOGGER.trace(ex.getMessage(), ex);
            LOGGER.debug("Failed to delete file: {} (error message: {}); attempting to delete on exit.", file.getPath(), ex.getMessage());
            file.deleteOnExit();
            return false;
        }

        return true;
    }
@Test
    public void testDeleteWithSubDirectories() throws Exception {

        File dir = new File(getSettings().getTempDirectory(), "delete-me");
        dir.mkdirs();
        File file = File.createTempFile("tmp", "deleteme", dir);
        assertTrue("Unable to create a temporary file " + file.getAbsolutePath(), file.exists());

        // delete the file
        boolean status = FileUtils.delete(dir);
        assertTrue("delete returned a failed status", status);
        assertFalse("Temporary file exists after attempting deletion", file.exists());
    }