void (@NotNull Path dir, @NotNull String fileName, @NotNull Project project, @NotNull ThrowableConsumer<? super Writer, ? extends IOException> writerConsumer) { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); Path fullPath = dir.resolve(fileName); if (indicator != null) { ProgressManager.checkCanceled(); indicator.setText(InspectionsBundle.message("inspection.export.generating.html.for", fullPath.toString())); } try { Files.createDirectories(dir); } catch (IOException e) { showErrorMessage("Can't create dir", dir, project); return; } try (BufferedWriter writer = Files.newBufferedWriter(fullPath)) { writerConsumer.consume(writer); } catch (AccessDeniedException e) { showErrorMessage("Permission denied", fullPath, project); } catch (IOException e) { showErrorMessage(String.valueOf(e.getCause()), fullPath, project); } }