/** * Shorthand for {@link #getFile(FileURL, AbstractFile, Authenticator, Object...)} called with the * {@link #getDefaultAuthenticator() default authenticator}. * * @param fileURL the file URL representing the file to be created * @param parent the parent AbstractFile to use as the created file's parent, can be <code>null</code> * @return an instance of {@link AbstractFile} for the given {@link FileURL}. * @throws java.io.IOException if something went wrong during file creation. */ public static AbstractFile getFile(FileURL fileURL, AbstractFile parent, Object... instantiationParams) throws IOException { return getFile(fileURL, parent, defaultAuthenticator, instantiationParams); }
private static AbstractFile createTemporaryFolder() { AbstractFile tempFolder; try { tempFolder = FileFactory.getTemporaryFile("mucomander-self-update", true); tempFolder.mkdir(); } catch(IOException e) { tempFolder = FileFactory.getTemporaryFolder(); } return tempFolder; }
public void addTab(String protocol, ServerPanel serverPanel, Class<? extends ServerPanel> selectPanelClass) { if(!FileFactory.isRegisteredProtocol(protocol)) return; JPanel northPanel = new JPanel(new BorderLayout()); northPanel.add(serverPanel, BorderLayout.NORTH); tabbedPane.addTab(protocol.toUpperCase(), northPanel); if(selectPanelClass.equals(serverPanel.getClass())) tabbedPane.setSelectedComponent(northPanel); serverPanels.add(serverPanel); }
/** * Creates a temporary file with a default filename. This method is a shorthand for * {@link #getTemporaryFile(String, boolean)} called with a <code>null</code> name. * * @param deleteOnExit if <code>true</code>, the temporary file will be deleted upon normal termination of the JVM * @return the temporary file, may be a LocalFile or an AbstractArchiveFile if the filename's extension corresponds * to a registered archive format. * @throws IOException if an error occurred while instantiating the temporary file. This should not happen under * normal circumstances. */ public static AbstractFile getTemporaryFile(boolean deleteOnExit) throws IOException { return getTemporaryFile(null, deleteOnExit); }
if(!isRegisteredProtocol(protocol)) throw new IOException("Unsupported file protocol: "+protocol); if (isArchiveFilename(pt.nextFilename())) { currentFile = wrapArchive(createRawFile(clonedURL, authenticator, instantiationParams)); currentFile = createRawFile(clonedURL, authenticator, instantiationParams);
/** * Calls {@link #testResolveDestination(AbstractFile)} with the system's temporary folder. * * @throws IOException should not happen */ @Test public void testResolveLocalDestination() throws IOException { testResolveDestination(FileFactory.getTemporaryFolder()); }
return FileFactory.wrapArchive(entryFile);
/** * Returns true if the given filename's extension matches one of the registered archive formats. * * @param filename the filename to test * @return <code>true</code> if the specified filename is a known archive file name, <code>false</code> otherwise. */ public static boolean isArchiveFilename(String filename) { return getArchiveFormatProvider(filename) != null; }
@Override public AbstractFile getTemporaryFile() throws IOException { // Returns a ProxyFile instance proxying a LocalFile ; the kind of proxied file should not matter as long as it // passes AbstractFileTest. return new ProxyFile(FileFactory.getTemporaryFile(getClass().getName(), false)) { // Note: a ProxyFile with no overridden method serves absolutely no purpose whatsoever }; }
/** * Creates a new <code>TempExecJob</code> that operates on a single file. * * @param progressDialog the ProgressDialog that monitors this job * @param mainFrame the MainFrame this job is attached to * @param fileToCopy the file to copy to a temporary location */ public TempCopyJob(ProgressDialog progressDialog, MainFrame mainFrame, AbstractFile fileToCopy) { super(progressDialog, mainFrame, new FileSet(fileToCopy.getParent(), fileToCopy), FileFactory.getTemporaryFolder(), getTemporaryFileName(fileToCopy), TransferMode.COPY, FileCollisionDialog.OVERWRITE_ACTION); }
resolvedFile = FileFactory.wrapArchive(resolvedFile, extension); resolvedFile.setCustomExtension(extension); } catch (IOException e) {
/** * Same as wrapArchive(AbstractFile) but using the given extension rather than the file's extension. */ public static AbstractFile wrapArchive(AbstractFile file, String extension) throws IOException { String filename = "tmp" + extension; ArchiveFormatProvider provider = getArchiveFormatProvider(filename); return provider != null ? provider.getFile(file) : file; }
/** * Opens a backup output stream on the specified file. * @param file file on which to open a backup output stream. * @exception IOException thrown if any IO error occurs. */ public BackupOutputStream(File file) throws IOException {this(FileFactory.getFile(file.getAbsolutePath()));}
protected static AbstractFile getTemporaryFolder(FileSet files) { AbstractFile tempFolder; try { tempFolder = FileFactory.getTemporaryFile(files.getBaseFolder().getName(), true); tempFolder.mkdir(); } catch(IOException e) { tempFolder = FileFactory.getTemporaryFolder(); } return tempFolder; }
@Override public AbstractFile getTemporaryFile() throws IOException { return FileFactory.getTemporaryFile(getClass().getName(), false); }
@BeforeClass protected void setUp() throws Exception { TestFile parent = new TestFile(FileFactory.getTemporaryFolder() + "parent", null); abcdef = new TestFile(FileFactory.getTemporaryFolder() + "abcdef", parent); abcdef_ghi = new TestFile(FileFactory.getTemporaryFolder() + "abcdef.ghi", parent); abcdef_ghi_jkl = new TestFile(FileFactory.getTemporaryFolder() + "abcdef.ghi.jkl", parent); _abcdef = new TestFile(FileFactory.getTemporaryFolder() + ".abcdef", parent); }
if(FileFactory.isRegisteredProtocol(FileProtocols.SMB)) { action = new CustomOpenLocationAction(mainFrame, new Hashtable<String, Object>(), new Bookmark(Translator.get("drive_popup.network_shares"), "smb:///")); action.setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.NETWORK_ICON_NAME));
/** * Tests if the given file's extension matches that of one of the registered archive formats. * If it does, a corresponding {@link AbstractArchiveFile} instance is created on top of the provided file * and returned. If it doesn't, the provided <code>AbstractFile</code> instance is simply returned. * <p> * Note that return {@link AbstractArchiveFile} instances may not actually be archives according to * {@link AbstractFile#isArchive()}. An {@link AbstractArchiveFile} instance that is not currently an archive * (either non-existent or a directory) will behave as a regular (non-archive) file. This allows file instances to * go from being an archive to not being an archive (and vice-versa), without having to re-resolve the file. * </p> */ public static AbstractFile wrapArchive(AbstractFile file) throws IOException { String filename = file.getName(); // Looks for an archive FilenameFilter that matches the given filename. // Comparing the filename against each and every archive extension has a cost, so we only perform the test if // the filename contains a dot '.' character, since most of the time this method is called with a filename that // doesn't match any of the filters. if (filename.indexOf('.')!=-1) { ArchiveFormatProvider provider = getArchiveFormatProvider(filename); if (provider != null) { return provider.getFile(file); } } return file; }
/** * Returns the user home folder. Most if not all OSes have one, but in the unlikely event that the OS doesn't have * one or that the folder cannot be resolved, <code>null</code> will be returned. * * @return the user home folder */ public static AbstractFile getUserHome() { String userHomePath = System.getProperty("user.home"); if(userHomePath==null) return null; return FileFactory.getFile(userHomePath); }
/** * 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); }