List of usage examples for org.apache.commons.vfs2 FileObject findFiles
FileObject[] findFiles(FileSelector selector) throws FileSystemException;
From source file:com.sonicle.webtop.vfs.VfsManager.java
public FileObject[] listStoreFiles(StoreFileType fileType, int storeId, String path) throws FileSystemException, WTException { FileObject tfo = null; try {/*from w w w . j a v a 2 s.c o m*/ tfo = getTargetFileObject(storeId, path); FileSelector selector = null; if (fileType.equals(StoreFileType.FILE)) { selector = new FileSelector(false, true); } else if (fileType.equals(StoreFileType.FOLDER)) { selector = new FileSelector(true, false); } else { selector = new FileSelector(true, true); } FileObject[] fos = tfo.findFiles(selector); Arrays.sort(fos, new TypeNameComparator()); return fos; } finally { IOUtils.closeQuietly(tfo); } }
From source file:org.apache.olingo.fit.utils.FSManager.java
public final FileObject[] find(final FileObject fo, final String ext) throws FileSystemException { return fo.findFiles(new FileSelector() { @Override/* w w w .j av a 2 s . co m*/ public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { return ext == null ? true : fileInfo.getFile().getName().getExtension().equals(ext); } @Override public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { return true; } }); }
From source file:org.datacleaner.user.upgrade.DataCleanerHomeUpgrader.java
private FileObject findUpgradeCandidate(FileObject target) throws FileSystemException { FileObject parentFolder = target.getParent(); List<FileObject> versionFolders = new ArrayList<>(); FileObject[] allFoldersInParent = parentFolder.findFiles(new FileDepthSelector(1, 1)); for (FileObject folderInParent : allFoldersInParent) { final String folderInParentName = folderInParent.getName().getBaseName(); if (folderInParent.getType().equals(FileType.FOLDER) && (!folderInParentName.equals(target.getName().getBaseName())) && (!candidateBlacklist.contains(folderInParentName))) { versionFolders.add(folderInParent); }//from w ww . ja va 2s.co m } List<FileObject> validatedVersionFolders = validateVersionFolders(versionFolders); if (!validatedVersionFolders.isEmpty()) { List<String> versions = new ArrayList<>(); for (FileObject validatedVersionFolder : validatedVersionFolders) { String baseName = validatedVersionFolder.getName().getBaseName(); versions.add(baseName); } final Comparator<String> comp = new VersionComparator(); String latestVersion = Collections.max(versions, comp); FileObject latestVersionFolder = null; for (FileObject validatedVersionFolder : validatedVersionFolders) { if (validatedVersionFolder.getName().getBaseName().equals(latestVersion)) { latestVersionFolder = validatedVersionFolder; } } return latestVersionFolder; } else { return null; } }
From source file:org.freedesktop.AbstractFreedesktopService.java
protected FileObject[] listDirs(FileObject dir) throws IOException { FileObject[] dirs = dir.findFiles(new DirectorySelector()); if (dirs == null) { throw new IOException("Directory could not be read."); }//w ww . ja va 2 s. c o m return dirs; }
From source file:org.freedesktop.desktopentry.DefaultDesktopEntryService.java
protected FileObject[] listEntries(FileObject dir) throws IOException { FileObject[] files = dir.findFiles(new DesktopSelector()); if (files == null) { throw new IOException("Directory could not be read."); }// w w w. j a va 2s . c o m return files; }
From source file:org.freedesktop.icons.Directory.java
public Directory(IconTheme theme, String key, Properties properties) throws ParseException, IOException { this.key = key; this.theme = theme; if (!properties.containsKey(SIZE)) { throw new ParseException("Size entry is required.", 0); }// ww w . jav a2s. c o m size = Integer.parseInt(properties.getProperty(SIZE)); context = properties.getProperty(CONTEXT); if (properties.containsKey(TYPE)) { String typeName = properties.getProperty(TYPE).toLowerCase(); try { type = Type.valueOf(typeName); } catch (IllegalArgumentException iae) { throw new ParseException("Invalid Type ' " + typeName + "' in " + key, 0); } } if (properties.containsKey(MAX_SIZE)) { maxSize = Integer.parseInt(properties.getProperty(MAX_SIZE)); } else { maxSize = size; } if (properties.containsKey(MIN_SIZE)) { minSize = Integer.parseInt(properties.getProperty(MIN_SIZE)); } else { minSize = size; } if (properties.containsKey(THRESHOLD)) { minSize = Integer.parseInt(properties.getProperty(THRESHOLD)); } for (FileObject base : theme.getBases()) { FileObject dirBase = base.resolveFile(getKey()); // Loop over the supported extensions so we get files in supported // extension order for (String extension : DefaultIconService.SUPPORTED_EXTENSIONS) { FileObject[] files = dirBase.findFiles(new ExtensionSelector(extension)); if (files != null) { for (FileObject file : files) { String name = file.getName().getBaseName(); int lidx = name.lastIndexOf('.'); String basename = name.substring(0, lidx); if (!cache.containsKey(basename)) { cache.put(basename, file); } } } } } }
From source file:org.freedesktop.mime.DefaultMIMEService.java
@Override protected Collection<MIMEEntry> scanBase(FileObject base) throws IOException { FileObject[] d = listDirs(base); MimeBase mimeBase = new MimeBase(); mimeBases.put(base, mimeBase);//from w w w . j a v a 2 s . co m if (d != null) { for (FileObject dir : d) { String family = dir.getName().getBaseName(); if (!family.equals("packages")) { Log.debug("Scanning family " + family); FileObject[] t = dir.findFiles(new FileSelector() { public boolean traverseDescendents(FileSelectInfo info) throws Exception { return info.getDepth() == 0; } public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getBaseName().toLowerCase().endsWith(".xml"); } }); for (FileObject type : t) { String typeName = type.getName().getBaseName().substring(0, type.getName().getBaseName().length() - 4); MIMEEntry entry = new MIMEEntry(family, typeName, type); Log.debug(" Adding type " + entry.getInternalName()); mimeBase.byType.put(entry.getInternalName(), entry); } } } } return mimeBase.byType.values(); }
From source file:org.freedesktop.wallpapers.DefaultWallpaperService.java
protected FileObject[] listImages(FileObject dir) throws IOException { FileSelector fileFilter = new ImageSelector(); FileObject[] files = dir.findFiles(fileFilter); if (files == null) { throw new IOException("Directory could not be read."); }//from www. j a v a 2 s.com return files; }
From source file:org.fuin.vfs2.filter.examples.AgeFileFilterExample.java
public static void main(String[] args) throws Exception { FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); // We are interested in files older than one day long cutoff = System.currentTimeMillis() - (24 * 60 * 60 * 1000); AgeFileFilter filter = new AgeFileFilter(cutoff); FileObject[] files = dir.findFiles(new FileFilterSelector(filter)); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }/*from w ww . j ava2s .c o m*/ }
From source file:org.fuin.vfs2.filter.examples.CanReadFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, showing how to print out a list of the current directory's // readable files: {//w w w . ja v a2 s. c om System.out.println("---CAN_READ---"); FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(CanReadFileFilter.CAN_READ)); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } } // Example, showing how to print out a list of the current directory's // un-readable files: { System.out.println("---CANNOT_READ---"); FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(CanReadFileFilter.CANNOT_READ)); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } } // Example, showing how to print out a list of the current directory's // read-only files: { System.out.println("---READ_ONLY---"); FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(CanReadFileFilter.READ_ONLY)); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } } }