/** * 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); }
private static AbstractFile createTemporaryFolder() { AbstractFile tempFolder; try { tempFolder = FileFactory.getTemporaryFile("mucomander-self-update", true); tempFolder.mkdir(); } catch(IOException e) { tempFolder = FileFactory.getTemporaryFolder(); } return tempFolder; }
@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 }; }
@Override public AbstractFile getTemporaryFile() throws IOException { return FileFactory.getTemporaryFile(getClass().getName(), false); }
protected static String getTemporaryFileName(AbstractFile files) { try { return FileFactory.getTemporaryFile(files.getName(), true).getName(); } catch(IOException e) { // Should never happen under normal circumstances. LOGGER.warn("Caught exception instantiating temporary file, this should not happen!"); return files.getName(); } } }
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; }
tmpFile = FileFactory.getTemporaryFile("trash_files.muco", false); tmpOut = new OutputStreamWriter(tmpFile.getOutputStream(), "utf-8");
/** * Creates a returns a temporary local file/directory with the same extension as the specified file/directory * (guaranteed), and the same filename as much as possible (best effort). * This method returns <code>null</code> if the temporary file/directory could not be created. * * @param nonLocalFile the non-local file for which to create a temporary file. * @return a temporary local file/directory with the same extension as the specified file/directory */ protected LocalFile createTempLocalFile(AbstractFile nonLocalFile) { try { // Note: the returned temporary file may be an AbstractArchiveFile if the filename's extension corresponds // to a registered archive format LocalFile tempFile = FileFactory.getTemporaryFile(nonLocalFile.getName(), false).getAncestor(LocalFile.class); // Create a directory if(nonLocalFile.isDirectory()) tempFile.mkdir(); // Create a regular file else tempFile.getOutputStream().close(); return tempFile; } catch(IOException e) { return null; } }
/** * Overridden to create the archive file before each test. */ @Override @BeforeMethod public void setUp() throws IOException { entryNum = 0; tempZipFile = (ZipArchiveFile)FileFactory.getTemporaryFile(ZipArchiveFileTest.class.getName()+".zip", false); // Assert that the file is not an actual archive yet assert !tempZipFile.isArchive(); tempZipFile.mkfile(); // Assert that the file is now an archive assert tempZipFile.isArchive(); super.setUp(); }
AbstractFile temporaryFile1 = FileFactory.getTemporaryFile(desiredName, true); assert temporaryFile1 != null; assert !temporaryFile1.exists(); AbstractFile temporaryFile2 = FileFactory.getTemporaryFile(desiredName, true); assert temporaryFile2 != null; assert !temporaryFile2.exists(); temporaryFile1 = FileFactory.getTemporaryFile(true); assert temporaryFile1 != null; assert !temporaryFile1.exists();
/** * Sets everything up for a test: retrieves a temporary file instance, create the file, waits until the file exists, * create a <code>FileMonitor</code>, register a {@link FileChangeTracker} and finally start monitoring file changes. * * @param attribute the attribute to monitor * @throws IOException should not normally happen */ private void setUp(int attribute) throws IOException { // Retrieve a temporary AbstractFile instance that will be deleted on VM shutdown file = FileFactory.getTemporaryFile(getClass().getName(), true); // Create the file file.mkfile(); // Waits until the file truly exists (I/O are usually asynchroneous) while(!file.exists()) { try { Thread.sleep(POLL_PERIOD); } catch(InterruptedException e) {} } // Create the monitor, change listener and start monitoring file changes fileMonitor = new FileMonitor(file, attribute, POLL_PERIOD); fileChangeTracker = new FileChangeTracker(); fileMonitor.addFileChangeListener(fileChangeTracker); fileMonitor.startMonitoring(); }
/** * 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); }
checksumFile = FileFactory.getTemporaryFile(getChecksumFilename(algorithm), true);
final OutputStream tempOut; try { tempFile = FileFactory.getTemporaryFile(false); tempOut = tempFile.getOutputStream();