@Nonnull private DiffContent createBinaryImpl(@javax.annotation.Nullable Project project, @Nonnull byte[] content, @Nonnull FileType type, @Nonnull String fileName, @javax.annotation.Nullable VirtualFile highlightFile) throws IOException { // workaround - our JarFileSystem and decompilers can't process non-local files boolean useTemporalFile = type instanceof ArchiveFileType || BinaryFileTypeDecompilers.INSTANCE.forFileType(type) != null; VirtualFile file; if (useTemporalFile) { file = createTemporalFile(project, "tmp", fileName, content); } else { file = new BinaryLightVirtualFile(fileName, type, content); file.setWritable(false); } return new FileContentImpl(project, file, highlightFile); }
@Nonnull public static CharSequence loadText(@Nonnull final VirtualFile file) { FileType type = file.getFileType(); if (type.isBinary()) { final BinaryFileDecompiler decompiler = BinaryFileTypeDecompilers.INSTANCE.forFileType(type); if (decompiler != null) { CharSequence text = decompiler.decompile(file); try { StringUtil.assertValidSeparators(text); } catch (AssertionError e) { LOG.error(e); } return text; } throw new IllegalArgumentException("Attempt to load text for binary file which doesn't have a decompiler plugged in: " + file.getPresentableUrl() + ". File type: " + type.getName()); } return loadText(file, UNLIMITED); }
public static boolean isTextFile(@NotNull VirtualFile file) { if (file.isDirectory() || !file.isValid()) { return false; } final FileType ft = file.getFileType(); return !ft.isBinary() || BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
@Override public boolean accept(@NotNull Project project, @NotNull VirtualFile file) { if (file.isDirectory() || !file.isValid()) { return false; } if (SingleRootFileViewProvider.isTooLargeForContentLoading(file)) { return false; } final FileType ft = file.getFileType(); return !ft.isBinary() || BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
@NotNull public static CharSequence loadText(@NotNull VirtualFile file) { if (file instanceof LightVirtualFile) { CharSequence content = ((LightVirtualFile)file).getContent(); if (StringUtil.indexOf(content, '\r') == -1) return content; CharBuffer buffer = CharBuffer.allocate(content.length()); buffer.append(content); buffer.rewind(); return convertLineSeparators(buffer).first; } if (file.isDirectory()) { throw new AssertionError("'" + file.getPresentableUrl() + "' is directory"); } final FileType fileType = file.getFileType(); if (fileType.isBinary()) { final BinaryFileDecompiler decompiler = BinaryFileTypeDecompilers.INSTANCE.forFileType(fileType); if (decompiler != null) { CharSequence text = decompiler.decompile(file); StringUtil.assertValidSeparators(text); return text; } throw new IllegalArgumentException("Attempt to load text for binary file, that doesn't have decompiler plugged in: "+file.getPresentableUrl()); } try { byte[] bytes = file.contentsToByteArray(); return getTextByBinaryPresentation(bytes, file); } catch (IOException e) { return ArrayUtil.EMPTY_CHAR_SEQUENCE; } }
public String getContent(final String fileUrl) { final VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(fileUrl); if (fileByUrl != null) { if (fileByUrl.isDirectory()) { return null; } BinaryFileDecompiler binaryFileDecompiler = null; FileType fileType = fileByUrl.getFileType(); if (fileType.isBinary()) { binaryFileDecompiler = BinaryFileTypeDecompilers.INSTANCE.forFileType(fileType); if (binaryFileDecompiler == null) { return null; } } if (binaryFileDecompiler != null) { return binaryFileDecompiler.decompile(fileByUrl).toString(); } return ApplicationManager.getApplication().runReadAction(new Computable<String>() { public String compute() { return getFileText(getProject(), fileByUrl).toString(); } }); } return null; }
public static boolean isTextFile(@Nonnull VirtualFile file) { if (file.isDirectory() || !file.isValid()) { return false; } final FileType ft = file.getFileType(); return !ft.isBinary() || BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
private static boolean isBinaryWithDecompiler(@NotNull VirtualFile file) { final FileType ft = file.getFileType(); return ft.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
private static boolean isBinaryWithoutDecompiler(@NotNull VirtualFile file) { final FileType fileType = file.getFileType(); return fileType.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(fileType) == null; }
private static boolean isBinaryWithoutDecompiler(VirtualFile file) { final FileType ft = file.getFileType(); return ft.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) == null; }
@NotNull public static CharSequence loadText(@NotNull final VirtualFile file) { if (file instanceof LightVirtualFile) { return ((LightVirtualFile)file).getContent(); } if (file.isDirectory()) { throw new AssertionError("'" + file.getPresentableUrl() + "' is a directory"); } FileType fileType = file.getFileType(); if (fileType.isBinary()) { final BinaryFileDecompiler decompiler = BinaryFileTypeDecompilers.INSTANCE.forFileType(fileType); if (decompiler != null) { CharSequence text; Application app = ApplicationManager.getApplication(); if (app != null && app.isDispatchThread() && !app.isWriteAccessAllowed() && !GraphicsEnvironment.isHeadless()) { final Ref<CharSequence> result = Ref.create(ArrayUtil.EMPTY_CHAR_SEQUENCE); final Ref<Throwable> error = Ref.create(); ProgressManager.getInstance().run(new Task.Modal(null, "Decompiling " + file.getName(), true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); try { result.set(ApplicationUtil.runWithCheckCanceled(new Callable<CharSequence>() { @Override public CharSequence call() { return decompiler.decompile(file); } }, indicator)); } catch (Throwable t) { error.set(t); } } }); ExceptionUtil.rethrowUnchecked(error.get()); text = result.get(); } else { text = decompiler.decompile(file); } StringUtil.assertValidSeparators(text); return text; } throw new IllegalArgumentException("Attempt to load text for binary file which doesn't have a decompiler plugged in: " + file.getPresentableUrl() + ". File type: " + fileType.getName()); } try { byte[] bytes = file.contentsToByteArray(); return getTextByBinaryPresentation(bytes, file); } catch (IOException e) { return ArrayUtil.EMPTY_CHAR_SEQUENCE; } }
private static boolean isBinaryWithDecompiler(VirtualFile file) { final FileType ft = file.getFileType(); return ft.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
private boolean isBinaryWithoutDecompiler(VirtualFile file) { final FileType ft = file.getFileType(); return ft.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) == null; }
private static boolean isBinaryWithDecompiler(@Nonnull VirtualFile file) { final FileType ft = file.getFileType(); return ft.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(ft) != null; }
private static boolean isBinaryWithoutDecompiler(@Nonnull VirtualFile file) { final FileType fileType = file.getFileType(); return fileType.isBinary() && BinaryFileTypeDecompilers.INSTANCE.forFileType(fileType) == null; }