List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:com.github.cereda.arara.langchecker.LanguageUtils.java
/** * Finds all language files from the provided directory. * @param directory The provided directory. * @return A list of files matching the language file pattern. *//*from w ww.java 2 s.c o m*/ public static List<File> findLanguages(File directory) { // we expect a directory, if not, halt if (!directory.isDirectory()) { // print error message System.err.println(WordUtils.wrap("Fatal exception: The provided argument could not " + "be resolved to a proper directory. I am afraid " + "I won't be able to continue. Please make sure the " + "argument resolves to a valid directory reference. " + "The application will halt now.", 60)); System.exit(1); } // we have a valid directory, in that case, return // a list of all files ending with .properties return new ArrayList( FileUtils.listFiles(directory, new SuffixFileFilter(".properties"), FalseFileFilter.FALSE)); }
From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java
/** * Detects whether using old configuration model and upgrades if necessary. * // w w w.j a va2 s . c o m * @param global * @throws SiteWhereException */ public static void migrateProjectStructureIfNecessary(IGlobalConfigurationResolver global) throws SiteWhereException { File root = new File(global.getConfigurationRoot()); if (!root.exists()) { throw new SiteWhereException("Configuration root does not exist."); } File templateFolder = new File(root, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_TEMPLATE_FOLDER); if (!templateFolder.exists()) { if (!templateFolder.mkdir()) { throw new SiteWhereException("Unable to create template folder."); } for (String filename : OLD_TEMPLATE_FILENAMES) { File templateFile = new File(root, filename); if (templateFile.exists()) { migrateTemplateFile(root, templateFolder, filename); migrateResources(root, templateFolder); break; } } } // Migrate tenant configuration files to separate directories. File tenants = new File(root, FileSystemTenantConfigurationResolver.TENANTS_FOLDER); if (!tenants.exists()) { if (!tenants.mkdir()) { throw new SiteWhereException("Unable to create tenant resources folder."); } } Collection<File> oldConfigs = FileUtils.listFiles(root, FileFilterUtils.suffixFileFilter("-tenant.xml"), null); for (File oldConfig : oldConfigs) { int dash = oldConfig.getName().lastIndexOf('-'); String tenantName = oldConfig.getName().substring(0, dash); File tenantFolder = new File(tenants, tenantName); try { FileUtils.copyDirectory(templateFolder, tenantFolder); File tenantConfig = new File(tenantFolder, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_CONFIGURATION_FILE + "." + FileSystemTenantConfigurationResolver.TENANT_SUFFIX_ACTIVE); if (tenantConfig.exists()) { tenantConfig.delete(); } FileUtils.moveFile(oldConfig, tenantConfig); oldConfig.delete(); } catch (IOException e) { throw new SiteWhereException("Unable to copy template folder for tenant."); } } }
From source file:android.databinding.tool.util.GenerationalClassUtil.java
private static void loadFromDirectory(File directory) { for (File file : FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { for (ExtensionFilter filter : ExtensionFilter.values()) { if (filter.accept(file.getName())) { InputStream inputStream = null; try { inputStream = FileUtils.openInputStream(file); Serializable item = fromInputStream(inputStream); if (item != null) { //noinspection unchecked sCache[filter.ordinal()].add(item); L.d("loaded item %s from file", item); }/*w w w.jav a 2 s. c om*/ } catch (IOException e) { L.e(e, "Could not merge in Bindables from %s", file.getAbsolutePath()); } catch (ClassNotFoundException e) { L.e(e, "Could not read Binding properties intermediate file. %s", file.getAbsolutePath()); } finally { IOUtils.closeQuietly(inputStream); } } } } }
From source file:com.denimgroup.threadfix.framework.engine.framework.JavaAndJspFrameworkChecker.java
@Nonnull @Override// w w w. j a v a 2s . co m @SuppressWarnings("unchecked") public FrameworkType check(@Nonnull ProjectDirectory directory) { FrameworkType frameworkType = FrameworkType.NONE; File webXML = directory.findWebXML(); if (webXML != null && webXML.exists()) { ServletMappings mappings = WebXMLParser.getServletMappings(webXML, directory); if (mappings != null) { frameworkType = mappings.guessApplicationType(); } } if (frameworkType == FrameworkType.SPRING_MVC) return frameworkType; // check for STRUTS Collection<File> configFiles = FileUtils.listFiles(directory.getDirectory(), new String[] { "xml", "properties" }, true); if (StrutsConfigurationChecker.check(configFiles)) { frameworkType = FrameworkType.STRUTS; return frameworkType; } // check for SPRING Collection<File> javaFiles = FileUtils.listFiles(directory.getDirectory(), new FileExtensionFileFilter("java"), TrueFileFilter.INSTANCE); for (File file : javaFiles) { if (SpringJavaConfigurationChecker.checkJavaFile(file)) { frameworkType = FrameworkType.SPRING_MVC; break; } } return frameworkType; }
From source file:com.denimgroup.threadfix.framework.util.java.EntityMappings.java
@SuppressWarnings("unchecked") public EntityMappings(@Nonnull File rootDirectory) { entityParsers = list();/*from ww w. j a va 2s . c o m*/ if (rootDirectory.exists() && rootDirectory.isDirectory()) { Collection<File> modelFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("java"), TrueFileFilter.TRUE); for (File file : modelFiles) { if (file != null && file.exists() && file.isFile()) { entityParsers.add(EntityParser.parse(file)); } } generateMap(); } }
From source file:com.dhenton9000.file.FileWatchers.java
/** * * scan the directory and return the files you find * * @return batch of files//from w w w.java2 s. c o m */ private List<File> findFiles() { String[] extensions = { this.fileExtension }; Collection<File> fCollection = FileUtils.listFiles(inputDir, extensions, false); return new ArrayList<>(fCollection); }
From source file:com.ecrimebureau.File.Hash.java
private void gethash() { File f = FileChooser.fileChoosers(JFileChooser.FILES_AND_DIRECTORIES);//new File(this.path); this.path = f.getAbsolutePath(); if (f.isFile()) { try {//ww w . java2s . co m jInternalFrame.setTitle("Hashing a Single File (1)"); String hash = getChecksum(path, algorithim); //or "SHA-256", "SHA-384", "SHA-512,SHA1" jTA.append(hash + " -> " + path + "\n"); System.out.println(hash); } catch (Exception e) { System.out.println("An error occured. hashing -> " + path + "\n"); jTA.append("An error occured. hashing -> " + path + "\n"); } } else if (f.isDirectory()) { isDirectory = true; Collection files = FileUtils.listFiles(f, new RegexFileFilter("^(.*?)"), DirectoryFileFilter.DIRECTORY); int totalNumberofFiles = files.size(); int startprogress = 1; jProgressBar.setMaximum(100); jInternalFrame.setTitle("Hashing " + totalNumberofFiles + " Files"); for (Object i : files.toArray(new File[] {})) { try { String hash = getChecksum(i.toString(), algorithim); //or "SHA-256", "SHA-384", "SHA-512,SHA1" System.out.println(hash + " -> " + i.toString() + "\n"); jTA.append(hash + " -> " + i.toString() + "\n"); //for the progress bar int percentageCompleted = (int) Math.round(startprogress * 100.0 / totalNumberofFiles); jProgressBar.setValue(percentageCompleted); //set the progress bar value jProgressBar.setString(String.valueOf(percentageCompleted) + "%");//the display string startprogress++; //increase the value //end progress bar } catch (Exception e) { System.out.println("An error occured. hashing -> " + i.toString() + "\n"); jTA.append("An error occured. hashing -> " + i.toString() + "\n"); } } } }
From source file:net.osrg.namazu.Experiment.java
public Experiment(File dir, String eqResultJsonPath, String jacocoPathRegex) throws IOException { this.dir = dir; this.resultJsonMap = new JSON().parse(new FileReader(new File(dir, eqResultJsonPath))); this.successful = (boolean) this.resultJsonMap.get("successful"); this.execFileLoaders = new ArrayList<ExecFileLoader>(); File[] jacocoFiles = FileUtils .listFiles(dir, new RegexFileFilter(jacocoPathRegex), DirectoryFileFilter.DIRECTORY) .toArray(new File[0]); Arrays.sort(jacocoFiles);/*w w w . j a va 2s . c o m*/ for (File jacocoFile : jacocoFiles) { ExecFileLoader loader = new ExecFileLoader(); // LOG.debug("Loading {}", jacocoFile); loader.load(jacocoFile); this.execFileLoaders.add(loader); } this.pattern = new ExperimentPattern(); }
From source file:com.denimgroup.threadfix.framework.util.CommonPathFinder.java
@Nonnull @SuppressWarnings("unchecked") private static List<String> getFilePathsFromDirectory(File rootFile, String fileExtension) { Collection<File> files = FileUtils.listFiles(rootFile, new FileExtensionFileFilter(fileExtension), TrueFileFilter.INSTANCE);// w w w. java2s. com List<String> strings = list(); for (File file : files) { strings.add(file.getAbsolutePath()); } return strings; }
From source file:beans.Recipe.java
/** * @return recipe type Application or Service by recipe directory. * @throws server.exceptions.ServerException * if found a not valid recipe file. *///from w w w .j a v a2 s. c om public Type getRecipeType() { Collection<File> files = FileUtils.listFiles(recipeRootDirectory, fileFilter, null); if (CollectionUtils.isEmpty(files)) { throw new ServerException(Messages.get("recipe.not.valid.1", Type.APPLICATION.fileIdentifier, Type.SERVICE.fileIdentifier)); } if (CollectionUtils.size(files) > 1) { throw new ServerException(Messages.get("recipe.not.valid.2", Type.APPLICATION.fileIdentifier, Type.SERVICE.fileIdentifier)); } File filename = CollectionUtils.first(files); return filename == null ? null : Type.getRecipeTypeByFileName(filename.getName()); }