private static OutputStream openOutputStream(Path file) throws IOException {
    try {
      return Files.newOutputStream(file);
    }
    catch (NoSuchFileException e) {
      Path parentDir = file.getParent();
      if (parentDir == null) {
        throw new IOException("Parent file is null for " + file, e);
      }
      Files.createDirectories(parentDir);
      return Files.newOutputStream(file);
    }
  }
private static OutputStream openOutputStream(Path file)