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.ontotext.s4.multiThreadRequest.thread.ThreadReadFiles.java
private void init(File directory) { listOfAllFiles = FileUtils.listFiles(directory, new RegexFileFilter("^(.*?)"), DirectoryFileFilter.DIRECTORY); logger.info("We found " + listOfAllFiles.size() + " files."); }
From source file:com.gs.obevo.util.FileUtilsCobra.java
public static MutableCollection<File> listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {/*from w w w. j a v a 2 s. c om*/ return FastList.newList(FileUtils.listFiles(directory, fileFilter, dirFilter)); }
From source file:com.ctriposs.rest4j.server.util.FileClassNameScanner.java
/** * Construct map from fully qualified class name to filename whose sources are found under a given source directory. * All source files are required to have an extension. * * @param sourceDir the source directory to scan * @param requiredExtension only include files whose extension equals to this parameter * null if no specific extension is required * @return map from fully qualified class name to filename for scanned source files. *//*from w w w . j a v a 2s .co m*/ public static Map<String, String> scan(String sourceDir, String requiredExtension) { final String sourceDirWithSeparator = sourceDir.endsWith(File.separator) ? sourceDir : sourceDir + File.separator; final File dir = new File(sourceDirWithSeparator); if (!dir.exists() || !dir.isDirectory()) { return Collections.emptyMap(); } // suppress the warning because of inconsistent FileUtils interface @SuppressWarnings("unchecked") final Collection<File> files = (Collection<File>) FileUtils.listFiles(dir, null, true); final Map<String, String> classFileNames = new HashMap<String, String>(); final int prefixLength = sourceDirWithSeparator.length(); for (File f : files) { assert (f.exists() && f.isFile()); final int extensionIndex = f.getName().lastIndexOf('.'); final String filePath = f.getPath(); if (extensionIndex < 0 || !filePath.startsWith(sourceDirWithSeparator)) { continue; } final int reverseExtensionIndex = f.getName().length() - extensionIndex; final String classPathName = filePath.substring(prefixLength, filePath.length() - reverseExtensionIndex); if (classPathName.contains(".")) { // dot is not allowed in package name, thus not allowed in the directory path continue; } if (requiredExtension != null) { final String extension = f.getName().substring(extensionIndex + 1); if (!extension.equals(requiredExtension)) { continue; } } classFileNames.put(classPathName.replace(File.separator, "."), filePath); } return classFileNames; }
From source file:com.github.mojo.bdd.LettuceMojo.java
@Override protected void preExecute() throws MojoExecutionException, MojoFailureException { super.preExecute(); //see if a particular feature was specified to run if (System.getProperty(FEATURE) != null) { String featureName = System.getProperty(FEATURE); //we need to find the first file that corresponds to that feature name File testDir = new File(getWorkingDirectory(), "features"); Collection<File> features = FileUtils.listFiles(testDir, new String[] { "feature" }, true); boolean found = false; for (File feature : features) { if (feature.getName().equals(featureName + ".feature")) { found = true;//from w w w . j a v a2 s . co m getRequestOptions().add(feature.getAbsolutePath()); break; } } if (!found) { throw new MojoFailureException( "Unable to find " + featureName + ".feature under " + getWorkingDirectory() + "/features"); } } }
From source file:com.servicelibre.jxsl.dstest.sources.FolderDocumentSource.java
@Override public List<DocumentId> getDocumentIds() { List<DocumentId> documentIds = new ArrayList<DocumentId>(); Collection<File> files = FileUtils.listFiles(rootDir, extensions, recursive); Iterator<File> fileIt = files.iterator(); while (fileIt.hasNext()) { File file = fileIt.next(); documentIds.add(new DocumentId(file.getAbsolutePath())); }//from w ww. ja v a2s . c om return documentIds; }
From source file:fr.acxio.tools.agia.io.FilesOperationProcessorTest.java
@After public void tearDown() throws Exception { Collection<File> aFilesToDelete = FileUtils.listFiles(new File("target"), new WildcardFileFilter("*-input*.csv"), null); for (File aFile : aFilesToDelete) { FileUtils.deleteQuietly(aFile);/*w w w .ja va 2 s .c o m*/ } }
From source file:com.fengduo.bee.commons.core.lang.ClassLoaderUtils.java
public static List<?> load(String classpath, ClassFilter filter) throws Exception { List<Object> objs = new ArrayList<Object>(); URL resource = ClassLoaderUtils.class.getClassLoader().getResource(classpath); logger.debug("Search from {} ...", resource.getPath()); List<String> classnameArray; if ("jar".equalsIgnoreCase(resource.getProtocol())) { String file = resource.getFile(); String jarName = file.substring(file.indexOf("/"), (file.lastIndexOf("jar") + 3)); classnameArray = getClassNamesInPackage(jarName, classpath); } else {//from w ww . j a va2 s .co m Collection<File> listFiles = FileUtils.listFiles(new File(resource.getPath()), null, false); String classNamePrefix = classpath.replaceAll("/", "."); classnameArray = new ArrayList<String>(); for (File file : listFiles) { String name = file.getName(); if (name.endsWith(".class") == false) { continue; } if (StringUtils.contains(name, '$')) { logger.warn("NOT SUPPORT INNERT CLASS" + file.getAbsolutePath()); continue; } String classname = classNamePrefix + "." + StringUtils.remove(name, ".class"); classnameArray.add(classname); } } for (String classname : classnameArray) { try { Class<?> loadClass = ClassLoaderUtils.class.getClassLoader().loadClass(classname); if (filter != null && !filter.filter(loadClass)) { logger.error("{} {} ", classname, filter); continue; } // if (ClassLoaderUtil.class.isAssignableFrom(loadClass) == false) { // logger.error("{} ?????", classname); // continue; // } Object newInstance = loadClass.newInstance(); objs.add(newInstance); logger.debug("load {}/{}.class success", resource.getPath(), classname); } catch (Exception e) { e.printStackTrace(); logger.error("load " + resource.getPath() + "/" + classname + ".class failed", e); } } return objs; }
From source file:it.drwolf.ridire.utility.test.NewsCleaner.java
public NewsCleaner() throws IOException { // this.removeDirtyHtml(); File dir2 = new File(DIR2); List<File> dir2files = new ArrayList(FileUtils.listFiles(dir2, null, false)); for (File f : dir2files) { String content = FileUtils.readFileToString(f); content = StringEscapeUtils.unescapeHtml(content); content = content.replaceAll("\\\\\n", " "); File nf = new File(f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 5)); FileUtils.writeStringToFile(nf, content, "UTF-8"); }/*from w ww .ja va 2 s . c o m*/ }
From source file:AIR.Common.Utilities.Path.java
public static Collection<File> getFilesMatchingExtensions(String folder, final String[] extensions) { return (Collection<File>) FileUtils.listFiles(new File(folder), new IOFileFilter() { @Override/*www. ja v a 2 s . c om*/ public boolean accept(File arg0) { return matches(arg0.getAbsolutePath()); } @Override public boolean accept(File arg0, String arg1) { return matches(arg1); } private boolean matches(String file) { for (int counter1 = 0; counter1 < extensions.length; ++counter1) { if (StringUtils.endsWithIgnoreCase(file, extensions[counter1])) return true; } return false; } }, TrueFileFilter.INSTANCE); }
From source file:jinex.Jinex.java
public void indexJars(File dir) throws Exception { LoaderExecutor le = new LoaderExecutor(accismusProps); int count = 0; for (File jarFile : FileUtils.listFiles(dir, new String[] { "jar" }, true)) { JarMetadata jarMeta = new Parser().parseJar(jarFile); le.execute(new JarMetadataLoader(jarMeta)); System.out.println("Queued : " + jarFile.getName()); count++;//from w w w. j a va 2 s. c o m } le.shutdown(); System.out.println("Loaded " + count + " jars"); }