/** * Convenience method that acts as {@link #getChild(String)} except that it does not throw {@link IOException} but * returns <code>null</code> if the child could not be instantiated. * * @param relativePath the child's path, relative to this file's path * @return an AbstractFile representing the requested child file, <code>null</code> if it could not be instantiated */ public final AbstractFile getChildSilently(String relativePath) { try { return getChild(relativePath); } catch(IOException e) { return null; } }
public static AbstractFile getDescriptionFile() throws IOException { if(descriptionFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_TOOLBAR_FILE_NAME); return descriptionFile; }
/** * Returns the path to the credentials file. * * @return the path to the credentials file. * @throws IOException if there was some problem locating the default credentials file. */ private static AbstractFile getCredentialsFile() throws IOException { if(credentialsFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_CREDENTIALS_FILE_NAME); return credentialsFile; }
/** * Returns the actions file. * @return the actions file. * @throws IOException if an error occurred while locating the default actions file. */ protected static AbstractFile getActionsFile() throws IOException { if(actionsFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_ACTIONS_FILE_NAME); return actionsFile; }
public static AbstractFile getDescriptionFile() throws IOException { if(commandBarFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_COMMAND_BAR_FILE_NAME); return commandBarFile; } }
/** * Returns the path to the configuration file. * @return the path to the configuration file. * @throws IOException if an error occurred while locating the default configuration file. */ private synchronized AbstractFile getConfigurationFile() throws IOException { if(configurationFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_CONFIGURATION_FILE_NAME); return configurationFile; }
/** * Convenience method that creates a file as a direct child of this directory. * This method will fail if this file is not a directory. * * @param name name of the file to create * @throws IOException if the file could not be created, either because the file already exists or for any * other reason. * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ public final void mkfile(String name) throws IOException, UnsupportedFileOperationException { getChild(name).mkfile(); }
/** * Convenience method that creates a directory as a direct child of this directory. * This method will fail if this file is not a directory. * * @param name name of the directory to create * @throws IOException if the directory could not be created, either because the file already exists or for any * other reason. * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ public final void mkdir(String name) throws IOException, UnsupportedFileOperationException { getChild(name).mkdir(); }
/** * Returns the path to the bookmark file. * <p> * If it hasn't been changed through a call to {@link #setBookmarksFile(String)}, * this method will return the default, system dependant bookmarks file. * </p> * @return the path to the bookmark file. * @see #setBookmarksFile(String) * @throws IOException if there was a problem locating the default bookmarks file. */ public static synchronized AbstractFile getBookmarksFile() throws IOException { if(bookmarksFile == null) return PlatformManager.getPreferencesFolder().getChild(DEFAULT_BOOKMARKS_FILE_NAME); return bookmarksFile; }
/** * 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; } }
private static AbstractFile getTempDestJar(AbstractFile destJar) { try { return createTemporaryFolder().getChild(destJar.getName()); } catch(IOException e) { return destJar; } }
/** * Returns an input stream on the requested custom theme. * @param name name of the custom theme on which to open an input stream. * @return an input stream on the requested custom theme. * @throws IOException if an I/O related error occurs. */ private static InputStream getCustomThemeInputStream(String name) throws IOException { return new BackupInputStream(getCustomThemesFolder().getChild(name + ".xml")); }
/** * Returns an output stream on the specified custom theme. * @param name name of the custom theme on which to open an output stream. * @return an output stream on the specified custom theme. * @throws IOException if an I/O related error occurs. */ private static BackupOutputStream getCustomThemeOutputStream(String name) throws IOException { return new BackupOutputStream(getCustomThemesFolder().getChild(name + ".xml")); }
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(); }
/** * 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; }
public static void renameCustomTheme(Theme theme, String name) throws IOException { if(theme.getType() != Theme.CUSTOM_THEME) throw new IllegalArgumentException("Cannot rename non-custom themes."); // Makes sure the operation is necessary. if(theme.getName().equals(name)) return; // Computes a legal new name and renames theme. name = getAvailableCustomThemeName(name); getCustomThemesFolder().getChild(theme.getName() + ".xml").renameTo(getCustomThemesFolder().getChild(name + ".xml")); theme.setName(name); if(isCurrentTheme(theme)) setConfigurationTheme(theme); }
/** * 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); }
/** * 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")); }
/** * Resolves an AbstractFile instance corresponding to the file named <code>filename</code> within the temporary * folder and asserts its {@link AbstractFile#getName() name}, {@link AbstractFile#getExtension() extension} and * {@link AbstractFile#getNameWithoutExtension() name without extension} match the specified values. * * @param tempFolder the temporary folder which will be the parent of the resolved AbstractFile instance * @param filename filename of the AbstractFile to resolved * @param expectedExtension the expected file's extension * @param expectedNameWOExt the expected file's name without extension * @throws IOException if an error occurred while resolving the file */ protected void assertNameAndExtension(AbstractFile tempFolder, String filename, String expectedExtension, String expectedNameWOExt) throws IOException { AbstractFile file = tempFolder.getChild(filename); assert filename.equals(file.getName()); assert StringUtils.equals(expectedExtension, file.getExtension(), true); assert StringUtils.equals(expectedNameWOExt, expectedNameWOExt, true); }