/** * Returns an <code>AbstractFile</code> to the extension file with the specified filename and located in the * {@link #getExtensionsFolder() extensions folder}. The returned file may or may not exist. * @param filename the extension's filename * @return an AbstractFile to the extension file with the specified filename and located in the * extensions folder. * @throws IOException if the file could not be instantiated. */ public static AbstractFile getExtensionsFile(String filename) throws IOException { return getExtensionsFolder().getDirectChild(filename); }
/** * Checks if CRC file exists. * @param file firts part */ private void findCRCFile(AbstractFile file) { AbstractFile f = file.getParent(); if (f != null) { try { crcFile = f.getDirectChild(file.getNameWithoutExtension() + ".sfv"); } catch (IOException e) { LOGGER.debug("Caught exception", e); } } }
/** * Creates and returns a temporary local file using the desired filename. If a file with this name already exists * in the temp directory, the filename's prefix (name without extension) will be appended an ID. The filename's * extension will however always be preserved. * * <p>The returned file may be a {@link LocalFile} or a {@link AbstractArchiveFile} if the extension corresponds * to a registered archive format.</p> * * @param desiredFilename the desired filename for the temporary file. If a file with this name already exists * in the temp directory, the filename's prefix (name without extension) will be appended an ID, but the filename's * extension will always be preserved. * @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(String desiredFilename, boolean deleteOnExit) throws IOException { if(desiredFilename==null || desiredFilename.equals("")) desiredFilename = "temp"; // Attempt to use the desired name AbstractFile tempFile = TEMP_DIRECTORY.getDirectChild(desiredFilename); if(tempFile.exists()) tempFile = TEMP_DIRECTORY.getDirectChild(getFilenameVariation(desiredFilename)); if(deleteOnExit) ((java.io.File)tempFile.getUnderlyingFileObject()).deleteOnExit(); return tempFile; }
@Override public AbstractFile getTemporaryFile() throws IOException { return tempFolder.getDirectChild(getPseudoUniqueFilename(HDFSFileTest.class.getName())); }
@Override public AbstractFile getTemporaryFile() throws IOException { return tempFolder.getDirectChild(getPseudoUniqueFilename(SMBFileTest.class.getName())); }
@Override public AbstractFile getTemporaryFile() throws IOException { return tempFolder.getDirectChild(getPseudoUniqueFilename(SFTPFileTest.class.getName())); }
@Override public AbstractFile getTemporaryFile() throws IOException { return tempFolder.getDirectChild(getPseudoUniqueFilename(FTPFileTest.class.getName())); }
@Override public AbstractFile getTemporaryFile() throws IOException { return tempFolder.getDirectChild(getPseudoUniqueFilename(S3FileTest.class.getName())); }
/** * Creates a destination file given a destination folder and a new file name. * @param destFolder a destination folder * @param destFileName a destination file name * @return the destination file or null if it cannot be created */ protected AbstractFile createDestinationFile(AbstractFile destFolder, String destFileName) { AbstractFile destFile; do { // Loop for retry try { destFile = destFolder.getDirectChild(destFileName); break; } catch(IOException e) { // Destination file couldn't be instantiated int ret = showErrorDialog(errorDialogTitle, Translator.get("cannot_write_file", destFileName)); // Retry loops if(ret==FileJobAction.RETRY) continue; // Cancel or close dialog return false return null; // Skip continues } } while(true); return destFile; }
sourceChecksum = ((ChecksumInputStream)origFileStream).getChecksumString(); AbstractFile crcFile = baseDestFolder.getDirectChild(crcFileName); OutputStream crcStream = crcFile.getOutputStream(); String line = sourceFile.getName() + " " + sourceChecksum;
file = lastSelectedFolder.getDirectChild(file.getName()+".xml");
checksumFile = resolvedDest.getDestinationFile().getDirectChild(getChecksumFilename(algorithm)); else checksumFile = resolvedDest.getDestinationFile();
/** * Asserts that a file can be renamed to a filename variation of the same file. * * @throws IOException should not normally happen * @throws NoSuchAlgorithmException should not happen */ @Test public void testRenameToCaseVariation() throws IOException, NoSuchAlgorithmException { // First test with a regular file createFile(tempFile, 1); AbstractFile destFile = tempFile.getParent().getDirectChild(tempFile.getName().toUpperCase()); deleteWhenFinished(destFile); tempFile.renameTo(destFile); assert !destFile.isSymlink(); // Leave me // Repeat the test with a directory destFile.delete(); tempFile.mkdir(); tempFile.renameTo(destFile); assert !destFile.isSymlink(); // Leave me }
for (AbstractFile child : children) { try { destChild = destFile.getDirectChild(child.getName());
/** * Tests {@link AbstractFile#getParent()} and {@link AbstractFile#isParentOf(AbstractFile)} methods. * * @throws IOException should not happen */ @Test public void testParent() throws IOException { AbstractFile file = tempFile; AbstractFile parent; AbstractFile child; // Tests all parents until the root is reached while((parent=file.getParent())!=null) { assert parent.isParentOf(file); // a file that has a parent shouldn't be a root file assert !file.isRoot(); // Assert that the child file can be resolved into the same file using getDirectChild() child = parent.getDirectChild(file.getName()); assert child != null; assert child.equals(file); file = parent; } // Assert that the root file's parent URL is null: if that is not the case, the parent file should have been // resolved. assert file.getURL().getParent()==null; // A file that has no parent should be a root file assert file.isRoot(); }
AbstractFile childFile = tempFile.getDirectChild("file"); childFile.mkfile(); ioExceptionThrown = false;
AbstractFile dir1 = tempFile.getDirectChild("dir1"); AbstractFile dir2 = dir1.getDirectChild("dir2"); AbstractFile dir2b = dir1.getChild("dir2"+dir1.getSeparator()); // Same file with a trailing separator dir2.mkdirs();
AbstractFile unicodeFile = baseFolder.getDirectChild(unicodeFilename); assert unicodeFilename.equals(unicodeFile.getName());
AbstractFile subFolder = tempFile.getDirectChild("subfolder"); exceptionThrown = false; try { copyTo(tempFile, subFolder, useRemoteCopy); }
String separator = baseFolder.getSeparator(); String nonExistentFilename = "non_existent_file"; AbstractFile nonExistentFile = baseFolder.getDirectChild(nonExistentFilename); String existingFilename = "existing_file"; AbstractFile existingFile = baseFolder.getDirectChild(existingFilename); existingFile.mkfile(); String existingArchiveFilename = "existing_archive.zip"; AbstractFile existingArchive = baseFolder.getDirectChild(existingArchiveFilename); existingArchive.mkfile();