@Override public boolean isDirectory() { return file.isDirectory(); }
/** * Return <code>true</code> if the specified file is a GNOME Trash folder, i.e. is a directory and has two * subdirectories named "info" and "files". * * @param file the file to test * @return <code>true</code> if the specified file is a GNOME Trash folder */ private static boolean isTrashFolder(AbstractFile file) { try { return file.isDirectory() && file.getChild("info").isDirectory() && file.getChild("files").isDirectory(); } catch(IOException e) { return false; } }
/** * Return <code>true</code> if the specified file is a Xfce Trash folder, i.e. is a directory and has two * subdirectories named "info" and "files". * * @param file the file to test * @return <code>true</code> if the specified file is a Xfce Trash folder */ private static boolean isTrashFolder(AbstractFile file) { try { return file.isDirectory() && file.getChild("info").isDirectory() && file.getChild("files").isDirectory(); } catch(IOException e) { return false; } }
/** * Returns <code>true</code> if this file is browsable. A file is considered browsable if it contains children files * that can be retrieved by calling the <code>ls()</code> methods. Archive files will usually return * <code>true</code>, as will directories (directories are always browsable). * * @return true if this file is browsable */ public final boolean isBrowsable() { return isDirectory() || isArchive(); }
public boolean canViewFile(AbstractFile file) { // Do not allow directories if(file.isDirectory()) return false; return filter.accept(file); }
/** * Returns <code>true</code> for directories with an <code>app</code> extension (case-insensitive comparison). * * @param file the file to test * @return <code>true</code> for directories with an <code>app</code> extension (case-insensitive comparison). */ @Override public boolean isApplication(AbstractFile file) { String extension = file.getExtension(); // the isDirectory() test comes last as it is I/O bound return extension!=null && extension.equalsIgnoreCase("app") && file.isDirectory(); } }
/** * Returns <code>true</code> for regular files (not directories) with an <code>exe</code> extension * (case-insensitive comparison). * * @param file the file to test * @return <code>true</code> for regular files (not directories) with an <code>exe</code> extension * (case-insensitive comparison). */ @Override public boolean isApplication(AbstractFile file) { String extension = file.getExtension(); // the isDirectory() test comes last as it is I/O bound return extension!=null && extension.equalsIgnoreCase("exe") && !file.isDirectory(); } }
/** * This method is a shorthand for {@link #importPermissions(AbstractFile, FilePermissions)} called with * {@link FilePermissions#DEFAULT_DIRECTORY_PERMISSIONS} if this file is a directory or * {@link FilePermissions#DEFAULT_FILE_PERMISSIONS} if this file is a regular file. * * @param sourceFile the file from which to import permissions * @throws IOException if the permissions couldn't be changed, either because of insufficient permissions or because * of an I/O error. * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ public final void importPermissions(AbstractFile sourceFile) throws IOException, UnsupportedFileOperationException { importPermissions(sourceFile,isDirectory() ? FilePermissions.DEFAULT_DIRECTORY_PERMISSIONS : FilePermissions.DEFAULT_FILE_PERMISSIONS); }
/** * Returns the MIME type of the given file (determined by the file extension), <code>null</code> * if the type is unknown (unknown or no extension) or if the file is a folder. */ public static String getMimeType(AbstractFile file) { if(file.isDirectory()) return null; String name = file.getName(); int pos = name.lastIndexOf('.'); if(pos==-1) return null; return mimeTypes.get(name.substring(pos+1, name.length()).toLowerCase()); }
public void addToCache(AbstractFile file, Icon icon, Dimension preferredResolution) { // Map the extension onto the given icon (file.isDirectory()? directoryIconCache : fileIconCache).put(getCheckedExtension(file), icon); }
@Override public boolean isDirectory() { if(!isDirectorySet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!isDirectorySet) { isDirectory = file.isDirectory(); isDirectorySet = true; } return isDirectory; }
public Icon lookupCache(AbstractFile file, Dimension preferredResolution) { // Under Mac OS X, return the icon of /Network for the root of remote (non-local) locations. if(OsFamily.MAC_OS_X.isCurrent() && !FileProtocols.FILE.equals(file.getURL().getScheme()) && file.isRoot()) return getSwingIcon(new java.io.File("/Network")); // Look for an existing icon instance for the file's extension return (file.isDirectory()? directoryIconCache : fileIconCache).get(getCheckedExtension(file)); }
/** * Adds the given file to the FileSet if it's not a folder, recurses otherwise. */ private void recurseOnFolder(AbstractFile file, FileSet flattenedFiles) throws IOException { if(file.isDirectory() && !file.isSymlink()) { AbstractFile children[] = file.ls(); for (AbstractFile child : children) recurseOnFolder(child, flattenedFiles); } else { flattenedFiles.add(file); } }
/** * Deletes the given file. If the file is a directory, enclosing files are deleted recursively. * Symbolic links to directories are simply deleted, without deleting the contents of the linked directory. * * @param file the file to delete * @throws IOException if an error occurred while deleting a file or listing a directory's contents * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ protected final void deleteRecursively(AbstractFile file) throws IOException, UnsupportedFileOperationException { if(file.isDirectory() && !file.isSymlink()) { AbstractFile children[] = file.ls(); for (AbstractFile child : children) deleteRecursively(child); } file.delete(); }
/** * Pre-fetch the attributes that are used by the table renderer and some actions from the given CachedFile. * By doing so, the attributes will be available when the associated getters are called and thus the methods won't * be I/O bound and will not lock. * * @param cachedFile a CachedFile instance from which to pre-fetch attributes */ private static void prefetchCachedFileAttributes(AbstractFile cachedFile) { cachedFile.isDirectory(); cachedFile.isBrowsable(); cachedFile.isHidden(); // Pre-fetch isSymlink attribute and if the file is a symlink, pre-fetch the canonical file and its attributes if(cachedFile.isSymlink()) { AbstractFile canonicalFile = cachedFile.getCanonicalFile(); if(canonicalFile!=cachedFile) // Cheap test to prevent infinite recursion on bogus file implementations prefetchCachedFileAttributes(canonicalFile); } }
/** * Tests {@link com.mucommander.commons.file.FileFactory#getTemporaryFolder()}. * * @throws IOException should not happen */ @Test public void testTemporaryFolder() throws IOException { // Assert that the returned file is a folder that exists AbstractFile temporaryFolder = FileFactory.getTemporaryFolder(); assert temporaryFolder != null; assert temporaryFolder.isDirectory(); assert temporaryFolder.exists(); // Assert that the temporary folder is the parent folder of temporary files AbstractFile temporaryFile = FileFactory.getTemporaryFile(false); assert temporaryFile.getParent().equals(temporaryFolder); }
@Override public void performAction() { FileTable fileTable = mainFrame.getActiveTable(); FileTableModel tableModel = fileTable.getFileTableModel(); // Starts at 1 if current folder is not root so that '..' is not marked AbstractFile file; int nbRows = tableModel.getRowCount(); for(int i=tableModel.getFirstMarkableRow(); i<nbRows; i++) { file = tableModel.getFileAtRow(i); if(!file.isDirectory()) tableModel.setRowMarked(i, !tableModel.isRowMarked(i)); } fileTable.repaint(); // Notify registered listeners that currently marked files have changed on the FileTable fileTable.fireMarkedFilesChangedEvent(); }
/** * Asserts that {@link com.mucommander.commons.file.protocol.local.LocalFile#getUserHome()} returns a file that is not null, * is a directory, and exists, and that '~' can be resolved as the user home folder. * * @throws IOException should not happen */ @Test public void testUserHome() throws IOException { AbstractFile homeFolder = LocalFile.getUserHome(); assert homeFolder != null; assert homeFolder.isDirectory(); assert homeFolder.exists(); assert homeFolder.equals(FileFactory.getFile("~")); assert homeFolder.getChild("blah").equals(FileFactory.getFile("~").getChild("blah")); }
/** * Asserts that the attributes of the given AbstractFile and SimpleFileAttributes match. */ private void assertAttributesMatch(AbstractFile file, SimpleFileAttributes attrs) { assert file.getAbsolutePath().equals(attrs.getPath()); assert file.exists() == attrs.exists(); assert file.getDate() == attrs.getDate(); assert file.getSize() == attrs.getSize(); assert file.isDirectory() == attrs.isDirectory(); assert file.getPermissions() == attrs.getPermissions(); assert file.getOwner() == null ? attrs.getOwner() == null : file.getOwner().equals(attrs.getOwner()); assert file.getGroup() == null ? attrs.getGroup() == null : file.getGroup().equals(attrs.getGroup()); }
/** * Creates a new SimpleFileAttributes instance whose attributes are set to those of the given AbstractFile. * Note that the path attribute is set to the file's {@link com.mucommander.commons.file.AbstractFile#getAbsolutePath() absolute path}. * * @param file the file from which to fetch the attribute values */ public SimpleFileAttributes(AbstractFile file) { setPath(file.getAbsolutePath()); setExists(file.exists()); setDate(file.getDate()); setSize(file.getSize()); setDirectory(file.isDirectory()); setPermissions(file.getPermissions()); setOwner(file.getOwner()); setGroup(file.getGroup()); }