Example usage for org.apache.commons.io FileUtils listFiles

List of usage examples for org.apache.commons.io FileUtils listFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils listFiles.

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:local.edg.ClassDB.java

/**
 * Generates a data base with class informations about a given application
 * // w  w w . j ava 2 s  .  c om
 * @param appClasses
 *            The classes of the application as directories to class-files or as path to jar-files.
 *            
 * @return Data base with class information.
 */
public static Map<String, Class> create(String[] appClasses) {
    ClassDbVisitor cv = new ClassDbVisitor();
    for (String s : appClasses) {
        File f = new File(s);
        if (f.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true);
            for (File cf : files) {
                try {
                    ClassReader cr = new ClassReader(new FileInputStream(cf));
                    cr.accept(cv, 0);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) {
            try {
                ZipFile zf = new ZipFile(f);
                Enumeration<? extends ZipEntry> en = zf.entries();
                while (en.hasMoreElements()) {
                    ZipEntry e = en.nextElement();
                    String name = e.getName();
                    if (name.endsWith(".class")) {
                        new ClassReader(zf.getInputStream(e)).accept(cv, 0);
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return cv.getClassDb();
}

From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDB.java

/**
 * Generates a database containing class information about given application classes
 * @param appClasses The classes of an application as directories to class-files or as path to jar-files
 * @return Database containing class information
 *//*from   w w  w.jav a  2  s.  c  o m*/
public static Map<String, Class> create(String[] appClasses) {
    ClassDBVisitor cv = new ClassDBVisitor();
    for (String s : appClasses) {
        File f = new File(s);
        if (f.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true);
            for (File cf : files) {
                try {
                    ClassReader cr = new ClassReader(new FileInputStream(cf));
                    cr.accept(cv, 0);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) {
            try {
                ZipFile zf = new ZipFile(f);
                Enumeration<? extends ZipEntry> en = zf.entries();
                while (en.hasMoreElements()) {
                    ZipEntry e = en.nextElement();
                    String name = e.getName();
                    if (name.endsWith(".class")) {
                        new ClassReader(zf.getInputStream(e)).accept(cv, 0);
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return cv.getClassDb();
}

From source file:edu.cuhk.hccl.Indexer.java

/**
 * Create index of RAMDirectory from a data folder with text files
 * //from w  w w . ja v  a2s  .c  om
 * @param dataSet
 * @throws IOException
 */
public static void createIndex(String dataSet) throws IOException {
    IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, analyzer);
    IndexWriter writer = new IndexWriter(index, config);

    Collection<File> files = FileUtils.listFiles(new File(dataSet), null, true);
    for (File file : files) {
        String path = file.getPath();
        String content = FileUtils.readFileToString(file);

        Document doc = new Document();

        doc.add(new StringField(PATH_FIELD, path, Field.Store.YES));
        doc.add(new Field(CONTENT_FIELD, content, TERM_STORED));

        writer.addDocument(doc);

        System.out.println("[INFO] Indexing file: " + path);
    }

    System.out.println("\n[INFO]" + files.size() + " files has been indexed.");

    writer.close();
}

From source file:hudson.plugins.simpleupdatesite.UpdateSite.java

/**
 * Init {@link UpdateSite} class with the .hpi files. This method should be
 * called after {@link UpdateSite} object is created, to construct update
 * info./*from  w  w  w .j  a va  2  s.c om*/
 * 
 * @param updateCenterBasePath
 *            the file path in which the "plugins" folder exist
 * @param urlBasePath
 *            base URL for downloading hpi files.
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public void init(File updateCenterBasePath, String urlBasePath) throws IOException {
    String downloadBaseUrl = urlBasePath + "/plugins";
    for (File hpiFile : (Collection<File>) FileUtils.listFiles(new File(updateCenterBasePath, "plugins"),
            new String[] { "hpi" }, false)) {
        try {
            Plugin plugin = new Plugin();
            plugin.init(hpiFile, downloadBaseUrl);
            if (isNewestPlugin(plugin)) {
                this.plugins.put(plugin.getName(), plugin);
            }
        } catch (IOException e) {
            System.out.printf("Fail to get the %s info\n", hpiFile.getName());
        }
    }
}

From source file:m3umaker.exFiles.java

public List getFiles(String Mdir, String[] extensions) {
    List<File> files = null;
    try {//from ww  w.  j av  a  2  s  .c  o m
        File dir = new File(Mdir);
        mDIR = dir.getCanonicalPath();
        files = (List<File>) FileUtils.listFiles(dir, extensions, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return files;
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.syntax.tagset.MappingsTest.java

@Test
public void testMappings() throws Exception {
    Collection<File> files = FileUtils.listFiles(
            new File("src/main/resources/de/tudarmstadt/ukp/dkpro/core/api/syntax/tagset"),
            new WildcardFileFilter("*.map"), TrueFileFilter.TRUE);

    assertTagsetMapping(files);/*from   w ww  .  j  av a2 s .  c om*/
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.tagset.MappingsTest.java

@Test
public void testMappings() throws Exception {
    Collection<File> files = FileUtils.listFiles(
            new File("src/main/resources/de/tudarmstadt/ukp/dkpro/core/api/lexmorph/tagset"),
            new WildcardFileFilter("*-pos.map"), TrueFileFilter.TRUE);

    assertTagsetMapping(files);//from w  ww . ja v a 2 s. c om
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.svmlib.SVMLibExperimentRunner.java

public void runCrossValidation(File dataDir) throws IOException {
    List<File> files = new ArrayList<File>(FileUtils.listFiles(dataDir, new String[] { "libsvm.txt" }, false));

    for (File testFile : files) {
        // create training files from the rest
        Set<File> trainingFiles = new HashSet<File>(files);
        trainingFiles.remove(testFile);//from w  w  w .j a  v  a2s . co m

        //            System.out.println("Training files: " + trainingFiles);
        System.out.println("Training files size: " + trainingFiles.size());
        System.out.println("Test file: " + testFile);

        runSingleFold(testFile, new ArrayList<File>(trainingFiles));

    }

}

From source file:com.leverno.ysbos.harvest.FileHarvester.java

public Collection<File> getFilesFor(File rootDirectory) {
    return FileUtils.listFiles(rootDirectory, new AlwaysAcceptFileFilter(), new AlwaysAcceptFileFilter());
}

From source file:com.r573.enfili.common.io.file.FileHelper.java

public static Collection<File> getAllFilesRecursively(File dir) {
    Collection<File> files = FileUtils.listFiles(dir, null, true);
    return files;
}