docs: public static void checkDirectory(final String dir,
        final boolean need_write, final boolean create) {
      if (dir.isEmpty())
        throw new IllegalArgumentException("Directory path is empty");
      final File f = new File(dir);
      if (!f.exists() && !(create && f.mkdirs())) {
        throw new IllegalArgumentException("No such directory [" + dir + "]");
      } else if (!f.isDirectory()) {
        throw new IllegalArgumentException("Not a directory [" + dir + "]");
      } else if (need_write && !f.canWrite()) {
        throw new IllegalArgumentException("Cannot write to directory [" + dir
            + "]");
      }
    }