static boolean cleanDirectory(File dir, boolean deleteDirectory) throws IOException {
    if (!dir.exists()) {
      return true;
    }
    if (!dir.isDirectory()) {
      throw new IllegalArgumentException(dir.getAbsolutePath() + " is not a directory");
    }
    File[] files = dir.listFiles();
    if (files == null) {
      throw new IOException("Could not list files in directory: " + dir.getAbsolutePath());
    }
    boolean success = true;
    for (File file : files) {
      success = file.delete() && success;
    }
    return deleteDirectory ? dir.delete() && success : success;
  }
Cleans up the {@code dir} and deletes it.
@param dir the directory to be cleaned up and deleted.
@param deleteDirectory if {@code true}, the directory is deleted too.
@return {@code true if the delete was successful}. {@code false} otherwise
@throws IOException
ambry-store/src/test/java/com/github/ambry/store/StoreTestUtils.java