List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:de.xirp.plugin.PluginLoader.java
/** * Looks for plugins in the plugins directory. Plugins which needs * are not full filled are not accepted. * //from w w w. ja v a2 s. co m * @param manager * instance of the plugin manager which is used for * notifying the application about the loading * progress. */ protected static void searchPlugins(PluginManager manager) { logClass.info(I18n.getString("PluginLoader.log.searchPlugins")); //$NON-NLS-1$ // Get all Files in the Plugin Directory with // Filetype jar File pluginDir = new File(Constants.PLUGIN_DIR); File[] fileList = pluginDir.listFiles(new FilenameFilter() { public boolean accept(@SuppressWarnings("unused") File dir, String filename) { return filename.endsWith(".jar"); //$NON-NLS-1$ } }); if (fileList != null) { double perFile = 1.0 / fileList.length; double cnt = 0; try { // Iterate over all jars and try to find // the plugin.properties file // The file is loaded and Information // extracted to PluginInfo // Plugin is added to List of Plugins for (File f : fileList) { String path = f.getAbsolutePath(); if (!plugins.containsKey(path)) { manager.throwLoaderProgressEvent( I18n.getString("PluginLoader.progress.searchingInFile", f.getName()), cnt); //$NON-NLS-1$ JarFile jar = new JarFile(path); JarEntry entry = jar.getJarEntry("plugin.properties"); //$NON-NLS-1$ if (entry != null) { InputStream input = jar.getInputStream(entry); Properties props = new Properties(); props.load(input); String mainClass = props.getProperty("plugin.mainclass"); //$NON-NLS-1$ PluginInfo info = new PluginInfo(path, mainClass, props); String packageName = ClassUtils.getPackageName(mainClass) + "." //$NON-NLS-1$ + AbstractPlugin.DEFAULT_BUNDLE_NAME; String bundleBaseName = packageName.replaceAll("\\.", "/"); //$NON-NLS-1$ //$NON-NLS-2$ for (Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) { JarEntry ent = entries.nextElement(); String name = ent.getName(); if (name.indexOf(bundleBaseName) != -1) { String locale = name .substring(name.indexOf(AbstractPlugin.DEFAULT_BUNDLE_NAME)); locale = locale.replaceAll(AbstractPlugin.DEFAULT_BUNDLE_NAME + "_", //$NON-NLS-1$ ""); //$NON-NLS-1$ locale = locale.substring(0, locale.indexOf(".properties")); //$NON-NLS-1$ Locale loc = new Locale(locale); info.addAvailableLocale(loc); } } PluginManager.extractAll(info); if (isPlugin(info)) { plugins.put(mainClass, info); } } } cnt += perFile; } } catch (IOException e) { logClass.error( I18n.getString("PluginLoader.log.errorSearchingforPlugins") + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } } checkAllNeeds(); logClass.info(I18n.getString("PluginLoader.log.searchPluginsCompleted") + Constants.LINE_SEPARATOR); //$NON-NLS-1$ }
From source file:ca.nines.ise.document.Corpus.java
/** * Return a list of Works, sorted by play code. * * @return Work[]/*from w w w.jav a 2 s . c om*/ * @throws IOException */ public Work[] getWorks() throws IOException { File[] dirs = ArrayUtils.addAll(new File(root.getCanonicalFile() + "/noTitlePage").listFiles(), new File(root.getCanonicalFile() + "/withTitlePage").listFiles()); for (File d : dirs) { File editions[] = d.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return Document.validName(name); } }); if (editions.length == 0) { continue; } Work w = new Work(d); for (File edition : editions) { w.addEdition(edition); } works.put(d.getName(), w); } Work[] list = works.values().toArray(new Work[works.size()]); Arrays.sort(list); return list; }
From source file:com.ogaclejapan.dotapk.manager.ApkFileManager.java
@Override public File getByName(final String apk) throws WebApiException { if (!apkDir.exists()) { throw WebApiException.asInternalServerError("does not exist: " + apkDir.getAbsolutePath()); }/* w ww.jav a 2 s .c o m*/ File[] files = apkDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches(Pattern.quote(apk)); } }); if (files == null || files.length == 0) { throw WebApiException.asNotFound("does not exist: " + apk); } return files[0]; }
From source file:org.fcrepo.examples.models.integration.ExampleNodeTypesIT.java
@Test public void testModelSets() throws Exception { for (final File f : modelSetsDirectory.listFiles()) { if (!f.isDirectory()) { logger.warn("Found a file in model sets directory: {}", f.getPath()); } else {/* www. ja va 2 s. co m*/ logger.debug("Testing model set: {}", f.getPath()); for (final File cnd : f.listFiles(new FilenameFilter() { @Override public final boolean accept(final File dir, final String name) { return name.endsWith(".cnd"); } })) { ingestNodeTypes(cnd); } } } }
From source file:de.andreasschoknecht.LS3.DocumentCollection.java
/** * Filters the PNML files in a directory, which possibly contains other files as well. * * @param dir The directory containing PNML files and possibly other files * @return the PNML files in the directory *//*from w w w .j a va 2 s. c om*/ private static String[] filterPNMLFiles(File dir) { // Check if directory can be accessed if (!dir.isDirectory()) { System.out.println("Error: could not open directory " + dir.getAbsolutePath()); System.exit(-2); } // Filter PNML files String[] fileList = dir.list(new FilenameFilter() { public boolean accept(File d, String name) { return name.endsWith(".pnml"); } }); return fileList; }
From source file:edu.uci.ics.asterix.installer.command.LogCommand.java
@Override protected void execCommand() throws Exception { InstallerDriver.initConfig(true);/* w w w. j a v a2s . c o m*/ String asterixInstanceName = ((LogConfig) config).name; AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.UNUSABLE, State.ACTIVE); PatternCreator pc = PatternCreator.INSTANCE; AsterixEventServiceClient eventrixClient = AsterixEventService .getAsterixEventServiceClient(instance.getCluster(), true, false); String outputDir = ((LogConfig) config).outputDir == null ? InstallerDriver.getManagixHome() + File.separator + "logdump" : ((LogConfig) config).outputDir; File f = new File(outputDir); String outputDirPath = f.getAbsolutePath(); if (!f.exists()) { boolean success = f.mkdirs(); if (!success) { throw new InstallerException("Unable to create output directory:" + outputDirPath); } } Patterns transferLogPattern = pc.getGenerateLogPattern(asterixInstanceName, instance.getCluster(), outputDirPath); eventrixClient.submit(transferLogPattern); File outputDirFile = new File(outputDirPath); final String destFileName = "log_" + new Date().toString().replace(' ', '_') + ".zip"; File destFile = new File(outputDirFile, destFileName); AsterixEventServiceUtil.zipDir(outputDirFile, destFile); String[] filesToDelete = outputDirFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return !name.equals(destFileName); } }); for (String fileS : filesToDelete) { f = new File(outputDirFile, fileS); if (f.isDirectory()) { FileUtils.deleteDirectory(f); } else { f.delete(); } } LOGGER.info("Log zip archive created at " + destFile.getAbsolutePath()); }
From source file:com.baomidou.framework.spring.SWPropertyPlaceholderConfigurer.java
/** * Java.exe-Dsw.home=D:/development?./* ww w . j a va 2 s. c o m*/ * * spring? <property name="swDeployConfigPathKey" value="sw.home"/>. * * @param propertiesPath * JVM?-Dsw.home=D:/developmentkey, ?sw.home */ public void setSwDeployConfigPathKey(String propertiesPath) { String configFilePath = System.getProperty(propertiesPath); if (configFilePath == null) throw new IllegalArgumentException(propertiesPath + "null, ?java.exe?, ?-D" + propertiesPath + "=D:/xxx"); try { // File file = new File(configFilePath); if (!file.exists() || !file.isDirectory()) throw new IllegalArgumentException(propertiesPath + "" + configFilePath + ", ???"); // File[] listPropertiesFiles = file.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.endsWith(PROPERTIES_SUFFX)) { return true; } return false; } }); // UrlResource? List<UrlResource> listResource = null; if (listPropertiesFiles != null && listPropertiesFiles.length > 0) { listResource = new ArrayList<UrlResource>(); for (File propertiesFile : listPropertiesFiles) { URI uri = propertiesFile.toURI(); UrlResource urlResource = new UrlResource(uri); listResource.add(urlResource); } } // if (listResource != null) { this.setLocations((Resource[]) listResource.toArray(new UrlResource[listResource.size()])); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:de.metanome.backend.algorithm_loading.AlgorithmFinder.java
/** * @param pathToFolder Path to search for jar files * @return an array of Files with ".jar" ending * @throws java.io.UnsupportedEncodingException if the file path could not be decoded in utf-8 *///from w ww . j av a2s .co m private File[] retrieveJarFiles(String pathToFolder) throws UnsupportedEncodingException { File folder = new File(URLDecoder.decode(pathToFolder, "utf-8")); File[] jars = folder.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String name) { return name.endsWith(".jar"); } }); if (jars == null) { jars = new File[0]; } return jars; }
From source file:eu.ggnet.dwoss.util.ImageFinder.java
public URL findImageUrlByName(final String head) { if (path == null || (!path.exists() && !path.isDirectory())) return errorUrl; String images[] = path.list(new FilenameFilter() { @Override//www. j a v a 2 s . c o m public boolean accept(File dir, String name) { if (name.equalsIgnoreCase(head + ".jpg")) return true; if (name.equalsIgnoreCase(head + ".gif")) return true; if (name.equalsIgnoreCase(head + ".png")) return true; return false; } }); if (images == null || images.length == 0) return noimageUrl; try { return new File(path, images[0]).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Error in URL creation", e); } }
From source file:dk.itst.oiosaml.sp.metadata.IdpMetadata.java
public static IdpMetadata getInstance() { if (instance == null) { Configuration conf = SAMLConfiguration.getSystemConfiguration(); String directory = SAMLConfiguration.getStringPrefixedWithBRSHome(conf, METADATA_DIRECTORY); File idpDir = new File(directory); File[] files = idpDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".xml"); }//from w w w . j a va 2s.c o m }); String protocol = conf.getString(Constants.PROP_PROTOCOL); List<EntityDescriptor> descriptors = new ArrayList<EntityDescriptor>(); for (File md : files) { log.info("Loading " + protocol + " metadata from " + md); try { XMLObject descriptor = SAMLUtil.unmarshallElementFromFile(md.getAbsolutePath()); if (descriptor instanceof EntityDescriptor) { descriptors.add((EntityDescriptor) descriptor); } else if (descriptor instanceof EntitiesDescriptor) { EntitiesDescriptor desc = (EntitiesDescriptor) descriptor; descriptors.addAll(desc.getEntityDescriptors()); } else { throw new RuntimeException("Metadata file " + md + " does not contain an EntityDescriptor. Found " + descriptor.getElementQName() + ", expected " + EntityDescriptor.ELEMENT_QNAME); } } catch (RuntimeException e) { log.error("Unable to load metadata from " + md + ". File must contain valid XML and have EntityDescriptor as top tag", e); throw e; } } if (descriptors.isEmpty()) { throw new IllegalStateException( "No IdP descriptors found in " + directory + "! At least one file is required."); } instance = new IdpMetadata(protocol, descriptors.toArray(new EntityDescriptor[descriptors.size()])); } return instance; }