List of usage examples for org.apache.commons.io.filefilter IOFileFilter accept
public boolean accept(File file);
From source file:fr.duminy.jbackup.core.filter.JexlFileFilterTest.java
/** * Method copied from {@link org.apache.commons.io.filefilter.RegexFileFilterTestCase#assertFiltering(org.apache.commons.io.filefilter.IOFileFilter, java.io.File, boolean)}. * TODO check potential license issue.//from ww w . j av a2 s. c o m * * @param filter * @param file * @param expected * @throws Exception */ public void assertFiltering(final IOFileFilter filter, final File file, final boolean expected) throws Exception { // Note. This only tests the (File, String) version if the parent of // the File passed in is not null assertThat(filter.accept(file)) .as("Source(File) " + filter.getClass().getName() + " not " + expected + " for " + file) .isEqualTo(expected); if (file != null && file.getParentFile() != null) { assertThat(filter.accept(file.getParentFile(), file.getName())) .as("Source(File, String) " + filter.getClass().getName() + " not " + expected + " for " + file) .isEqualTo(expected); } }
From source file:net.sf.jvifm.control.FindCommand.java
private void find(File directory, IOFileFilter filter) { if (Thread.currentThread().isInterrupted()) return;/*from w w w . j a va 2s.c o m*/ File[] list = directory.listFiles(); if (list == null) { return; } int sz = list.length; for (int i = 0; i < sz; i++) { if (Thread.currentThread().isInterrupted()) return; File tmp = list[i]; if (filter.accept(tmp)) { // retlist.add(tmp); addSubFileInPanel(tmp); } if (tmp.isDirectory()) { find(tmp, filter); } } }
From source file:fr.duminy.jbackup.core.archive.FileCollector.java
private long collect(final List<SourceWithPath> collectedFiles, final Path source, final IOFileFilter directoryFilter, final IOFileFilter fileFilter, final Cancellable cancellable) throws IOException { final long[] totalSize = { 0L }; SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { @Override/* w w w .ja v a 2 s . c o m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { super.preVisitDirectory(dir, attrs); if ((directoryFilter == null) || source.equals(dir) || directoryFilter.accept(dir.toFile())) { return CONTINUE; } else { return SKIP_SUBTREE; } } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if ((cancellable != null) && cancellable.isCancelled()) { return TERMINATE; } super.visitFile(file, attrs); if (!Files.isSymbolicLink(file)) { if ((fileFilter == null) || fileFilter.accept(file.toFile())) { LOG.trace("visitFile {}", file.toAbsolutePath()); collectedFiles.add(new SourceWithPath(source, file)); totalSize[0] += Files.size(file); } } return CONTINUE; } }; Files.walkFileTree(source, visitor); return totalSize[0]; }
From source file:org.geoserver.config.GeoServerLoader.java
/** * Helper method for listing files in a directory. */// ww w.java 2 s .c o m Collection<File> list(File d, IOFileFilter filter) { if (d == null) { return Collections.EMPTY_LIST; } ArrayList<File> files = new ArrayList(); for (File f : d.listFiles()) { if (filter.accept(f)) { files.add(f); } } return files; }
From source file:org.kuali.kfs.gl.batch.EnterpriseFeederFileSetType.java
/** * Return set of file user identifiers from a list of files * /*www . j a v a 2 s .co m*/ * @param user user who uploaded or will upload file * @param files list of files objects * @return Set containing all user identifiers from list of files * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List) */ public Set<String> extractFileUserIdentifiers(Person user, List<File> files) { Set<String> extractedFileUserIdentifiers = new TreeSet<String>(); StringBuilder buf = new StringBuilder(); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()) .append(FILE_NAME_PART_DELIMITER); String prefixString = buf.toString(); IOFileFilter prefixFilter = new PrefixFileFilter(prefixString); IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX), new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX)); IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter); for (File file : files) { if (combinedFilter.accept(file)) { String fileName = file.getName(); if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.DATA_FILE_SUFFIX)); } else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, EnterpriseFeederService.RECON_FILE_SUFFIX)); } else { LOG.error("Unable to determine file user identifier for file name: " + fileName); throw new RuntimeException( "Unable to determine file user identifier for file name: " + fileName); } } } return extractedFileUserIdentifiers; }
From source file:org.kuali.kfs.module.cam.batch.AssetBarcodeInventoryInputFileType.java
/** * Return set of file user identifiers from a list of files * //from ww w .j av a 2s . c o m * @param user user who uploaded or will upload file * @param files list of files objects * @return Set containing all user identifiers from list of files * * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List) */ public Set<String> extractFileUserIdentifiers(Person user, List<File> files) { Set<String> extractedFileUserIdentifiers = new TreeSet<String>(); StringBuilder buf = new StringBuilder(); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()) .append(FILE_NAME_PART_DELIMITER); String prefixString = buf.toString(); IOFileFilter prefixFilter = new PrefixFileFilter(prefixString); IOFileFilter suffixFilter = new SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION); IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter); for (File file : files) { if (combinedFilter.accept(file)) { String fileName = file.getName(); if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) { extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)); } else { LOG.error("Unable to determine file user identifier for file name: " + fileName); throw new RuntimeException( "Unable to determine file user identifier for file name: " + fileName); } } } return extractedFileUserIdentifiers; }
From source file:org.wisdom.asciidoc.AsciidocMojo.java
/** * Compiles Asciidoc files from the internal and external assets to HTML. * * @throws MojoExecutionException if the processing failed *//*from w w w. j a v a 2 s . c om*/ public void execute() throws MojoExecutionException { if (!watch) { removeFromWatching(); } if (extensions == null || extensions.isEmpty()) { extensions = ImmutableList.of("ad", "asciidoc", "adoc"); } if (instance == null) { instance = getAsciidoctorInstance(); } final OptionsBuilder optionsBuilderExternals = OptionsBuilder.options().compact(compact) .safe(SafeMode.UNSAFE).eruby(eruby).backend(backend).docType(doctype).headerFooter(headerFooter) .inPlace(true); final OptionsBuilder optionsBuilderInternals = OptionsBuilder.options().compact(compact) .safe(SafeMode.UNSAFE).eruby(eruby).backend(backend).docType(doctype).headerFooter(headerFooter) .inPlace(true); if (templateEngine != null) { optionsBuilderExternals.templateEngine(templateEngine); optionsBuilderInternals.templateEngine(templateEngine); } if (templateDir != null) { optionsBuilderExternals.templateDir(templateDir); optionsBuilderInternals.templateDir(templateDir); } if (sourceHighlighter != null) { attributes.put("source-highlighter", sourceHighlighter); } if (embedAssets) { attributes.put("linkcss!", true); attributes.put("data-uri", true); } if (imagesDir != null) { attributes.put("imagesdir", imagesDir); } if (stylesheet != null) { attributes.put(Attributes.STYLESHEET_NAME, stylesheet); attributes.put(Attributes.LINK_CSS, true); } if (stylesheetDir != null) { attributes.put(Attributes.STYLES_DIR, stylesheetDir); } optionsBuilderExternals.attributes(attributes); optionsBuilderInternals.attributes(attributes); IOFileFilter filter = null; if (includes != null && includes.length != 0) { filter = new WildcardFileFilter(includes); if (excludes != null && excludes.length != 0) { filter = new AndFileFilter(filter, new NotFileFilter(new WildcardFileFilter(excludes))); } } try { for (File file : getResources(extensions)) { if (filter == null || filter.accept(file)) { renderFile(optionsBuilderExternals.asMap(), file); } } } catch (IOException e) { throw new MojoExecutionException("Error while compiling AsciiDoc file", e); } }