private static @NotNull OutputStream startWriteOrCreate(@NotNull Path templateFile) throws IOException {
    try {
      return Files.newOutputStream(templateFile);
    }
    catch (NoSuchFileException e) {
      // try to recover from the situation 'file exists, but is a directory'
      NioFiles.deleteRecursively(templateFile);
      return Files.newOutputStream(templateFile);
    }
  }
private static @NotNull OutputStream startWriteOrCreate(@NotNull Path templateFile)