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:com.ebay.logstorm.core.utils.PipelineEnvironmentLoaderForTest.java

private static File findAssemblyJarFile(String relativeToHomePath) {
    String projectRootDir = System.getProperty("user.dir");
    String assemblyModuleTargeDirPath = relativeToHomePath == null ? projectRootDir + "/assembly/target/"
            : projectRootDir + relativeToHomePath + "/assembly/target/";
    File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath);
    if (!assemblyTargeDirFile.exists()) {
        throw new IllegalStateException(
                assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under "
                        + projectRootDir + " to build the project firstly and retry");
    }/*from w w  w  .j a  v a2 s  . c  o m*/
    String jarFileNameWildCard = "logstorm-assembly-*.jar";
    Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile,
            new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE);
    if (jarFiles.size() == 0) {
        throw new IllegalStateException(
                "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry");
    }
    File jarFile = jarFiles.iterator().next();
    LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath());
    return jarFile;
}

From source file:com.quavo.util.FileUtilities.java

/**
 * Gets the class files inside a directory.
 *
 * @param directory The directory./*from   w  ww.j  a  v  a  2s .c om*/
 * @return An array of classes.
 * @throws IOException If an I/O exception is thrown.
 * @throws ClassNotFoundException If the class is not found.
 */
public static Class<?>[] getAllClasses(String directory) throws IOException, ClassNotFoundException {
    String path = Constants.OUTPUT_DIRECTORY + "/" + directory.replace('.', '/') + "/";
    File dir = new File(path);
    List<Class<?>> classes = new ArrayList<>();
    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.getName().endsWith(".class")) {
            classes.add(Class
                    .forName(file.getParent().replace("\\", ".").replace(Constants.OUTPUT_DIRECTORY + ".", "")
                            + '.' + file.getName().substring(0, file.getName().length() - 6)));
        }
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:com.bancvue.mongomigrate.MigrationFileRepository.java

@Override
public List<File> findAll() {
    return new ArrayList<File>(FileUtils.listFiles(dir, new String[] { "js" }, true));
}

From source file:fr.dutra.tools.maven.deptree.extras.JQueryTreeTableRenderer.java

@Override
protected Collection<File> getFilesToCopy() {
    return FileUtils.listFiles(staticDir,
            FileFilterUtils.or(new PathContainsFilter("treeTable"), new PathContainsFilter("common")),
            TrueFileFilter.TRUE);/* w w w  . j  a va 2 s  . co  m*/
}

From source file:com.denimgroup.threadfix.framework.impl.dotNetWebForm.MasterPageParser.java

public static Map<String, AspxParser> getMasterFileMap(File rootDirectory, Map<String, AscxFile> ascxFileMap) {
    if (rootDirectory == null) {
        throw new IllegalArgumentException("Can't pass null argument to getMasterFileMap()");
    } else if (!rootDirectory.isDirectory()) {
        throw new IllegalArgumentException("Can't pass a non-directory file argument to getMasterFileMap()");
    }/*  www.  java  2s .c  o m*/

    Map<String, AspxParser> parserMap = map();

    Collection masterFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("Master"),
            TrueFileFilter.INSTANCE);

    for (Object aspxFile : masterFiles) {
        if (aspxFile instanceof File) {
            File file = (File) aspxFile;

            AspxParser aspxParser = AspxParser.parse(file);
            AspxUniqueIdParser uniqueIdParser = AspxUniqueIdParser.parse(file, ascxFileMap);

            aspxParser.parameters.addAll(uniqueIdParser.parameters);
            parserMap.put(file.getName(), aspxParser);
        }
    }

    return parserMap;
}

From source file:com.enioka.jqm.tools.DeliverableTest.java

@Before
public void before() throws IOException {
    File jar = FileUtils.listFiles(new File("../jqm-ws/target/"), new String[] { "war" }, false).iterator()
            .next();//from   w  w w. ja va 2s . c o m
    FileUtils.copyFile(jar, new File("./webapp/jqm-ws.war"));
}

From source file:net.padaf.preflight.IsartorTargetFileInformation.java

public static List<IsartorTargetFileInformation> loadConfiguration(File root) throws Exception {
    // load config
    InputStream expected = IsartorTargetFileInformation.class.getResourceAsStream("/expected_errors.txt");
    Properties props = new Properties();
    props.load(expected);//from w w w  .  j  av a2s.  co m
    // list files
    List<IsartorTargetFileInformation> result = new ArrayList<IsartorTargetFileInformation>();
    if (root.isDirectory()) {
        Collection<?> col = FileUtils.listFiles(root, new String[] { "pdf" }, true);
        for (Object o : col) {
            File file = (File) o;
            IsartorTargetFileInformation info = getInformation(file, props);
            if (info == null) {
                continue;
            }
            result.add(info);
        }
    } else if (root.isFile()) {
        result.add(getInformation(root, props));
    }
    return result;
}

From source file:com.liferay.ide.core.util.FileListing.java

public static List<IPath> getFileListing(File dir, String fileType) {
    Collection<File> files = FileUtils.listFiles(dir, new String[] { fileType }, true);

    Stream<File> stream = files.stream();

    return stream.filter(file -> file.exists()).map(file -> new Path(file.getPath()))
            .collect(Collectors.toList());
}

From source file:core.Helpers.java

public String[] getApplicants() {
    String[] dataformats = { "asdp", "jpeg" };
    LinkedList<File> j = (LinkedList<File>) FileUtils.listFiles(new File("applicants"), dataformats, false);
    String[] al = new String[j.size()];
    for (int i = 0; i < j.size(); i++) {
        al[i] = (j.get(i).getName().toString().replace(".asdp", ""));
    }/*from   w w  w .  j av a  2s . c o  m*/

    return al;
}

From source file:com.googlecode.dex2jar.test.ResTest.java

@Test
public void test() throws Exception {
    File dir = new File("target/test-classes/res");
    Map<String, List<File>> m = new HashMap<String, List<File>>();
    for (File f : FileUtils.listFiles(dir, new String[] { "class" }, false)) {
        String name = FilenameUtils.getBaseName(f.getName());

        int i = name.indexOf('$');
        String z = i > 0 ? name.substring(0, i) : name;
        List<File> files = m.get(z);
        if (files == null) {
            files = new ArrayList<File>();
            m.put(z, files);//from  w w w  .ja  va  2s. c o  m
        }
        files.add(f);
    }

    List<Exception> exes = new ArrayList<Exception>();
    System.out.flush();
    int count = 0;
    for (Entry<String, List<File>> e : m.entrySet()) {
        String name = e.getKey();
        count++;
        try {
            File dex = TestUtils.dex(e.getValue(), new File(dir, name + ".dex"));
            File distFile = new File(dex.getParentFile(),
                    FilenameUtils.getBaseName(dex.getName()) + "_dex2jar.jar");
            Dex2jar.from(dex).reUseReg().skipDebug().optimizeSynchronized().topoLogicalSort().to(distFile);
            TestUtils.checkZipFile(distFile);
            System.out.write('.');
        } catch (Exception ex) {
            exes.add(ex);
            System.out.write('X');
        }
        if (count % 5 == 0) {
            System.out.write('\n');
        }
        System.out.flush();
    }
    System.out.flush();
    System.out.println();
    if (exes.size() > 0) {
        for (Exception ex : exes) {
            ex.printStackTrace(System.err);
        }
        throw new RuntimeException("there are " + exes.size() + " errors while translate");
    }
}