/** * Creates a CachedFile instance for each of the AbstractFile instances in the given array. */ private AbstractFile[] createCachedFiles(AbstractFile files[]) { int nbFiles = files.length; for(int i=0; i<nbFiles; i++) files[i] = new CachedFile(files[i], true); return files; }
@Override public AbstractFile[] ls(FileFilter filter) throws IOException, UnsupportedFileOperationException { // Don't cache ls() result but create a CachedFile instance around each of the files if recursion is enabled AbstractFile files[] = file.ls(filter); if(recurseInstances) return createCachedFiles(files); return files; }
/** * Returns the current folder's children. The returned array contains {@link AbstractFile} instances, and not * CachedFile instances contrary to {@link #getCachedFiles()}. * * @return the current folder's children * @see #getCachedFiles() */ public synchronized AbstractFile[] getFiles() { int nbFiles = cachedFiles.length; AbstractFile[] files = new AbstractFile[nbFiles]; for(int i=0; i<nbFiles; i++) files[i] = cachedFiles[i]==null?null:((CachedFile)cachedFiles[i]).getProxiedFile(); return files; }
@Override public boolean isDirectory() { if(!isDirectorySet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!isDirectorySet) { isDirectory = file.isDirectory(); isDirectorySet = true; } return isDirectory; }
@Override public boolean isHidden() { if(!isHiddenSet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!isHiddenSet) { isHidden = file.isHidden(); isHiddenSet = true; } return isHidden; }
@Override public AbstractFile getRoot() { if(!getRootSet) { getRoot = file.getRoot(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances) getRoot = new CachedFile(getRoot, true); getRootSet = true; } return getRoot; }
/** * Returns the file located at the given index, not including the parent file. * Returns <code>null</code> if fileIndex is lower than 0 or is greater than or equals {@link #getFileCount() getFileCount()}. * * @param fileIndex index of a file, comprised between 0 and #getFileCount() * @return the file located at the given index, not including the parent file */ public synchronized AbstractFile getFileAt(int fileIndex) { // Need to check that row index is not larger than actual number of rows // because if table has just been changed (rows have been removed), // JTable may have an old row count value and may try to repaint rows that are out of bounds. if(fileIndex>=0 && fileIndex<fileArrayIndex.length) { return ((CachedFile)cachedFiles[fileArrayIndex[fileIndex]]).getProxiedFile(); } return null; }
@Override public AbstractFile[] ls(FilenameFilter filter) throws IOException, UnsupportedFileOperationException { // Don't cache ls() result but create a CachedFile instance around each of the files if recursion is enabled AbstractFile files[] = file.ls(filter); if(recurseInstances) return createCachedFiles(files); return files; } }
@Override public boolean exists() { if(!existsSet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!existsSet) { exists = file.exists(); existsSet = true; } return exists; }
@Override public AbstractFile getParent() { if(!getParentSet) { getParent = file.getParent(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances && getParent!=null) getParent = new CachedFile(getParent, true); getParentSet = true; } return getParent; }
/** * Returns the file located at the given row index. * This method can return the parent folder file ('..') if a parent exists and rowIndex is 0. * * <p>Returns <code>null</code> if rowIndex is lower than 0 or is greater than or equals * {@link #getRowCount() getRowCount()}.</p> * * @param rowIndex a row index, comprised between 0 and #getRowCount() * @return the file located at the given row index */ public synchronized AbstractFile getFileAtRow(int rowIndex) { AbstractFile file = getCachedFileAtRow(rowIndex); if(file==null) return null; else if(file instanceof CachedFile) return ((CachedFile)file).getProxiedFile(); else return file; }
@Override public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException { // Don't cache ls() result but create a CachedFile instance around each of the files if recursion is enabled AbstractFile files[] = file.ls(); if(recurseInstances) return createCachedFiles(files); return files; }
@Override public AbstractFile getCanonicalFile() { if(!getCanonicalFileSet) { getCanonicalFile = file.getCanonicalFile(); // Create a CachedFile instance around the file if recursion is enabled if(recurseInstances) { // AbstractFile#getCanonicalFile() may return 'this' if the file is not a symlink. In that case, // no need to create a new CachedFile, simply use this one. if(getCanonicalFile==file) getCanonicalFile = this; else getCanonicalFile = new CachedFile(getCanonicalFile, true); } getCanonicalFileSet = true; } return getCanonicalFile; }
public ChangeFolderThread(AbstractFile folder, boolean findWorkableFolder, boolean changeLockedTab) { // Ensure that we work on a raw file instance and not a cached one this.folder = (folder instanceof CachedFile)?((CachedFile)folder).getProxiedFile():folder; this.folderURL = folder.getURL(); this.findWorkableFolder = findWorkableFolder; this.changeLockedTab = changeLockedTab; setPriority(Thread.MAX_PRIORITY); }
int nbFiles = children.length; this.currentFolder = (folder instanceof CachedFile)?folder:new CachedFile(folder, true); AbstractFile file; for(int i=0; i<nbFiles; i++) { file = new CachedFile(children[i], true);
/** * Creates a new FileJob without starting it, and with no associated ProgressDialog. * * @param mainFrame mainFrame this job has been triggered by * @param files files which are going to be processed */ public FileJob(MainFrame mainFrame, FileSet files) { this.mainFrame = mainFrame; this.files = files; this.nbFiles = files.size(); this.baseSourceFolder = files.getBaseFolder(); // Create CachedFile instances around the source files in order to cache the return value of frequently accessed // methods. This eliminates some I/O, at the (small) cost of a bit more CPU and memory. Recursion is enabled // so that children and parents of the files are also cached. // Note: When cached methods are called, they no longer reflect changes in the underlying files. In particular, // changes of size or date could potentially not be reflected when files are being processed but this should // not really present a risk. AbstractFile tempFile; for(int i=0; i<nbFiles; i++) { tempFile = files.elementAt(i); files.setElementAt((tempFile instanceof CachedFile)?tempFile:new CachedFile(tempFile, true), i); } if (this.baseSourceFolder!=null) this.baseSourceFolder = (getBaseSourceFolder() instanceof CachedFile)?getBaseSourceFolder():new CachedFile(getBaseSourceFolder(), true); this.jobProgress = new JobProgress(this); }