/** * Get the physical root URL of the filesystem of a virtual file. This URI is suitable for conversion to a class loader's * code source URL or in similar situations where only standard URL types ({@code jar} and {@code file}) are supported. * * @param file the virtual file * @return the root URI * @throws URISyntaxException if the URI is not valid */ public static URI getRootURI(final VirtualFile file) throws URISyntaxException { return VFS.getMount(file).getFileSystem().getRootURI(); }
/** * Get the {@link CodeSigner}s for a the virtual file. * * @return the {@link CodeSigner}s for the virtual file, or {@code null} if not signed */ public CodeSigner[] getCodeSigners() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); return mount.getFileSystem().getCodeSigners(mount.getMountPoint(), this); }
/** * Get the children. This is the combined list of real children within this directory, as well as virtual children * created by submounts. * * @return the children */ public List<VirtualFile> getChildren() { // isDirectory does the read security check if (!isDirectory()) { return Collections.emptyList(); } final VFS.Mount mount = VFS.getMount(this); final Set<String> submounts = VFS.getSubmounts(this); final List<String> names = mount.getFileSystem().getDirectoryEntries(mount.getMountPoint(), this); final List<VirtualFile> virtualFiles = new ArrayList<VirtualFile>(names.size() + submounts.size()); for (String name : names) { final VirtualFile child = new VirtualFile(name, this); virtualFiles.add(child); submounts.remove(name); } for (String name : submounts) { final VirtualFile child = new VirtualFile(name, this); virtualFiles.add(child); } return virtualFiles; }
/** * When the file was last modified * * @return the last modified time */ public long getLastModified() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Long>() { @Override public Long run() { return mount.getFileSystem().getLastModified(mount.getMountPoint(), target); } }); } return mount.getFileSystem().getLastModified(mount.getMountPoint(), this); }
/** * Delete this virtual file * * @return {@code true} if file was deleted */ public boolean delete() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "delete")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { return mount.getFileSystem().delete(mount.getMountPoint(), target); } }); } return mount.getFileSystem().delete(mount.getMountPoint(), this); }
/** * Determine whether the named virtual file is a directory. * * @return {@code true} if it is a directory, {@code false} otherwise */ public boolean isDirectory() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { return mount.getFileSystem().isDirectory(mount.getMountPoint(), target); } }); } return mount.getFileSystem().isDirectory(mount.getMountPoint(), this); }
/** * Get the size * * @return the size */ public long getSize() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Long>() { @Override public Long run() { return mount.getFileSystem().getSize(mount.getMountPoint(), target); } }); } return mount.getFileSystem().getSize(mount.getMountPoint(), this); }
/** * Tests whether the underlying implementation file still exists. * * @return true if the file exists, false otherwise. */ public boolean exists() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { return mount.getFileSystem().exists(mount.getMountPoint(), target); } }); } return mount.getFileSystem().exists(mount.getMountPoint(), this); }
/** * Determine whether the named virtual file is a plain file. * * @return {@code true} if it is a plain file, {@code false} otherwise */ public boolean isFile() { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { @Override public Boolean run() { return mount.getFileSystem().isFile(mount.getMountPoint(), target); } }); } return mount.getFileSystem().isFile(mount.getMountPoint(), this); }
/** * Get a physical file for this virtual file. Depending on the underlying file system type, this may simply return * an already-existing file; it may create a copy of a file; or it may reuse a preexisting copy of the file. * Furthermore, the returned file may or may not have any relationship to other files from the same or any other * virtual directory. * * @return the physical file * @throws IOException if an I/O error occurs while producing the physical file */ public File getPhysicalFile() throws IOException { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "getfile")); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return doIoPrivileged(new PrivilegedExceptionAction<File>() { @Override public File run() throws Exception { return mount.getFileSystem().getFile(mount.getMountPoint(), target); } }); } return mount.getFileSystem().getFile(mount.getMountPoint(), this); }
/** * Access the file contents. * * @return an InputStream for the file contents. * @throws IOException for any error accessing the file system */ public InputStream openStream() throws IOException { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new VirtualFilePermission(getPathName(), "read")); } if (isDirectory()) { return new VirtualJarInputStream(this); } final VFS.Mount mount = VFS.getMount(this); if (sm != null) { final VirtualFile target = this; return doIoPrivileged(new PrivilegedExceptionAction<InputStream>() { @Override public InputStream run() throws Exception { return mount.getFileSystem().openInputStream(mount.getMountPoint(), target); } }); } return mount.getFileSystem().openInputStream(mount.getMountPoint(), this); }