List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:org.apache.carbondata.core.datastore.filesystem.LocalCarbonFile.java
@Override public CarbonFile[] listFiles(final CarbonFileFilter fileFilter) { if (!file.isDirectory()) { return new CarbonFile[0]; }//from w w w . j av a2 s . c o m File[] files = file.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return fileFilter.accept(new LocalCarbonFile(pathname)); } }); if (files == null) { return new CarbonFile[0]; } CarbonFile[] carbonFiles = new CarbonFile[files.length]; for (int i = 0; i < carbonFiles.length; i++) { carbonFiles[i] = new LocalCarbonFile(files[i]); } return carbonFiles; }
From source file:com.doculibre.constellio.utils.persistence.ConstellioPersistenceContext.java
private static void generatePersistenceFile() { //Usefull for unit testing String basePersistenceFileName = System.getProperty("base-persistence-file"); if (basePersistenceFileName == null) { basePersistenceFileName = "persistence_derby.xml"; }/*from w ww . j a v a 2 s .c o m*/ File classesDir = ClasspathUtils.getClassesDir(); File metaInfDir = new File(classesDir, "META-INF"); File persistenceFile = new File(metaInfDir, "persistence.xml"); File persistenceBaseFile = new File(metaInfDir, basePersistenceFileName); if (persistenceFile.exists()) { persistenceFile.delete(); } // FIXME Using text files rather than Dom4J because of empty xmlns attribute generated... try { String persistenceBaseText = FileUtils.readFileToString(persistenceBaseFile); StringBuffer sbJarFile = new StringBuffer("\n"); File pluginsDir = PluginFactory.getPluginsDir(); for (String availablePluginName : ConstellioSpringUtils.getAvailablePluginNames()) { if (PluginFactory.isValidPlugin(availablePluginName)) { File pluginDir = new File(pluginsDir, availablePluginName); File pluginJarFile = new File(pluginDir, availablePluginName + ".jar"); String pluginJarURI = pluginJarFile.toURI().toString(); sbJarFile.append("\n"); sbJarFile.append("<jar-file>" + pluginJarURI + "</jar-file>"); } } File webInfDir = ClasspathUtils.getWebinfDir(); File libDir = new File(webInfDir, "lib"); File[] contellioJarFiles = libDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { boolean accept; if (pathname.isDirectory()) { accept = false; } else { List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames(); String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName()); accept = availablePluginNames.contains(jarNameWoutExtension); } return accept; } }); for (File constellioJarFile : contellioJarFiles) { URI constellioJarFileURI = constellioJarFile.toURI(); sbJarFile.append("\n"); sbJarFile.append("<jar-file>" + constellioJarFileURI + "</jar-file>"); } String persistenceText = persistenceBaseText.replaceAll("</provider>", "</provider>" + sbJarFile); FileUtils.writeStringToFile(persistenceFile, persistenceText); // persistenceFile.deleteOnExit(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.joliciel.jochre.search.JochreIndexBuilderImpl.java
public void updateIndex(File contentDir, boolean forceUpdate) { long startTime = System.currentTimeMillis(); try {/* www . jav a 2 s . c om*/ File[] subdirs = contentDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } }); for (File subdir : subdirs) { this.processDocument(subdir, forceUpdate); } indexWriter.commit(); indexWriter.close(); } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } finally { long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; LOG.info("Total time (ms): " + totalTime); } }
From source file:co.mcme.animations.MCMEAnimations.java
public void loadAnimations() { triggers.clear();/* w w w . ja v a 2 s. c om*/ animations.clear(); actions.clear(); File animationsPath = new File(MCMEAnimationsInstance.getDataFolder() + File.separator + "schematics" + File.separator + "animations"); if (!animationsPath.exists()) { animationsPath.mkdirs(); } File[] folders = animationsPath.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } }); for (File f : folders) { File[] confFile = f.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getAbsolutePath().endsWith(".json"); } }); if (confFile.length > 0) { //generate exception. //More than one configuration file } try { animations.add(MCMEAnimation.createInstance(confFile[0])); } catch (IOException | ParseException ex) { Logger.getLogger(MCMEAnimations.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.zenoss.zep.impl.PluginServiceImpl.java
private URLClassLoader createPluginClassLoader() throws ZenossException { final List<URL> urls = new ArrayList<URL>(); List<ZenPack> zenPacks; try {/*from www . j a v a 2s. c om*/ zenPacks = ZenPacks.getAllZenPacks(); } catch (ZenossException e) { logger.warn("Unable to find ZenPacks", e); return null; } for (ZenPack zenPack : zenPacks) { final File pluginDir = new File(zenPack.packPath("zep", "plugins")); if (!pluginDir.isDirectory()) { continue; } final File[] pluginJars = pluginDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile() && pathname.getName().endsWith(".jar"); } }); if (pluginJars != null) { for (File pluginJar : pluginJars) { try { urls.add(pluginJar.toURI().toURL()); logger.info("Loading plugin: {}", pluginJar.getAbsolutePath()); } catch (MalformedURLException e) { logger.warn("Failed to get URL from file: {}", pluginJar.getAbsolutePath()); } } } } URLClassLoader classLoader = null; if (!urls.isEmpty()) { logger.info("Discovered plug-ins: {}", urls); classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); } else { logger.info("No external plug-ins found."); } return classLoader; }
From source file:com.moss.appsnap.keeper.data.jaxbstore.JaxbStore.java
public void scan(ValueScanner<T> scanner) { File[] files = dataPath.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.exists() && pathname.getName().endsWith(".xml"); }/*from w w w .j ava 2 s . co m*/ }); for (File next : files) { try { final boolean keepScanning = scanner.scan((T) helper.readFromFile(next)); if (!keepScanning) { return; } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:com.peppe130.fireinstaller.core.CustomFileChooser.java
File[] listFiles(String mimeType) { File[] contents = parentFolder.listFiles(new FileFilter() { @Override//w w w . j av a 2 s .c o m public boolean accept(File file) { return getShowHiddenFiles() || !file.isHidden(); } }); List<File> results = new ArrayList<>(); if (contents != null) { MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); for (File fi : contents) { if (fi.isDirectory()) { results.add(fi); } else { if (fileIsMimeType(fi, mimeType, mimeTypeMap)) { results.add(fi); } } } Collections.sort(results, new FileSorter()); return results.toArray(new File[results.size()]); } return null; }
From source file:br.com.caelum.jstestrunner.JavascriptTestSuite.java
/** * Extend to configure a filter to select the Javascript test pages inside the Javascript test page folder. * The default is to accept only files with ".html" extension. * * @return A FileFilter that accepts the Javascript test page files *//* www. ja va 2 s .com*/ protected FileFilter testPageFileFilter() { return new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".html"); } }; }
From source file:maltcms.ui.nb.pipelineRunner.ui.MaltcmsLocalHostExecution.java
protected String locateMaltcmsJar(File baseDir) throws ConstraintViolationException { Logger.getLogger(MaltcmsLocalHostExecution.class.getName()).log(Level.FINE, "Checking files in dir: {0}", baseDir.getAbsolutePath());//from w w w . j a v a 2 s . co m File[] f = baseDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.getName().toLowerCase().endsWith("jar") && file.getName().toLowerCase().startsWith("maltcms")) { Logger.getLogger(MaltcmsLocalHostExecution.class.getName()).log(Level.FINE, "Found match: {0}", file.getName()); return true; } return false; } }); if (f.length > 1) { throw new ConstraintViolationException( "Found more than one candidate for maltcms.jar in base directory: " + baseDir.getAbsolutePath()); } return f[0].getName(); }
From source file:com.eviware.soapui.plugins.PluginManager.java
public void loadPlugins() { File[] pluginFiles = pluginDirectory.listFiles(new FileFilter() { @Override//from w w w. j a va 2 s . c o m public boolean accept(File pathname) { return pathname.isFile() && (pathname.getName().toLowerCase().endsWith(".jar") || pathname.getName().toLowerCase().endsWith(".zip")); } }); if (pluginFiles != null) { List<File> pluginFileList = new ArrayList<>(); ProductBodyguard productBodyguard = new ProductBodyguard(); for (File f : pluginFiles) { if (!productBodyguard.isKnown(f)) { SoapUI.log.warn("Plugin '" + f.getName() + "' is not loaded because it hasn't been signed by SmartBear Software."); } else { pluginFileList.add(f); } } resolver = null; try { resolver = new PluginDependencyResolver(pluginLoader, pluginFileList); pluginFileList = resolver.determineLoadOrder(); } catch (Exception e) { log.error("Couldn't resolve plugin dependency order. This may impair plugin functionality.", e); } long startTime = System.currentTimeMillis(); getForkJoinPool().invoke(new LoadPluginsTask(pluginFileList)); long timeTaken = System.currentTimeMillis() - startTime; log.info(pluginFileList.size() + " plugins loaded in " + timeTaken + " ms"); } }