List of usage examples for org.apache.commons.io FileUtils listFiles
public static Collection listFiles(File directory, String[] extensions, boolean recursive)
From source file:io.github.bunnyblue.droidfix.classcomputer.proguard.MappingMapper.java
public ArrayList<ClassObject> processRawClasses() { ArrayList<ClassObject> cacheClasses = new ArrayList<ClassObject>(); produce(Configure.getInstance().getPatchMapping()); File pathRoot = new File(Configure.getInstance().getTransformedClassDir()); Collection<File> clses = FileUtils.listFiles(pathRoot, new String[] { "class" }, true); for (File file : clses) { String path = file.getAbsolutePath(); String md5 = HashUtil.getClassMd5(path); String tmp = "classes" + File.separator + "debug"; path = path.replaceAll(pathRoot.getAbsolutePath(), ""); path = path.substring(1, path.indexOf(".class")); String classname = path.replaceAll(File.separator, "."); ClassObject classObject = new ClassObject(md5, classname); classObject.setProguardedClassName(hashtable.get(classname)); classObject.setLocalPath(file.getAbsolutePath()); cacheClasses.add(classObject);//w w w . j a v a2 s . com } int index = 0; for (ClassObject file : cacheClasses) { index++; //System.out.println(file.toString()+index); } return cacheClasses; }
From source file:com.opengamma.util.test.DbTest.java
private static void unzipSQLScripts() throws IOException { File zipScriptPath = new File(DbTool.getWorkingDirectory(), getZipPath()); for (File file : (Collection<File>) FileUtils.listFiles(zipScriptPath, new String[] { "zip" }, false)) { ZipUtils.unzipArchive(file, SCRIPT_INSTALL_DIR); }//from w w w.j a v a 2 s.co m }
From source file:com.textocat.textokit.commons.util.CorpusUtils.java
/** * Partition corpus files specified by filters. * * @param corpusDir corpus base directory * @param corpusFileFilter filter for corpus files * @param corpusSubDirFilter filter for corpus subdirectories. If null subdirectories will * be ignored. * @param partitionsNumber//w w w .ja v a2s . c o m * @return list of file sets (partitions) */ public static List<Set<File>> partitionCorpusByFileSize(File corpusDir, IOFileFilter corpusFileFilter, IOFileFilter corpusSubDirFilter, int partitionsNumber) { log.info("Partitioning corpus {} with file filter {} and subdir filter {}...", new Object[] { corpusDir.getAbsolutePath(), corpusFileFilter, corpusSubDirFilter }); // TODO implement an algorithm that is more robust to different file sizes // e.g. it should handle the case when there is no more files to include into the last partition if (partitionsNumber <= 0) { throw new IllegalArgumentException(String.format("Illegal number of partitions: %s", partitionsNumber)); } if (!corpusDir.isDirectory()) { throw new IllegalArgumentException(String.format("%s is not existing directory", corpusDir)); } final Deque<File> corpusFilesDeq; { List<File> corpusFiles = Lists .newArrayList(FileUtils.listFiles(corpusDir, corpusFileFilter, corpusSubDirFilter)); // sort by decreasing size to smooth differences between parts Collections.sort(corpusFiles, SizeFileComparator.SIZE_REVERSE); corpusFilesDeq = Lists.newLinkedList(corpusFiles); } // int totalSize = 0; for (File cf : corpusFilesDeq) { totalSize += cf.length(); } log.info("Corpus total size (bytes): {}", totalSize); List<FileBucket> buckets = Lists.newArrayListWithExpectedSize(partitionsNumber); // create empty parts for (int i = 0; i < partitionsNumber; i++) { buckets.add(new FileBucket()); } while (!corpusFilesDeq.isEmpty()) { File cf = corpusFilesDeq.pop(); buckets.get(0).add(cf); // resort: make the least bucket first Collections.sort(buckets); } // resort: make the largest bucket first Collections.sort(buckets, Collections.reverseOrder()); // log log.info("Corpus {} has been partitioned by file sizes. Result partitions:\n{}", corpusDir, Joiner.on('\n').join(buckets)); // transform List<Set<File>> result = Lists.newArrayList(); for (FileBucket b : buckets) { result.add(b.getFiles()); } // sanity checks if (result.size() != partitionsNumber || result.get(result.size() - 1).isEmpty()) { throw new IllegalStateException( "Illegal corpus partitioning result. Check previous log messages for details."); } return result; }
From source file:gr.aueb.cs.nlp.main.ExperimentTest.java
public static void walkFiles(String init) { Collection<File> files = FileUtils.listFiles(new File(init), FileFileFilter.FILE, DirectoryFileFilter.DIRECTORY); for (File f : files) { System.out.println(f.getName() + " " + f.isFile()); // qnStatEmbTrainSmall(f.getAbsolutePath(), f.getName()); //qnStatEmbTrainBig(f.getAbsolutePath(), f.getName()); }//from w w w. j a v a 2 s .c om }
From source file:ai.grakn.test.docs.DocTestUtil.java
public static Collection<File> allMarkdownFiles() { return FileUtils.listFiles(PAGES, new RegexFileFilter(".*\\.md"), DirectoryFileFilter.DIRECTORY); }
From source file:com.iterranux.droolsjbpmCore.runtime.environment.impl.LocalResourcesRuntimeEnvironmentFactory.java
/** * RuntimeEnvironment factory method that automatically registers all drools resources in the given * directory into the RuntimeEnvironment KieBase. * * @param pathToLocalResourcesDir either relative to the application root or absolute. * @return RuntimeEnvironment with local resources in default KieBase. *//*from ww w . j a va 2s .c o m*/ public RuntimeEnvironment newRuntimeEnvironment(String pathToLocalResourcesDir) { RuntimeEnvironmentBuilder builder = newDefaultRuntimeEnvironmentBuilder(); builder.registerableItemsFactory( registerableItemsFactoryFactory.newDroolsjbpmCoreDefaultRegisterableItemsFactory()); if (pathToLocalResourcesDir == null) { log.error( "No path to the local resources folder was set. Please set a valid path for the config option or don't instantiate a LocalResourcesRuntimeEnvironment."); } else { //Folder in file system: Add all assets in droolsjbpm resources folder to kbase File resourcesFolder = new File(pathToLocalResourcesDir); if (resourcesFolder.isDirectory()) { for (File file : FileUtils.listFiles(resourcesFolder, new ResourceTypeIOFileFilter(), TrueFileFilter.INSTANCE)) { builder.addAsset(ResourceFactory.newFileResource(file), ResourceType.determineResourceType(file.getName())); log.debug("Added resource (" + file.getName() + ") to the localResourcesRuntimeEnvironment."); } } else { log.error("The path (" + pathToLocalResourcesDir + ") to the local resources folder does not exist. Please set a valid path for the config option or don't instantiate a LocalResourcesRuntimeEnvironment."); } } return builder.get(); }
From source file:com.aionengine.gameserver.dataholders.DataLoader.java
/** * This method is supposed to be called from subclass to initialize data loading process.<br> * <br>//from www .j a v a2s .c om * This method is using file given in the constructor to load the data and there are two possibilities: * <ul> * <li>Given file is file is in deed the <b>file</b> then it's forwarded to {@link #loadFile(File)} method</li> * <li>Given file is a <b>directory</b>, then this method is obtaining list of all visible .txt files in this * directory and subdirectiores ( except hidden ones and those named "new" ) and call {@link #loadFile(File)} for * each of these files. * </ul> */ protected void loadData() { if (dataFile.isDirectory()) { Collection<?> files = FileUtils .listFiles(dataFile, FileFilterUtils .andFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils .notFileFilter(FileFilterUtils.nameFileFilter("new")), FileFilterUtils.suffixFileFilter(".txt")), HiddenFileFilter.VISIBLE), HiddenFileFilter.VISIBLE); for (Object file1 : files) { File f = (File) file1; loadFile(f); } } else { loadFile(dataFile); } }
From source file:com.sander.verhagen.DatabaseConnectionHelper.java
/** * Determine the database URL. The trick here is to determine it without * asking the user to tell us their Skype name. Note that this is currently * working for Windows, it should be not too difficult to make it work for * other platforms, if anyone desires this. Note that this is currently only * supporting a single account for each system user, it should not be too * difficult to make it work for multiple users<br/> * <br/>//from w w w . ja v a 2 s .c o m * The file location of the database should be something like: * <code>C:\Users\<Windows user>\Application Data\Skype\<Skype user>\main.db</code> * * @return database URL as determined */ String determineDatabaseUrl() { File skypeFolder = getSkypeFolder(); String[] extensions = { "db" }; Collection<File> files = FileUtils.listFiles(skypeFolder, extensions, true); List<File> mainFiles = new ArrayList<File>(); for (File file : files) { if (file.getName().equals("main.db")) { mainFiles.add(file); } } switch (mainFiles.size()) { case 0: throw new RuntimeException("No database file found. Looked here: " + skypeFolder); case 1: return "jdbc:sqlite:" + mainFiles.get(0).getAbsolutePath(); default: throw new RuntimeException("Multiple database files found; " + "don't know which one to choose"); } }
From source file:com.adobe.granite.samples.maintenance.impl.DeleteTempFilesTask.java
@Override public JobExecutionResult process(Job job, JobExecutionContext context) { log.info("Deleting old temp files from {}.", tempDir.getAbsolutePath()); Collection<File> files = FileUtils.listFiles(tempDir, new LastModifiedBeforeYesterdayFilter(), TrueFileFilter.INSTANCE);//from ww w . jav a 2s . c o m int counter = 0; for (File file : files) { log.debug("Deleting file {}.", file.getAbsolutePath()); counter++; file.delete(); // TODO - capture the output of delete() and do something useful with it } return context.result().message(String.format("Deleted %s files.", counter)).succeeded(); }
From source file:ca.nines.ise.cmd.Command.java
/** * Get a list of file paths from the command line arguments. * * @param cmd//from ww w. j a v a 2 s . c o m * @return File[] */ public File[] getFilePaths(CommandLine cmd) { Collection<File> fileList = new ArrayList<>(); List<?> argList = cmd.getArgList(); argList = argList.subList(1, argList.size()); String[] args = argList.toArray(new String[argList.size()]); if (argList.isEmpty()) { File dir = new File("input"); SuffixFileFilter sfx = new SuffixFileFilter(".txt"); fileList = FileUtils.listFiles(dir, sfx, TrueFileFilter.INSTANCE); } else { for (String name : args) { fileList.add(new File(name)); } } File[] files = fileList.toArray(new File[fileList.size()]); Arrays.sort(files); return files; }