@Override public void mkfile() throws IOException, UnsupportedFileOperationException { file.mkfile(); }
/** * 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(); }
/** * Tests {@link AbstractFile#getIcon()} and {@link AbstractFile#getIcon(java.awt.Dimension)}. * * @throws IOException should not happen */ @Test public void testIcon() throws IOException { Icon icon; boolean isHeadless; // Skips the test if under OS X (this would create a new instance of JFileChooser, which fails isHeadless = GraphicsEnvironment.isHeadless(); if(isHeadless && OsFamily.MAC_OS_X.isCurrent()) return; // Some icon providers will fail (return a null icon) if the file doesn't exist tempFile.mkfile(); icon = tempFile.getIcon(); if(!isHeadless) assert icon != null; icon = tempFile.getIcon(new Dimension(16, 16)); if(!isHeadless) assert icon != null; }
/** * 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(); }
tempFile.mkfile();
/** * Validates that FileMonitor properly reports {@link FileMonitor#IS_DIRECTORY_ATTRIBUTE} changes when a file * becomes a directory and vice-versa. * * @throws IOException should not normally happen */ @Test public void testIsDirectoryAttribute() throws IOException { setUp(IS_DIRECTORY_ATTRIBUTE); file.delete(); file.mkdir(); assert hasAttributeChanged(IS_DIRECTORY_ATTRIBUTE); file.delete(); file.mkfile(); assert hasAttributeChanged(IS_DIRECTORY_ATTRIBUTE); }
temporaryFile1.mkfile();
/** * Validates that FileMonitor properly reports {@link FileMonitor#EXISTS_ATTRIBUTE} changes when an existing file or * directory is deleted, or when a non-existing file or directory is created. * * @throws IOException should not normally happen */ @Test public void testExistsAttribute() throws IOException { setUp(EXISTS_ATTRIBUTE); file.delete(); assert hasAttributeChanged(EXISTS_ATTRIBUTE); file.mkdir(); assert hasAttributeChanged(EXISTS_ATTRIBUTE); file.delete(); assert hasAttributeChanged(EXISTS_ATTRIBUTE); file.mkfile(); assert hasAttributeChanged(EXISTS_ATTRIBUTE); }
/** * 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(); }
tempFile.mkfile();
/** * Creates a SimpleFileAttributes instance from an AbstractFile and ensures that the values returned by * SimpleFileAttributes' getters match those of AbstractFile. * * @throws IOException should not happen */ @Test public void testAccessors() throws IOException { LocalFileTest lft = new LocalFileTest(); // File doesn't exist AbstractFile tempFile = lft.getTemporaryFile(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); // File exists as a regular file tempFile.mkfile(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); // File exists as a directory tempFile.delete(); tempFile.mkdir(); assertAttributesMatch(tempFile, new SimpleFileAttributes(tempFile)); }
unicodeFile.mkdir(); else unicodeFile.mkfile();
assert !tempFileB.isDirectory(); tempFile.mkfile(); assert tempFile.exists(); assert !tempFile.isDirectory();
String existingFilename = "existing_file"; AbstractFile existingFile = baseFolder.getDirectChild(existingFilename); existingFile.mkfile(); String existingArchiveFilename = "existing_archive.zip"; AbstractFile existingArchive = baseFolder.getDirectChild(existingArchiveFilename); existingArchive.mkfile();