List of usage examples for java.io FileFilter accept
boolean accept(File pathname);
From source file:com.yahoo.yrlhaifa.haifa_utils.utils.FileUtils.java
private static void addToFileList(File base, List<File> files, FileFilter filter) { if (base.isFile()) { if (filter == null || filter.accept(base)) files.add(base);/*from w ww .j ava 2 s . c o m*/ } else if (base.isDirectory()) { for (File child : base.listFiles()) if (child.isFile() && (filter == null || filter.accept(child))) files.add(child); } else throw new IllegalArgumentException(base + " is not a file nor a directory"); }
From source file:org.opencms.util.CmsFileUtil.java
/** * Returns a list of all filtered files in the RFS.<p> * * If the <code>name</code> is not a folder the folder that contains the * given file will be used instead.<p> * * Despite the filter may not accept folders, every subfolder is traversed * if the <code>includeSubtree</code> parameter is set.<p> * * @param name a folder or file name//from www . j a v a2 s. c o m * @param filter a filter * @param includeSubtree if to include subfolders * * @return a list of filtered <code>{@link File}</code> objects */ public static List<File> getFiles(String name, FileFilter filter, boolean includeSubtree) { List<File> ret = new ArrayList<File>(); File file = new File(name); if (!file.isDirectory()) { file = new File(file.getParent()); if (!file.isDirectory()) { return ret; } } File[] dirContent = file.listFiles(); for (int i = 0; i < dirContent.length; i++) { File f = dirContent[i]; if (filter.accept(f)) { ret.add(f); } if (includeSubtree && f.isDirectory()) { ret.addAll(getFiles(f.getAbsolutePath(), filter, true)); } } return ret; }
From source file:com.adaptris.core.fs.CompositeFileFilter.java
/** * @see java.io.FileFilter#accept(java.io.File) *///from ww w. j a v a 2 s .co m @Override public boolean accept(File pathname) { int result = 0; for (FileFilter f : filters) { if (!quietMode) { log.trace("Checking {} is acceptable for {}", pathname.getAbsolutePath(), f.getClass().getSimpleName()); } result += f.accept(pathname) ? 1 : 0; } return result == filters.size(); }
From source file:org.dbflute.helper.io.compress.DfZipArchiver.java
protected void addAll(ArchiveOutputStream archive, File topDir, File targetFile, FileFilter filter) throws IOException { if (_suppressCompressSubDir && isSubDir(topDir, targetFile)) { return; // sub directory }/*from w w w . ja v a 2 s . c o m*/ if (!isTopDir(topDir, targetFile) && !filter.accept(targetFile)) { return; // not top directory and cannot accept it } if (targetFile.isDirectory()) { final File[] listFiles = targetFile.listFiles(); if (listFiles == null || listFiles.length == 0) { addDir(archive, topDir, targetFile); } else { for (File elementFile : listFiles) { addAll(archive, topDir, elementFile, filter); } } } else { addFile(archive, topDir, targetFile); } }
From source file:nicta.com.au.patent.document.CreateUnifiedDocuments.java
public boolean index(File dataDir, FileFilter filter) throws Exception { File[] listFiles = dataDir.listFiles(); for (File file : listFiles) { if (file.isDirectory()) { if (index(file, filter) == true) { this.writeUnifiedPatentDocument(this.analyze(file), file); }/*from w w w .ja v a2 s .c o m*/ } else { if (!file.isHidden() && file.exists() && file.canRead() && (filter == null || filter.accept(file))) { return true; } } } return false; }
From source file:it.tidalwave.northernwind.core.impl.model.DefaultSite.java
/******************************************************************************************************************* * * Traverse the file system with a {@link FilePredicate}. * * @param file the file to traverse * @param fileFilter the filter for directory contents * @param predicate the predicate/*from w w w .ja v a2s.com*/ * ******************************************************************************************************************/ private void traverse(final @Nonnull ResourcePath rootPath, final @Nonnull ResourceFile file, final @Nonnull FileFilter fileFilter, final @Nonnull FilePredicate predicate) { log.trace("traverse({}, {}, {}, {})", rootPath, file, fileFilter, predicate); final ResourcePath relativePath = file.getPath().urlDecoded().relativeTo(rootPath); if (fileFilter.accept(file)) { predicate.apply(file, relativePath); } for (final ResourceFile child : file.findChildren().results()) { traverse(rootPath, child, fileFilter, predicate); } }
From source file:de.ingrid.iplug.csw.dsc.cache.impl.DefaultFileCache.java
/** * Get record ids from a directory and all sub directories * @param directory The start directory/*from w w w . j a v a2s . com*/ * @return Set */ protected Set<String> getRecordIds(File directory) { Set<String> recordIds = new HashSet<String>(); FileFilter cacheFileFilter = new CacheFileFilter(); File[] files = directory.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (cacheFileFilter.accept(files[i])) recordIds.add(this.getIdFromFilename(files[i].getName())); if (files[i].isDirectory()) recordIds.addAll(getRecordIds(files[i])); } } return recordIds; }
From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java
private void extractZip(File zipFile, File output, FileFilter filter) throws IOException { Logger.info("Extracting ZIP file: %s to: %s", zipFile.getPath(), output.getPath()); if (!output.exists()) output.mkdirs();//from w ww . ja va 2s . c o m ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { File file = new File(output, entry.getName()); if (file.isDirectory()) continue; if (filter != null && !filter.accept(file)) continue; Logger.verbose("Unzipping %s", entry.getName()); FileUtils.touch(file); FileOutputStream out = new FileOutputStream(file.getPath()); int n; byte[] buffer = new byte[BLOCK_SIZE]; while ((n = zip.read(buffer)) != -1) { out.write(buffer, 0, n); } out.close(); zip.closeEntry(); Logger.verbose("Done extracting %s", entry.getName()); } zip.close(); Logger.debug("Done extracting ZIP."); }
From source file:org.ebayopensource.turmeric.plugins.maven.AbstractTurmericMojo.java
private void recursiveAddMatchingFiles(File dir, FileFilter filter) { for (File path : dir.listFiles()) { if (path.isFile()) { filter.accept(path); continue; }/* ww w . ja v a 2 s .c om*/ if (path.isDirectory()) { recursiveAddMatchingFiles(path, filter); } } }
From source file:org.lnicholls.galleon.util.FileGatherer.java
private static final void gatherDirectoryFromFileSystem(File directory, FileFilter suffixFilter, boolean recursive, int recursionDepth, GathererCallback callback) { // Limit recursion in case there is a recursive shortcut if (recursionDepth >= MAX_RECURSION_DEPTH) { log.info("Max recursion depth reached: " + directory.getPath()); return;/*from w ww .ja va 2s.c o m*/ } ++recursionDepth; // Get the list of all files in this directory. These may be media files, // directories, playlists, Windows shortcuts, or other unrecognized file // that should be ignored. We do not filter at this stage because we need // to apply several different filters later and we don't want to repeat // the listFiles() call for performance reasons. File[] directories = directory.listFiles(FileFilters.directoryFilter); if (directories != null) { if (recursive && directories.length > 0) { for (int i = 0; i < directories.length; ++i) { File dir = resolveLink(directories[i]); if (dir != null) // broken shortcut { gatherDirectoryFromFileSystem(dir, suffixFilter, true, recursionDepth, callback); } } } } directories = null; File[] files = directory.listFiles(); if (files != null) { // Iterate through the list of files, taking the correct action by type. for (int i = 0; i < files.length; ++i) { // Before applying file filters, dereference shortcuts (if any) File file = resolveLink(files[i]); if (file != null) // broken shortcut { if (suffixFilter.accept(file)) try { callback.visit(file, files[i]); } catch (Throwable ex) { } } } } files = null; // Decrement recursion depth --recursionDepth; }