code: public static void ensureDirectoryExists(final Path path) throws IOException {
          if (Files.exists(path)) {
              if (!Files.isDirectory(path)) {
                  throw new IOException("path is not a directory: " + path);
              }
              // probably should fsync parent here just to be sure, but that might slow stuff down
          } else {
              Files.createDirectories(path);
              fsyncLineage(path.getParent());
          }
      }
docs: Create a directory if it does not already exist.  Fails if the path exists and is NOT a directory.
  Will fsync the parent directory inode.
  
  @param path path to ensure is a directory.
  @throws IOException In the event that the path is not a directory.