public static void cleanDirectory(File directory) throws IOException {
        if (!directory.exists()) {
            String message = directory + " does not exist";
            throw new IllegalArgumentException(message);
        }

        if (!directory.isDirectory()) {
            String message = directory + " is not a directory";
            throw new IllegalArgumentException(message);
        }

        File[] files = directory.listFiles();
        // null if security restricted
        if (files == null) {
            throw new IOException("Failed to list contents of " + directory);
        }

        IOException exception = null;
        for (File file : files) {
            try {
                delete(file);
            } catch (IOException ioe) {
                exception = ioe;
            }
        }

        if (null != exception) {
            throw exception;
        }
    }
@Test
    public void testCleanDirectory() throws IOException {
        File cleanDir = new File(tempDir.toFile(), "clean");
        cleanDir.mkdirs();
        File cleanFile1 = new File(cleanDir, "clean1.txt");
        File cleanFile2 = new File(cleanDir, "clean2.txt");
        Assert.assertTrue(cleanDir.exists());
        Assert.assertTrue(cleanFile1.createNewFile());
        Assert.assertTrue(cleanFile2.createNewFile());
        IoUtil.cleanDirectory(cleanDir);
        Assert.assertFalse(cleanFile1.exists());
        Assert.assertFalse(cleanFile2.exists());
    }