在本文中,我们将带你了解linuxgnome虚拟文件系统gvfs和gnome-vfs简介在这篇文章中,我们将为您详细介绍linuxgnome虚拟文件系统gvfs和gnome-vfs简介的方方面面,并解
在本文中,我们将带你了解linux gnome虚拟文件系统 gvfs和gnome-vfs 简介在这篇文章中,我们将为您详细介绍linux gnome虚拟文件系统 gvfs和gnome-vfs 简介的方方面面,并解答linux的虚拟文件系统常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的Apache commons VFS 无法解析带有字符串 URI、Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block、com.intellij.openapi.vfs.encoding.EncodingRegistry的实例源码、com.intellij.openapi.vfs.impl.http.HttpVirtualFile的实例源码。
本文目录一览:- linux gnome虚拟文件系统 gvfs和gnome-vfs 简介(linux的虚拟文件系统)
- Apache commons VFS 无法解析带有字符串 URI
- Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block
- com.intellij.openapi.vfs.encoding.EncodingRegistry的实例源码
- com.intellij.openapi.vfs.impl.http.HttpVirtualFile的实例源码
linux gnome虚拟文件系统 gvfs和gnome-vfs 简介(linux的虚拟文件系统)
gvfs是gnome从2.22版本开始引入的高级特性,用于将各种存档文件(tar、gz、zip、iso等)和各种本地及网络协议(burn、cdda、ftp、http、webdav等)挂载为虚拟文件系统。
存档文件挂载之后会出现在系统的“位置”菜单和nautilus资源管理器的位置栏里,但还不是文件系统的一部分,因此只有支持gio的应用程序才能访问(类似于kde下的kio)。要让挂载的存档文件真正成为文件系统的一部分,以至于任何应用程序都能像访问普通文件一样访问存档里的文件,你需要确保你的系统中已经安装了gvfs-fuse这个软件包(ubuntu 8.04和8.10是默认安装的)。如果是这样,那么恭喜你,看一看你的家目录下的.gvfs隐藏目录,挂载的存档文件已经作为一个目录放在里面了,任何应用程序都可以在这里访问存档里的文件了,唯一的缺憾是不可写。
对本地及网络协议的处理方法是类似的。以ftp访问为例,只要你是在nautilus资源管理器的地址栏输入
ftp://ftp站点域名
或者用系统主菜单中的“连接到服务器”功能来访问的,那么该ftp连接已经自动被挂载到系统的“位置”菜单和nautilus资源管理器的位置栏里了,支持gio的应用程序可以访问。如果你的系统中有gvfs-fuse的话,那么~/.gvfs下面也会出现对应于该ftp连接的一个目录,任何应用程序都能像访问本地文件一样在这里访问ftp站点上的文件。
gnome-vfs和gio/gfvs是两个不同的概念,也许在不久的将来gnome-vfs应该会被gvfs所取代
gfvs是gnome新一种虚拟文件系统。gfvs是用来代替过时的gnome-vfs虚拟文件系统。gvfs算是gnome 2.22中一个比较大的改动,也gnome 2.22中一个主要的新特性。
gvfs是一个带有诸如 sftp,ftp,dav,smb,obexftp 等协议后台的用户空间虚拟文件系统。gvfs是 gnome-vfs 的替代品。gnome-vfs 将不再被赞成使用,开发者也不应在新的应用程序中继续使用。
gvfs 包含两个部分:
* gio,作为 gLib的一部分的新共享库,提供了 针对 gvfs的 api;同时
* gvfs本身,是一个包含多种文件系统和协议(如sftp,smb 和 obexftp)支持的后台软件包。
gvfs/gio致力于提供一个现代的,易用的 vfs系统。它的目标是提供一些列 api给开发者,以是他们不再使用原始的 posix io访问。它提供了一个更高级的以文件为中心的接口,而不仅仅是 posix io 的复制品。除了文件的读写支持外,gio还提供了文件监视工具,异步 io,和文件名完成功能。
gvfs通过运行一个单独的主守护进程 (gvfsd) 来工作,它保证了对当前的 gvfs挂载的跟踪。每一个挂在都有独立的守护进程。(一些挂载也会同时共享一个进程,但多数情况下不会这样。) 客户端通过一个联合 D-Bus 会话来与这些挂载通信(在会话总线上,但是使用点对点 D-Bus),同时用一个用户协议来进操作文件内容。通过进程进行后台传递大大简化了程序的依赖关系,使整个系统更加健壮。
gvfs也提供了在 ~/.gvfs/ 提供了一个 fuse挂在点,这样可以使得 gvfs 挂载可以被传统的使用标准 posix io 的应用程序使用。
不同于gnome-vfs,gvfs中的连接是有状态的。这意味着用户仅仅需要输入一次密码,而不是每次成功的连接都需要一次次地重复输入。
因为转为使用 gvfs,自动挂载和自动运行现在已经直接由 nautilus 完成而不再使用 gnome-volume-manager。
为什么现在的发行版中同时包括 gnome-vfs和gvfs?
因为,目前很多程序使用的仍然是 gnome-vfs。
Apache commons VFS 无法解析带有字符串 URI
如何解决Apache commons VFS 无法解析带有字符串 URI?
我正在尝试使用 Apache Commons VFS v2.6.0 通过 Spring Boot Web 应用程序访问和读取文件。 Web 应用程序在托管的 docker 容器中运行,并且通过定位 /mnt
在同一个 docker 中安装了一个单独的 AWS 存储。当我尝试使用以下代码访问 /mnt
(例如:/mnt/abc/def/ghi.csv
)中的文件/文件夹时,
fileSystemManager = VFS.getManager();
fileSystemManager.resolveFile("/mnt/abc/def/ghi.csv")
它抛出以下异常。
Could not find file with URI "/mnt/abc/def/ghi.csv because it is a relative path,and no base URI was provided.
我已确保 Jsch jar 文件在类路径 (Jsch v0.1.54) 中也可用。这里奇怪的是我可以在同一位置使用 Java File IO 读取/写入文件而没有任何问题。
因为它说未提供基本 URI,所以我尝试通过以 Java File IO 格式提供基本文件,然后它能够解析文件对象。
fileSystemManager.resolveFile(new File("/mnt/abc/def"),"ghi.csv")
一旦第一次调用传递了基本文件,之后它就会完美地工作。
我正在使用 VFS 来解析 file:
和 sftp:
方案中的文件
有什么想法可以更好地解决问题吗?如果我们可以在 fileSystemManager
第一次初始化时设置一个基本文件,然后仅通过给出字符串路径来解析文件,那将是理想的。
解决方法
经过多次尝试,我自己找到了这个问题,并想在这里提及它,这样可能对某人有所帮助。
简短回答:删除任何出现的 ggplot(df,aes(Age,Frequency)) +
geom_col() +
theme_classic()
详细解答:这就是我在代码中处理 FileSystemManager
的方式。
我总是使用 fileSystemManager.close()
来获取 FileSystemManager 实例,而我自己没有在其他任何地方创建自定义 FileSystemManager。
VFS.getManager()
在一个地方,为了释放资源,我关闭了通过 if (fileSystemManager == null) {
fileSystemManager = VFS.getManager();
}
从上述方法获得的 FileSystemManager
单例。但是在另一个完全独立于第一个方法的方法中,它使用并关闭了 fileSystemManager 实例,再次尝试使用相同的 fileSystemManager。
因此,一旦 fileSystemManager 关闭,fileSystemManager 内部的大多数组件(如提供程序、fileCache 等)都设置为 null,但 fileSystemManager 单例仍然不为 null。因此程序将跳过 If 条件并尝试使用没有组件的 fileSystemManager 解析 filePath。
即使在 documentation 中也清楚地说明了这一点,并在我发现问题后注意到。
关闭给定的文件系统。
如果你使用 VFS 作为单例,调用这个方法是非常危险的。
删除 fileSystemManager.close()
后,问题解决。
Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block
内核升级的时候导致ftp连接慢 在不知情的情况下,被同事重启后 内核混乱了
重启后 按ESC 选择旧版的内核就可以了
所以重启也不是随便操作的
http://www.th7.cn/system/lin/201309/44174.shtml
com.intellij.openapi.vfs.encoding.EncodingRegistry的实例源码
public VirtualFile copy(final Object requestor,@NotNull final VirtualFile newParent,@NotNull final String copyName) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.copy.error",newParent.getPresentableurl())); } if (!newParent.isDirectory()) { throw new IOException(VfsBundle.message("file.copy.target.must.be.directory")); } return EncodingRegistry.doActionAndRestoreEncoding(this,new ThrowableComputable<VirtualFile,IOException>() { @Override public VirtualFile compute() throws IOException { return getFileSystem().copyFile(requestor,VirtualFile.this,newParent,copyName); } }); }
@Override public VirtualFile copy(final Object requestor,IOException>() { @Override public VirtualFile compute() throws IOException { return ourPersistence.copyFile(requestor,VirtualFileSystemEntry.this,copyName); } }); }
public static void setApplication(@NotNull Application instance,@NotNull Getter<FileTypeRegistry> fileTypeRegistryGetter,@NotNull Getter<EncodingRegistry> encodingRegistryGetter,@NotNull disposable parent) { final Application old = ourApplication; final Getter<FileTypeRegistry> oldFileTypeRegistry = FileTypeRegistry.ourInstanceGetter; final Getter<EncodingRegistry> oldEncodingRegistry = EncodingRegistry.ourInstanceGetter; disposer.register(parent,new disposable() { @Override public void dispose() { if (old != null) { // to prevent NPEs in threads still running setApplication(old); //noinspection AssignmentToStaticFieldFromInstanceMethod FileTypeRegistry.ourInstanceGetter = oldFileTypeRegistry; //noinspection AssignmentToStaticFieldFromInstanceMethod EncodingRegistry.ourInstanceGetter = oldEncodingRegistry; } } }); setApplication(instance); FileTypeRegistry.ourInstanceGetter = fileTypeRegistryGetter; EncodingRegistry.ourInstanceGetter = encodingRegistryGetter; }
public VirtualFile copy(final Object requestor,copyName); } }); }
public void initApplication() { //if (ApplicationManager.getApplication() instanceof MockApplicationEx) return; final MockApplicationEx instance = new MockApplicationEx(getTestRootdisposable()); ApplicationManager.setApplication(instance,new Getter<FileTypeRegistry>() { @Override public FileTypeRegistry get() { return FileTypeManager.getInstance(); } },new Getter<EncodingRegistry>() { @Override public EncodingRegistry get() { return EncodingManager.getInstance(); } },getTestRootdisposable()); getApplication().registerService(EncodingManager.class,EncodingManagerImpl.class); }
@Override public VirtualFile copy(final Object requestor,copyName); } }); }
@Nullable public String getContent() throws VcsException { if (myContents == null) { BufferExposingByteArrayOutputStream bos = new BufferExposingByteArrayOutputStream(2048); try { myRepository.getFile(myPath,-1,null,bos); myRepository.closeSession(); } catch (SVNException e) { throw new VcsException(e); } final byte[] bytes = bos.toByteArray(); final Charset charset = myFilePath.getCharset(); myContents = charset == null ? CharsetToolkit.bytesToString(bytes,EncodingRegistry.getInstance().getDefaultCharset()) : CharsetToolkit.bytesToString(bytes,charset); } return myContents; }
public VirtualFile copy(final Object requestor,@Nonnull final VirtualFile newParent,@Nonnull final String copyName) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.copy.error",copyName); } }); }
@Override public void move(final Object requestor,@NotNull final VirtualFile newParent) throws IOException { if (!exists()) { throw new IOException("File to move does not exist: " + getPath()); } if (!newParent.exists()) { throw new IOException("Destination folder does not exist: " + newParent.getPath()); } if (!newParent.isDirectory()) { throw new IOException("Destination is not a folder: " + newParent.getPath()); } final VirtualFile child = newParent.findChild(getName()); if (child != null) { throw new IOException("Destination already exists: " + newParent.getPath() + "/" + getName()); } EncodingRegistry.doActionAndRestoreEncoding(this,IOException>() { @Override public VirtualFile compute() throws IOException { getFileSystem().moveFile(requestor,NewVirtualFile.this,newParent); return NewVirtualFile.this; } }); }
public String stringFromBytes(@NotNull byte[] bytes,@NotNull String path) { try { VirtualFile file = findVirtualFile(path); if (file == null) { return CharsetToolkit.bytesToString(bytes,EncodingRegistry.getInstance().getDefaultCharset()); } return new String(bytes,file.getCharset().name()); } catch (UnsupportedEncodingException e1) { return new String(bytes); } }
/** * Moves this file to another directory. This method should be only called within write-action. * See {@link Application#runWriteAction}. * * @param requestor any object to control who called this method. Note that * it is considered to be an external change if <code>requestor</code> is <code>null</code>. * See {@link VirtualFileEvent#getRequestor} * @param newParent the directory to move this file to * @throws IOException if file Failed to be moved */ public void move(final Object requestor,@NotNull final VirtualFile newParent) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.move.error",newParent.getPresentableurl())); } EncodingRegistry.doActionAndRestoreEncoding(this,newParent); return VirtualFile.this; } }); }
/** * @return Retrieve the charset file has been loaded with (if loaded) and would be saved with (if would). */ @NotNull public Charset getCharset() { Charset charset = getStoredCharset(); if (charset == null) { charset = EncodingRegistry.getInstance().getDefaultCharset(); setCharset(charset); } return charset; }
@Override public void move(final Object requestor,IOException>() { @Override public VirtualFile compute() throws IOException { ourPersistence.moveFile(requestor,newParent); return VirtualFileSystemEntry.this; } }); }
@NotNull public static Charset detectCharset(@NotNull VirtualFile virtualFile,@NotNull byte[] content,@NotNull FileType fileType) { Charset charset = null; Trinity<Charset,CharsetToolkit.GuessedEncoding,byte[]> guessed = guessFromContent(virtualFile,content,content.length); if (guessed != null && guessed.first != null) { charset = guessed.first; } else { String charsetName = fileType.getCharset(virtualFile,content); if (charsetName == null) { Charset specifiedExplicitly = EncodingRegistry.getInstance().getEncoding(virtualFile,true); if (specifiedExplicitly != null) { charset = specifiedExplicitly; } } else { charset = CharsetToolkit.forName(charsetName); } } if (charset == null) { charset = EncodingRegistry.getInstance().getDefaultCharset(); } if (fileType.getName().equals("Properties") && EncodingRegistry.getInstance().isNative2Ascii(virtualFile)) { charset = Native2AsciiCharset.wrap(charset); } virtualFile.setCharset(charset); return charset; }
private static String bytesToString(FilePath path,@NotNull byte[] bytes) { Charset charset = null; if (path.getVirtualFile() != null) { charset = path.getVirtualFile().getCharset(); } if (charset != null) { int bomLength = CharsetToolkit.getBOMLength(bytes,charset); final CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(bytes,bomLength,bytes.length - bomLength)); return charBuffer.toString(); } return CharsetToolkit.bytesToString(bytes,EncodingRegistry.getInstance().getDefaultCharset()); }
@Override public String getCharset(@NotNull VirtualFile file,@NotNull final byte[] content) { Charset charset = EncodingRegistry.getInstance().getDefaultCharsetForPropertiesFiles(file); if (charset == null) { charset = CharsetToolkit.getDefaultSystemCharset(); } return charset.name(); }
@Nullable @Override public String getCharset(@NotNull VirtualFile virtualFile,@NotNull byte[] bytes) { Charset charset = EncodingRegistry.getInstance().getDefaultCharsetForPropertiesFiles(virtualFile); if (charset == null) { charset = CharsetToolkit.getDefaultSystemCharset(); } return charset.name(); }
@Override public void move(final Object requestor,newParent); return NewVirtualFile.this; } }); }
@SuppressWarnings({"EmptyCatchBlock"}) @Nullable public Document getDocument() { if (myDocument == null) { if (isBinary()) return null; String text = null; try { if (myCharset == null) { text = CharsetToolkit.bytesToString(myBytes,EncodingRegistry.getInstance().getDefaultCharset()); } else { text = CharsetToolkit.bytesToString(myBytes,myCharset); } } catch (IllegalCharsetNameException e) { } // Still NULL? only if not supported or an exception was thrown. // Decode a string using the truly default encoding. if (text == null) text = new String(myBytes); text = Linetokenizer.correctLineseparators(text); myDocument = EditorFactory.getInstance().createDocument(text); myDocument.setReadOnly(true); } return myDocument; }
public String stringFromBytes(@NotNull byte[] bytes,file.getCharset().name()); } catch (UnsupportedEncodingException e1) { return new String(bytes); } }
/** * Moves this file to another directory. This method should be only called within write-action. * See {@link com.intellij.openapi.application.Application#runWriteAction}. * * @param requestor any object to control who called this method. Note that * it is considered to be an external change if <code>requestor</code> is <code>null</code>. * See {@link VirtualFileEvent#getRequestor} * @param newParent the directory to move this file to * @throws IOException if file Failed to be moved */ public void move(final Object requestor,newParent); return VirtualFile.this; } }); }
/** * @return Retrieve the charset file has been loaded with (if loaded) and would be saved with (if would). */ public Charset getCharset() { Charset charset = getStoredCharset(); if (charset == null) { charset = EncodingRegistry.getInstance().getDefaultCharset(); setCharset(charset); } return charset; }
@Override public void move(final Object requestor,newParent); return VirtualFileSystemEntry.this; } }); }
private static Charset detectCharset(@NotNull VirtualFile virtualFile,@NotNull byte[] content) { Charset charset = null; Trinity<Charset,content.length); if (guessed != null && guessed.first != null) { charset = guessed.first; } else { FileType fileType = virtualFile.getFileType(); String charsetName = fileType.getCharset(virtualFile,true); if (specifiedExplicitly != null) { charset = specifiedExplicitly; } } else { charset = CharsetToolkit.forName(charsetName); } } charset = charset == null ? EncodingRegistry.getInstance().getDefaultCharset() : charset; if (EncodingRegistry.getInstance().isNative2Ascii(virtualFile)) { charset = Native2AsciiCharset.wrap(charset); } virtualFile.setCharset(charset); return charset; }
@Nullable("null means no luck,otherwise it's tuple(guessed encoding,hint about content if was unable to guess,BOM)") public static Trinity<Charset,byte[]> guessFromContent(@NotNull VirtualFile virtualFile,int length) { EncodingRegistry settings = EncodingRegistry.getInstance(); boolean shouldGuess = settings != null && settings.isUseUTFGuessing(virtualFile); CharsetToolkit toolkit = shouldGuess ? new CharsetToolkit(content,EncodingRegistry.getInstance().getDefaultCharset()) : null; String detectedFromBytes = null; try { if (shouldGuess) { toolkit.setEnforce8Bit(true); Charset charset = toolkit.guessFromBOM(); if (charset != null) { detectedFromBytes = AUTO_DETECTED_FROM_BOM; byte[] bom = CharsetToolkit.getMandatoryBom(charset); if (bom == null) bom = CharsetToolkit.UTF8_BOM; return Trinity.create(charset,bom); } CharsetToolkit.GuessedEncoding guessed = toolkit.guessFromContent(length); if (guessed == CharsetToolkit.GuessedEncoding.VALID_UTF8) { detectedFromBytes = "auto-detected from bytes"; return Trinity.create(CharsetToolkit.UTF8_CHARSET,guessed,null); //UTF detected,ignore all directives } return Trinity.create(null,null); } return null; } finally { setCharsetWasDetectedFromBytes(virtualFile,detectedFromBytes); } }
private static String bytesToString(FilePath path,EncodingRegistry.getInstance().getDefaultCharset()); }
private void loadFrom(@NotNull VirtualFile file) { try { final String text = CharsetToolkit.bytesToString(file.contentsToByteArray(),EncodingRegistry.getInstance().getDefaultCharset()); fillDocument(text); myChanged = false; } catch (IOException e) { Messages.showErrorDialog(e.getMessage(),"Cannot load file"); } }
@Nullable public String getContent() throws VcsException { if (myContent == null) { byte[] content = loadContent(); if (content != null) { final Charset charset = myLocalFile.getCharset(); myContent = charset == null ? CharsetToolkit.bytesToString(content,EncodingRegistry.getInstance().getDefaultCharset()) : CharsetToolkit.bytesToString(content,charset); } } return myContent; }
@Override public void move(final Object requestor,@Nonnull final VirtualFile newParent) throws IOException { if (!exists()) { throw new IOException("File to move does not exist: " + getPath()); } if (!newParent.exists()) { throw new IOException("Destination folder does not exist: " + newParent.getPath()); } if (!newParent.isDirectory()) { throw new IOException("Destination is not a folder: " + newParent.getPath()); } final VirtualFile child = newParent.findChild(getName()); if (child != null) { throw new IOException("Destination already exists: " + newParent.getPath() + "/" + getName()); } EncodingRegistry.doActionAndRestoreEncoding(this,newParent); return NewVirtualFile.this; } }); }
public String stringFromBytes(@Nonnull byte[] bytes,@Nonnull String path) { try { VirtualFile file = findVirtualFile(path); if (file == null) { return CharsetToolkit.bytesToString(bytes,file.getCharset().name()); } catch (UnsupportedEncodingException e1) { return new String(bytes); } }
/** * Moves this file to another directory. This method should be only called within write-action. * See {@link Application#runWriteAction}. * * @param requestor any object to control who called this method. Note that * it is considered to be an external change if <code>requestor</code> is <code>null</code>. * See {@link VirtualFileEvent#getRequestor} * @param newParent the directory to move this file to * @throws IOException if file Failed to be moved */ public void move(final Object requestor,@Nonnull final VirtualFile newParent) throws IOException { if (getFileSystem() != newParent.getFileSystem()) { throw new IOException(VfsBundle.message("file.move.error",newParent); return VirtualFile.this; } }); }
/** * @return Retrieve the charset file has been loaded with (if loaded) and would be saved with (if would). */ @Nonnull public Charset getCharset() { Charset charset = getStoredCharset(); if (charset == null) { charset = EncodingRegistry.getInstance().getDefaultCharset(); setCharset(charset); } return charset; }
@Override public VirtualFile copy(final Object requestor,() -> ourPersistence.copyFile(requestor,this,copyName)); }
@Override public void move(final Object requestor,() -> { ourPersistence.moveFile(requestor,newParent); return this; }); }
@Nonnull private static Charset detectCharset(@Nonnull VirtualFile virtualFile,@Nonnull byte[] content,@Nonnull FileType fileType) { Charset charset = null; String charsetName = fileType.getCharset(virtualFile,content); if (charsetName != null) { charset = CharsetToolkit.forName(charsetName); } else { Trinity<Charset,content.length); Charset hardCodedCharset = guessed == null ? null : guessed.first; if (hardCodedCharset == null) { Charset specifiedExplicitly = EncodingRegistry.getInstance().getEncoding(virtualFile,true); if (specifiedExplicitly != null) { charset = specifiedExplicitly; } } else { charset = hardCodedCharset; } } if (charset == null) { charset = EncodingRegistry.getInstance().getDefaultCharset(); } virtualFile.setCharset(charset); return charset; }
private static String bytesToString(FilePath path,@Nonnull byte[] bytes) { Charset charset = null; if (path.getVirtualFile() != null) { charset = path.getVirtualFile().getCharset(); } if (charset != null) { int bomLength = CharsetToolkit.getBOMLength(bytes,EncodingRegistry.getInstance().getDefaultCharset()); }
private void loadFrom(@Nonnull VirtualFile file) { try { final String text = CharsetToolkit.bytesToString(file.contentsToByteArray(),"Cannot load file"); } }
/** * @param elementTocopy PsiFile or PsiDirectory * @param newName can be not null only if elements.length == 1 * @param choice a horrible way to pass/keep user preference * @return first copied PsiFile (recursively); null if no PsiFiles copied */ @Nullable public static PsiFile copyToDirectory(@NotNull PsiFileSystemItem elementTocopy,@Nullable String newName,@NotNull PsiDirectory targetDirectory,@Nullable int[] choice) throws IncorrectOperationException,IOException { if (elementTocopy instanceof PsiFile) { PsiFile file = (PsiFile)elementTocopy; String name = newName == null ? file.getName() : newName; if (checkFileExist(targetDirectory,choice,file,name,"copy")) return null; return targetDirectory.copyFileFrom(name,file); } else if (elementTocopy instanceof PsiDirectory) { PsiDirectory directory = (PsiDirectory)elementTocopy; if (directory.equals(targetDirectory)) { return null; } if (newName == null) newName = directory.getName(); final PsiDirectory existing = targetDirectory.findsubdirectory(newName); final PsiDirectory subdirectory = existing == null ? targetDirectory.createsubdirectory(newName) : existing; EncodingRegistry.doActionAndRestoreEncoding(directory.getVirtualFile(),IOException>() { @Override public VirtualFile compute() { return subdirectory.getVirtualFile(); } }); PsiFile firstFile = null; PsiElement[] children = directory.getChildren(); for (PsiElement child : children) { PsiFileSystemItem item = (PsiFileSystemItem)child; PsiFile f = copyToDirectory(item,item.getName(),subdirectory,choice); if (firstFile == null) { firstFile = f; } } return firstFile; } else { throw new IllegalArgumentException("unexpected elementTocopy: " + elementTocopy); } }
@Nullable public static Element read(byte[] bytes,@Nullable ErrorHandler handler) { return doRead(CharsetToolkit.bytesToString(bytes,EncodingRegistry.getInstance().getDefaultCharset()),handler); }
public CoreApplicationEnvironment(disposable parentdisposable) { myParentdisposable = parentdisposable; Extensions.cleanRootArea(myParentdisposable); myFileTypeRegistry = new CoreFileTypeRegistry(); myEncodingRegistry = new CoreEncodingRegistry(); myApplication = createApplication(myParentdisposable); ApplicationManager.setApplication(myApplication,new StaticGetter<FileTypeRegistry>(myFileTypeRegistry),new StaticGetter<EncodingRegistry>(myEncodingRegistry),myParentdisposable); myLocalFileSystem = createLocalFileSystem(); myJarFileSystem = createJarFileSystem(); Extensions.registerareaClass(ExtensionAreas.IDEA_PROJECT,null); final Mutablepicocontainer appContainer = myApplication.getpicocontainer(); registerComponentInstance(appContainer,FileDocumentManager.class,new MockFileDocumentManagerImpl(new Function<CharSequence,Document>() { @Override public Document fun(CharSequence charSequence) { return new DocumentImpl(charSequence); } },null)); VirtualFileSystem[] fs = {myLocalFileSystem,myJarFileSystem}; VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(fs,new MessageBusImpl(myApplication,null)); registerComponentInstance(appContainer,VirtualFileManager.class,virtualFileManager); registerapplicationservice(VirtualFilePointerManager.class,createVirtualFilePointerManager()); myApplication.registerService(DefaultASTFactory.class,new CoreASTFactory()); myApplication.registerService(PsiBuilderFactory.class,new PsiBuilderFactoryImpl()); myApplication.registerService(ReferenceProvidersRegistry.class,new MockReferenceProvidersRegistry()); myApplication.registerService(StubTreeLoader.class,new CoreStubTreeLoader()); myApplication.registerService(PsiReferenceService.class,new PsiReferenceServiceImpl()); myApplication.registerService(MetaDataRegistrar.class,new MetaRegistry()); registerapplicationExtensionPoint(ContentBasedFileSubstitutor.EP_NAME,ContentBasedFileSubstitutor.class); registerExtensionPoint(Extensions.getRootArea(),BinaryFileStubBuilders.EP_NAME,FileTypeExtensionPoint.class); registerExtensionPoint(Extensions.getRootArea(),FileContextProvider.EP_NAME,FileContextProvider.class); registerapplicationExtensionPoint(MetaDataContributor.EP_NAME,MetaDataContributor.class); ProgressIndicatorProvider.ourInstance = createProgressIndicatorProvider(); myApplication.registerService(JobLauncher.class,createJobLauncher()); }
com.intellij.openapi.vfs.impl.http.HttpVirtualFile的实例源码
public HttpFileEditor(@NotNull Project project,@NotNull HttpVirtualFile virtualFile) { super(project); myPanel = new RemoteFilePanel(project,virtualFile,this); RemoteFileInfo fileInfo = virtualFile.getFileInfo(); assert fileInfo != null; fileInfo.download() .done(new Consumer<VirtualFile>() { @Override public void consume(VirtualFile file) { ApplicationManager.getApplication().invokelater(new Runnable() { @Override public void run() { contentLoaded(); } },myProject.getdisposed()); } }) .rejected(new Consumer<Throwable>() { @Override public void consume(Throwable throwable) { contentRejected(); } }); }
@Override public boolean canSelect(SelectInContext context) { Object selectorInFile = context.getSelectorInFile(); OpenInbrowserRequest request = selectorInFile instanceof PsiElement ? OpenInbrowserRequest.create((PsiElement) selectorInFile) : null; if(request == null) { return false; } WebbrowserUrlProvider urlProvider = WebbrowserServiceImpl.getProvider(request); if(urlProvider == null) { VirtualFile virtualFile = request.getVirtualFile(); return virtualFile instanceof HttpVirtualFile || (HtmlUtil.isHtmlFile(request.getFile()) && !(virtualFile instanceof LightVirtualFile)); } return true; }
@Override public boolean canHandleElement(@NotNull OpenInbrowserRequest request) { if (request.getVirtualFile() instanceof HttpVirtualFile) { return true; } // we must use base language because we serve file - not part of file,but the whole file // handlebars,for example,contains HTML and HBS psi trees,so,regardless of context,we should not handle such file FileViewProvider viewProvider = request.getFile().getViewProvider(); return viewProvider.isPhysical() && !(request.getVirtualFile() instanceof LightVirtualFile) && isMyLanguage(viewProvider.getBaseLanguage()); }
@Nullable @Override protected Url getUrl(@NotNull OpenInbrowserRequest request,@NotNull VirtualFile file) throws browserException { if (file instanceof HttpVirtualFile) { return Urls.newFromVirtualFile(file); } else { return ContainerUtil.getFirstItem(getUrls(file,request.getProject(),null)); } }
public static boolean mayShowToolbar(@Nullable final Document document) { if (document == null) { return false; } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); return file != null && file.isValid() && (file.isInLocalFileSystem() || file instanceof HttpVirtualFile); }
/** * do not call this method from plugins,use {@link com.intellij.xdebugger.XDebuggerUtil#createPosition(com.intellij.openapi.vfs.VirtualFile,int)} instead */ @Nullable public static XSourcePositionImpl create(@Nullable VirtualFile file,int line) { if (file == null) { return null; } Accesstoken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { int offset; if (file instanceof LightVirtualFile || file instanceof HttpVirtualFile) { offset = -1; } else { Document document = file.isValid() ? FileDocumentManager.getInstance().getDocument(file) : null; if (document == null) { return null; } if (line < 0) { line = 0; } offset = line < document.getLineCount() ? document.getLinestartOffset(line) : -1; } return new XSourcePositionImpl(file,line,offset); } finally { lock.finish(); } }
@Nullable @Override public PsiFileSystemItem resolveFileReference(@NotNull FileReference reference,@NotNull String name) { VirtualFile file = getVirtualFile(); if (!(file instanceof HttpVirtualFile)) { return null; } VirtualFile parent = file; if (!parent.isDirectory()) { parent = parent.getParent(); if (parent == null) { parent = file; } } VirtualFile childFile = parent.findChild(name); HttpFileSystem fileSystem = (HttpFileSystem)parent.getFileSystem(); if (childFile == null) { childFile = fileSystem.createChild(parent,name,!reference.isLast()); } if (childFile.isDirectory()) { // pre create children VirtualFile childParent = childFile; FileReference[] references = reference.getFileReferenceSet().getAllReferences(); for (int i = reference.getIndex() + 1,n = references.length; i < n; i++) { FileReference childReference = references[i]; childParent = fileSystem.createChild(childParent,childReference.decode(childReference.getText()),i != (n - 1)); } return getManager().findDirectory(childFile); } else { return getManager().findFile(childFile); } }
private static boolean isSuitable(@NotNull Project project,@NotNull VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); return provider != null && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; }
@Override public boolean canSelect(SelectInContext context) { Object selectorInFile = context.getSelectorInFile(); OpenInbrowserRequest request = selectorInFile instanceof PsiElement ? OpenInbrowserRequest.create((PsiElement)selectorInFile) : null; if (request == null) { return false; } WebbrowserUrlProvider urlProvider = WebbrowserServiceImpl.getProvider(request); if (urlProvider == null) { VirtualFile virtualFile = request.getVirtualFile(); return virtualFile instanceof HttpVirtualFile || (HtmlUtil.isHtmlFile(request.getFile()) && !(virtualFile instanceof LightVirtualFile)); } return true; }
public static boolean mayShowToolbar(@Nullable final Document document) { if (document == null) { return false; } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); return file != null && file.isValid() && (file.getFileSystem() == LocalFileSystem.getInstance() || file instanceof HttpVirtualFile); }
private static boolean isSuitable(final Project project,final VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(file); return provider != null && BreadcrumbsXmlWrapper.findInfoProvider(provider) != null; }
@Override @Nullable public Url getUrlToOpen(@NotNull PsiElement psiElement,boolean preferLocalUrl) throws WebbrowserUrlProvider.browserException { final PsiFile psiFile = psiElement instanceof PsiFile ? (PsiFile)psiElement : psiElement.getContainingFile(); if (psiFile == null) { return null; } VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) { return null; } if (virtualFile instanceof HttpVirtualFile) { return Urls.newFromVirtualFile(virtualFile); } if (!(preferLocalUrl && HtmlUtil.isHtmlFile(psiFile))) { Pair<WebbrowserUrlProvider,Url> provider = getProvider(psiElement); if (provider != null) { if (provider.second != null) { return provider.second; } try { Url url = provider.first.getUrl(psiElement,psiFile,virtualFile); if (url != null) { return url; } } catch (WebbrowserUrlProvider.browserException e) { if (!HtmlUtil.isHtmlFile(psiFile)) { throw e; } } } } return virtualFile instanceof LightVirtualFile ? null : Urls.newFromVirtualFile(virtualFile); }
public static boolean mayShowToolbar(@Nullable final Document document) { if (document == null) { return false; } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); return file != null && file.isValid() && (file.getFileSystem() == LocalFileSystem.getInstance() || file instanceof HttpVirtualFile); }
/** * do not call this method from plugins,offset); } finally { lock.finish(); } }
private static boolean isSuitable(@Nonnull TextEditor editor,@Nonnull VirtualFile file) { if (file instanceof HttpVirtualFile) { return false; } return editor.isValid() && BreadcrumbsWrapper.findInfoProvider(editor.getEditor(),file) != null; }
@NotNull @Override public Collection<Url> getUrlsToOpen(@NotNull OpenInbrowserRequest request,boolean preferLocalUrl) throws WebbrowserUrlProvider.browserException { VirtualFile virtualFile = request.getVirtualFile(); if(virtualFile instanceof HttpVirtualFile) { return Collections.singleton(Urls.newFromVirtualFile(virtualFile)); } if(!preferLocalUrl || !HtmlUtil.isHtmlFile(request.getFile())) { WebbrowserUrlProvider provider = getProvider(request); if(provider != null) { if(request.getResult() != null) { return request.getResult(); } try { Collection<Url> urls = provider.getUrls(request); if(!urls.isEmpty()) { return urls; } } catch(WebbrowserUrlProvider.browserException e) { if(!HtmlUtil.isHtmlFile(request.getFile())) { throw e; } } } } return virtualFile instanceof LightVirtualFile || !request.getFile().getViewProvider().isPhysical() ? Collections.<Url>emptySet() : Collections.singleton(Urls.newFromVirtualFile(virtualFile)); }
public RemoteFilePanel(final Project project,final HttpVirtualFile virtualFile,@NotNull Propertychangelistener propertychangelistener) { myProject = project; myVirtualFile = virtualFile; myPropertychangelistener = propertychangelistener; myErrorLabel.setIcon(AllIcons.runconfigurations.ConfigurationWarning); myUrlTextField.setText(virtualFile.getUrl()); myProgressUpdatesQueue = new MergingUpdateQueue("downloading progress updates",300,false,myMainPanel); initToolbar(project); final RemoteFileInfo remoteFileInfo = virtualFile.getFileInfo(); myDownloadingListener = new MyDownloadingListener(); assert remoteFileInfo != null; remoteFileInfo.addDownloadingListener(myDownloadingListener); myCancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull final ActionEvent e) { remoteFileInfo.cancelDownloading(); } }); myTryAgainButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull final ActionEvent e) { showCard(DOWNLOADING_CARD); remoteFileInfo.restartDownloading(); } }); myChangeProxySettingsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@NotNull ActionEvent e) { HttpConfigurable.editConfigurable(myMainPanel); } }); if (remoteFileInfo.getState() != RemoteFileState.DOWNLOADED) { showCard(DOWNLOADING_CARD); remoteFileInfo.startDownloading(); } // file Could be from cache if (remoteFileInfo.getState() == RemoteFileState.DOWNLOADED) { switchEditor(); } else { String errorMessage = remoteFileInfo.getErrorMessage(); if (errorMessage != null) { myDownloadingListener.errorOccurred(errorMessage); } } }
@NotNull public abstract AnAction[] createtoolbaractions(@NotNull Project project,@NotNull HttpVirtualFile file);
@Override public boolean accept(@NotNull final Project project,@NotNull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@Override @NotNull public FileEditor createEditor(@NotNull final Project project,@NotNull final VirtualFile file) { return new HttpFileEditor(project,(HttpVirtualFile)file); }
public RefreshRemoteFileAction(HttpVirtualFile file) { super("Reload File","",AllIcons.Actions.Refresh); myFile = file; }
public JumpFromremoteFiletoLocalAction(HttpVirtualFile file,Project project) { super("Find Local File",AllIcons.General.AutoscrollToSource); myFile = file; myProject = project; }
@NotNull @Override public AnAction[] createtoolbaractions(@NotNull Project project,@NotNull HttpVirtualFile file) { return new AnAction[] {new JumpFromremoteFiletoLocalAction(file,project)}; }
@Override public boolean ismine(Project project,@NotNull VirtualFile file) { return file instanceof HttpVirtualFile; }
@NotNull public abstract AnAction[] createtoolbaractions(@NotNull Project project,@NotNull HttpVirtualFile file);
public boolean accept(@NotNull final Project project,@NotNull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@NotNull public FileEditor createEditor(@NotNull final Project project,(HttpVirtualFile)file); }
public RefreshRemoteFileAction(HttpVirtualFile file) { super("Reload File",AllIcons.Actions.Refresh); myFile = file; }
public HttpFileEditor(final Project project,final HttpVirtualFile virtualFile) { myProject = project; myPanel = new RemoteFilePanel(project,virtualFile); }
public JumpFromremoteFiletoLocalAction(HttpVirtualFile file,AllIcons.General.AutoscrollToSource); myFile = file; myProject = project; }
@NotNull @Override public AnAction[] createtoolbaractions(@NotNull Project project,project)}; }
@Nonnull public abstract AnAction[] createtoolbaractions(@Nonnull Project project,@Nonnull HttpVirtualFile file);
public boolean accept(@Nonnull final Project project,@Nonnull final VirtualFile file) { return file instanceof HttpVirtualFile && !file.isDirectory(); }
@Nonnull public FileEditor createEditor(@Nonnull final Project project,@Nonnull final VirtualFile file) { return new HttpFileEditor(project,(HttpVirtualFile)file); }
public RefreshRemoteFileAction(HttpVirtualFile file) { super("Reload File",AllIcons.Actions.Refresh); myFile = file; }
public HttpFileEditor(final Project project,virtualFile); }
public JumpFromremoteFiletoLocalAction(HttpVirtualFile file,AllIcons.General.AutoscrollToSource); myFile = file; myProject = project; }
@Nonnull @Override public AnAction[] createtoolbaractions(@Nonnull Project project,@Nonnull HttpVirtualFile file) { return new AnAction[] {new JumpFromremoteFiletoLocalAction(file,project)}; }
@Override public boolean ismine(Project project,@Nonnull VirtualFile file) { return file instanceof HttpVirtualFile; }
今天关于linux gnome虚拟文件系统 gvfs和gnome-vfs 简介和linux的虚拟文件系统的分享就到这里,希望大家有所收获,若想了解更多关于Apache commons VFS 无法解析带有字符串 URI、Centos kernel panic-not syncing:VFS:Unable to mount root fs on unknown block、com.intellij.openapi.vfs.encoding.EncodingRegistry的实例源码、com.intellij.openapi.vfs.impl.http.HttpVirtualFile的实例源码等相关知识,可以在本站进行查询。
本文标签: