/** * Returns the canonical path to this file, resolving any symbolic links or '..' and '.' occurrences. * A separator character will be appended to the returned path if <code>true</code> is passed. * * @param appendSeparator if true, a separator will be appended to the returned path * @return the canonical path to this file */ public final String getCanonicalPath(boolean appendSeparator) { String path = getCanonicalPath(); return appendSeparator?addTrailingSeparator(path): removeTrailingSeparator(path); }
/** * Returns the absolute path to this file. * A separator character will be appended to the returned path if <code>true</code> is passed. * * @param appendSeparator if true, a separator will be appended to the returned path * @return the absolute path to this file */ public final String getAbsolutePath(boolean appendSeparator) { String path = getAbsolutePath(); return appendSeparator?addTrailingSeparator(path): removeTrailingSeparator(path); }
/** * Adds a dummy output file (used in progress monitoring). * @param i index of a file * @param size size of a file */ private void addDummyFile(int i, long size) { String num; if (i<10) { num = "00" + Integer.toString(i); } else if (i<100) { num = "0" + Integer.toString(i); } else { num = Integer.toString(i); } FileURL childURL = (FileURL)destFolder.getURL().clone(); childURL.setPath(destFolder.addTrailingSeparator(childURL.getPath()) + sourceFile.getName() + "." + num); DummyDestFile fileHolder = new DummyDestFile(childURL, size); files.add(fileHolder); }
/** * Returns a child of this file, whose path is the concatenation of this file's path and the given relative path. * Although this method does not enforce it, the specified path should be relative, i.e. should not start with * a separator.<br/> * An <code>IOException</code> may be thrown if the child file could not be instantiated but the returned file * instance should never be <code>null</code>. * * @param relativePath the child's path, relative to this file's path * @return an AbstractFile representing the requested child file, never null * @throws IOException if the child file could not be instantiated */ public final AbstractFile getChild(String relativePath) throws IOException { FileURL childURL = (FileURL)getURL().clone(); childURL.setPath(addTrailingSeparator(childURL.getPath())+ relativePath); return FileFactory.getFile(childURL, true); }
/** * Ensures that {@link AbstractFile} instance caching works as expected, that is the same instance is returned * by <code>FileFactory#getFile</code> methods every time the same location is asked for. * * @throws Exception should not happen */ @Test public void testFileInstanceCaching() throws Exception { AbstractFile file; for(int i=0; i<10; i++) { file = getTemporaryFile(); for(int j=0; j<5; j++) { // Resolve by path String pathT = file.addTrailingSeparator(file.getURL().toString(true, false)); String pathNT = file.removeTrailingSeparator(pathT); assert FileFactory.getFile(pathT)==file; assert FileFactory.getFile(pathNT)==file; // Resolve by URL assert FileFactory.getFile(file.getURL())==file; assert FileFactory.getFile(FileURL.getFileURL(pathT))==file; assert FileFactory.getFile(FileURL.getFileURL(pathNT))==file; } } }
tempFileURLB.setPath(tempFile.addTrailingSeparator(tempFileURLB.getPath())); AbstractFile tempFileB = FileFactory.getFile(tempFileURLB, true);