/** * Iterates through the ancestors returned by {@link #getAncestor()} until the top-most ancestor is reached and * returns it. If this file has no ancestor, <code>this</code> will be returned. * * @return returns the top-most ancestor of this file, <code>this</code> if this file has no ancestor */ public final AbstractFile getTopAncestor() { AbstractFile topAncestor = this; while(topAncestor.hasAncestor()) topAncestor = topAncestor.getAncestor(); return topAncestor; }
/** * Returns <code>true</code> if this file is or has an ancestor (immediate or not) that is an instance of the given * <code>Class</code> or of a subclass of the <code>Class</code>. Note that the specified must correspond to an * <code>AbstractFile</code> subclass. Specifying any other Class will always yield to this method returning * <code>false</code>. Also note that this method will always return <code>true</code> if * <code>AbstractFile.class</code> is specified. * * @param abstractFileClass a Class corresponding to an AbstractFile subclass * @return <code>true</code> if this file has an ancestor (immediate or not) that is an instance of the given Class * or of a subclass of the given Class. */ public final boolean hasAncestor(Class<? extends AbstractFile> abstractFileClass) { AbstractFile ancestor = this; AbstractFile lastAncestor; do { if(abstractFileClass.isAssignableFrom(ancestor.getClass())) return true; lastAncestor = ancestor; ancestor = ancestor.getAncestor(); } while(lastAncestor!=ancestor); return false; }
/** * Returns the first ancestor of this file that is an instance of the given Class or of a subclass of it, * or <code>this</code> if this instance's class matches those criteria. Returns <code>null</code> if this * file has no such ancestor. * <br> * Note that this method will always return <code>this</code> if <code>AbstractFile.class</code> is specified. * * @param abstractFileClass a Class corresponding to an AbstractFile subclass * @return the first ancestor of this file that is an instance of the given Class or of a subclass of the given * Class, or <code>this</code> if this instance's class matches those criteria. Returns <code>null</code> if this * file has no such ancestor. */ public final <T extends AbstractFile> T getAncestor(Class<T> abstractFileClass) { AbstractFile ancestor = this; AbstractFile lastAncestor; do { if(abstractFileClass.isAssignableFrom(ancestor.getClass())) return (T) ancestor; lastAncestor = ancestor; ancestor = ancestor.getAncestor(); } while(lastAncestor!=ancestor); return null; }
@Override public FilePermissions getPermissions() { if(isSymlink()) return getCanonicalFile().getAncestor(FTPFile.class).permissions; return permissions; }
public boolean equals(Object o) { // Makes sure we're working with an abstract file. if(!(o instanceof AbstractFile)) return false; // Retrieves the actual file instance. // We might have received a Proxied or Cached file, so we need to make sure // we 'unwrap' that before comparing. AbstractFile file = ((AbstractFile)o).getAncestor(); // We only know how to compare one bookmark file to the other. if(file instanceof BookmarkFile) return bookmark.equals(((BookmarkFile)file).getBookmark()); return false; }
/** * Convenience method that returns the parent {@link AbstractArchiveFile} that contains this file. If this file * is an {@link AbstractArchiveFile} or an ancestor of {@link AbstractArchiveFile}, <code>this</code> is returned. * If this file is neither contained by an archive nor is an archive, <code>null</code> is returned. * * <p> * <b>Important note:</b> the returned {@link AbstractArchiveFile}, if any, may not necessarily be an * archive, as specified by {@link #isArchive()}. This is the case for files that were resolved as * {@link AbstractArchiveFile} instances based on their path, but that do not yet exist or were created as * directories. On the contrary, an existing archive will necessarily return a non-null value. * </p> * * @return the parent {@link AbstractArchiveFile} that contains this file */ public final AbstractArchiveFile getParentArchive() { if(hasAncestor(AbstractArchiveFile.class)) return getAncestor(AbstractArchiveFile.class); else if(hasAncestor(AbstractArchiveEntryFile.class)) return getAncestor(AbstractArchiveEntryFile.class).getArchiveFile(); return null; }
/** * Tests methods related to root drives (e.g. C:\). */ @Test public void testRootDriveMethods() { // The following test simply assert that the method doesn't produce an uncaught exception. LocalFile.hasRootDrives(); LocalFile localFile = (LocalFile)tempFile.getAncestor(LocalFile.class); localFile.guessRemovableDrive(); }
/** * 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; } }
checkCopyRemotelyPrerequisites(destFile, true, false); S3Object destObjectFile = destFile.getAncestor(S3Object.class);
List<ArchiveEntry> selectedEntries = new Vector<ArchiveEntry>(); for(int i=0; i<nbFiles; i++) { selectedEntries.add((ArchiveEntry)files.elementAt(i).getAncestor(AbstractArchiveEntryFile.class).getUnderlyingFileObject());
AbstractArchiveFile archiveFile = file.getAncestor(AbstractArchiveFile.class); ArchiveEntryIterator iterator = null;