@Override public boolean exists() { return file.exists(); }
public boolean isExists() throws IOException { return getConfigurationFile().exists(); } }
/** * This function return an icon for the specified file. * * @param file the file for which to return an icon * @return the specified file's icon. null is returned if the file does not exist */ protected Icon getIconOfFile(AbstractFile file) { return (file != null && file.exists()) ? IconManager.getImageIcon(FileIcons.getFileIcon(file)) : null; }
@Override public boolean exists() { if(!existsSet && 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(!existsSet) { exists = file.exists(); existsSet = true; } return exists; }
public static void deleteCustomTheme(String name) throws IOException { AbstractFile file; // Makes sure the specified theme is not the current one. if(isCurrentTheme(Theme.CUSTOM_THEME, name)) throw new IllegalArgumentException("Cannot delete current theme."); // Deletes the theme. file = getCustomThemesFolder().getChild(name + ".xml"); if(file.exists()) file.delete(); }
/** * Tries to load credentials from the credentials file if it exists. Does nothing if it doesn't. * * @throws Exception if an error occurs while loading the credentials file. */ public static void loadCredentials() throws Exception { AbstractFile credentialsFile = getCredentialsFile(); if(credentialsFile.exists()) { LOGGER.debug("Found credentials file: "+credentialsFile.getAbsolutePath()); // Parse the credentials file new CredentialsParser().parse(credentialsFile); LOGGER.debug("Credentials file loaded."); } else LOGGER.debug("No credentials file found at "+credentialsFile.getAbsolutePath()); }
/** * Tests {@link com.mucommander.commons.file.AbstractFile#exists()} in various situations. * * @throws IOException should not happen */ @Test public void testExists() throws IOException { assert !tempFile.exists(); tempFile.mkfile(); assert tempFile.exists(); tempFile.delete(); assert !tempFile.exists(); tempFile.mkdir(); assert tempFile.exists(); tempFile.delete(); assert !tempFile.exists(); }
/** * Overwrites the target file with the backup one. * @exception IOException thrown if any IO related error occurs. */ private void backup() throws IOException { // Deletes the destination file (AbstractFile.copyTo now fails when the destination exists). if(target.exists()) target.delete(); // We're not using backup.moveTo(target) because we want to make absolutely sure // that if an error occurs in the middle of the operation, at least one of the two files // is complete. backup.copyTo(target); backup.delete(); }
/** * Creates this file as a directory and any parent directory that does not already exist. This method will fail * (throw an <code>IOException</code>) if this file already exists. It may also fail because of an I/O error ; * in this case, this method will not remove the parent directories it has created (if any). * * @throws IOException if this file already exists or if an I/O error occurred. * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ public final void mkdirs() throws IOException, UnsupportedFileOperationException { AbstractFile parent; if(((parent=getParent())!=null) && !parent.exists()) parent.mkdirs(); mkdir(); }
/** * Return a workable location according the following logic: * - If the given folder exists, return it * - if the given folder is local file, find workable location * according to the logic used for inaccessible local files * - Otherwise, return the non-exist remote location */ private AbstractFile getWorkableLocation(FileURL folderURL) { AbstractFile folder = FileFactory.getFile(folderURL); if (folder != null && folder.exists()) return folder; if (folder == null) folder = new NullableFile(folderURL); return FileProtocols.FILE.equals(folderURL.getScheme()) ? getWorkableFolder(folder) : folder; }
/** * Returns the path to the custom themes' folder. * <p> * This method guarantees that the returned file actually exists. * </p> * @return the path to the custom themes' folder. * @throws IOException if an error occured while locating the default user themes folder. */ public static AbstractFile getCustomThemesFolder() throws IOException { AbstractFile customFolder; // Retrieves the path to the custom themes folder and creates it if necessary. customFolder = PlatformManager.getPreferencesFolder().getChild(CUSTOM_THEME_FOLDER); if(!customFolder.exists()) customFolder.mkdir(); return customFolder; }
/** * Cleans up test files after each test execution so as to leave the filesystem in the same state as it was * before the test. In particular, all files registered with {@link #deleteWhenFinished(AbstractFile)} are * deleted if they exist. * * @throws IOException if an error occurred while delete files registered with {@link #deleteWhenFinished(AbstractFile)} */ @AfterMethod public void tearDown() throws IOException { Iterator<AbstractFile> iterator = filesToDelete.iterator(); AbstractFile file; while(iterator.hasNext()) { file = iterator.next(); if(file.exists()) file.deleteRecursively(); } }
/** * Parses the XML file describing the toolbar's buttons and associated actions. * If the file doesn't exist, default toolbar elements will be used. */ public static void loadDescriptionFile() throws Exception { AbstractFile descriptionFile = getDescriptionFile(); if (descriptionFile != null && descriptionFile.exists()) { ToolBarReader reader = new ToolBarReader(descriptionFile); ToolBarAttributes.setActions(reader.getActionsRead()); } else LOGGER.debug("User toolbar.xml was not found, using default toolbar"); toolBarWriter = ToolBarWriter.create(); }
@Override public void renameTo(AbstractFile destFile) throws IOException { // Throw an exception if the file cannot be renamed to the specified destination checkRenamePrerequisites(destFile, false, false); // Delete the destination if it already exists as FileSystem#rename would otherwise fail. // Note: HadoopFile#delete() does not delete directories recursively (good). if(destFile.exists()) destFile.delete(); if(!fs.rename(path, ((HadoopFile)destFile).path)) throw new IOException(); // Update destination file attributes by fetching them from the server ((HadoopFileAttributes)destFile.getUnderlyingFileObject()).fetchAttributes(); // Update this file's attributes locally fileAttributes.setExists(false); fileAttributes.setDirectory(false); fileAttributes.setSize(0); }
private void assertReadable(AbstractFile file) throws IOException { assert file != null; assertReadable(file.getInputStream()); assert file.exists(); }
/** * Tests <code>ResourceLoader#getRootPackageAsFile</code> methods. * * @throws IOException should not happen */ @Test public void testRootPackageAsFile() throws IOException { AbstractFile rootPackageFile = ResourceLoader.getRootPackageAsFile(getClass()); assert rootPackageFile != null; assert rootPackageFile.exists(); assert rootPackageFile.isBrowsable(); AbstractFile thisClassFile = rootPackageFile.getChild("com/mucommander/commons/file/util/ResourceLoaderTest.class"); assertReadable(thisClassFile); }
/** * 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); }
/** * 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")); }
/** * 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()); }
/** * 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()); }