List<FileContent> (@NotNull final VirtualFile file, @NotNull Project project, @Nullable String prefix) { if (file.isDirectory()) { return getContentFromDirectory(file, project, prefix); } if (file.getFileType().isBinary()) { GithubNotifications .showWarning(project, GithubNotificationIdsHolder.GIST_CANNOT_CREATE, GithubBundle.message("cannot.create.gist"), GithubBundle.message("create.gist.error.binary.file", file.getName())); return Collections.emptyList(); } String content = ReadAction.compute(() -> { try { Document document = FileDocumentManager.getInstance().getDocument(file); if (document != null) { return document.getText(); } else { return new String(file.contentsToByteArray(), file.getCharset()); } } catch (IOException e) { LOG.info("Couldn't read contents of the file " + file, e); return null; } }); if (content == null) { GithubNotifications .showWarning(project, GithubNotificationIdsHolder.GIST_CANNOT_CREATE, GithubBundle.message("cannot.create.gist"), GithubBundle.message("create.gist.error.content.read", file.getName())); return Collections.emptyList(); } if (StringUtil.isEmptyOrSpaces(content)) { return Collections.emptyList(); } String filename = addPrefix(file.getName(), prefix, false); return Collections.singletonList(new FileContent(filename, content)); }