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:io.github.bunnyblue.droidfix.classcomputer.gradleImpl.GradleImpl15.java

public static void extract() {
    File srcDir = new File(Configure.getInstance().getProguardJarFolder());
    Collection<File> jars = FileUtils.listFiles(srcDir, new String[] { "jar" }, true);
    List<File> jarsList = (List<File>) jars;
    File jar = jarsList.get(0);/*from w ww. j  a  v  a2 s. c  om*/
    String extractClasses = jar.getParentFile().getAbsolutePath() + File.separator
            + jar.getName().substring(0, jar.getName().indexOf(".jar"));
    Configure.getInstance().setTransformedClassDir(extractClasses);
    File targetFile = new File(extractClasses);
    try {
        FileUtils.deleteDirectory(targetFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ZipUtil.unpack(jar, targetFile);
}

From source file:download.XBRLFileCleaner.java

/**
 * Deletes all non xbrl file in the, master directory
 *
 * @throws java.io.IOException//from  w  ww.  j  a v  a  2s .  c  o m
 */
public void deleteNonXBRLFiles() throws IOException {
    File masterDirectory = new File(XBRLFilePaths.XBRL_FILING_DIRECTORY);

    // lists all files that are not directories except rfd object files
    Collection<File> files = FileUtils.listFiles(masterDirectory, new String[] { "zip", "xdr", "xsd", "xml" },
            true);

    // deletes the files that are not xbrl files
    for (File file : files) {
        if (!isXBRLFile(file.getName())) {
            Files.delete(Paths.get(file.getAbsolutePath()));
        } else {
            file.renameTo(
                    new File(file.getParent() + File.separatorChar + file.getParentFile().getName() + ".xml"));
        }
    }

}

From source file:com.igormaznitsa.nbmindmap.nb.refactoring.RefactoringUtils.java

public static Collection<FileObject> findAllMindMapsInFolder(final NonRecursiveFolder folder) {
    final File folderFile = FileUtil.toFile(folder.getFolder());
    if (folderFile == null) {
        return Collections.<FileObject>emptyList();
    } else {// w w  w.  j  av a2 s  . c o m
        final Collection<File> files = FileUtils.listFiles(folderFile, new String[] { "mmd", "MMD", "Mmd" },
                true);
        final Set<FileObject> result = new HashSet<FileObject>();
        for (final File f : files) {
            final FileObject fo = FileUtil.toFileObject(f);
            result.add(fo);
        }
        return result;
    }
}

From source file:cop.raml.processor.AbstractProcessorTest.java

protected static boolean runAnnotationProcessor(File dir) throws URISyntaxException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    Set<JavaFileObject> compilationUnits = new LinkedHashSet<>();

    for (File file : (List<File>) FileUtils.listFiles(dir, JAVA_FILE_FILTER, DirectoryFileFilter.INSTANCE))
        compilationUnits.add(new SimpleJavaFileObjectImpl(file, JavaFileObject.Kind.SOURCE));

    List<String> options = new ArrayList<>();
    //        options.put("-Apackages=com.bosch");
    //        options.put("-AfilterRegex=AnalysisController");
    //        options.put("-Aversion=0.8");
    options.add("-d");
    options.add("target");

    JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compilationUnits);
    task.setProcessors(Collections.singleton(new RestProcessor()));

    return task.call();
}

From source file:filesmodel.SoundModel.java

public void main(String[] args) throws IOException {

    File dir = new File("/Users/macbookpro/Documents/fichiers");
    String[] extensions = new String[] { "mp3", "flv" };

    List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
    files.stream().map((file) -> file.toPath().toString()).forEach((biir) -> {
        soundModel.add(createPlayer("file:///" + (biir).replace("\\", "/").replaceAll(" ", "%20")));
    });/*  w ww  .j a v a 2s .  c  om*/

}

From source file:exec.examples.EventExamples.java

/**
 * 1: Find all users in the dataset./*from ww w.ja  va 2s. c  o  m*/
 */
public static List<String> findAllUsers() {
    // This step is straight forward, as events are grouped by user. Each
    // .zip file in the dataset corresponds to one user.

    List<String> zips = Lists.newLinkedList();
    for (File f : FileUtils.listFiles(new File(DIR_USERDATA), new String[] { "zip" }, true)) {
        zips.add(f.getAbsolutePath());
    }
    return zips;
}

From source file:com.sonarsource.lits.Dump.java

static Map<String, Multiset<IssueKey>> load(File dir) {
    Map<String, Multiset<IssueKey>> result = new HashMap<>();
    for (File file : FileUtils.listFiles(dir, new String[] { EXT }, false)) {
        load(file, result);//from  w  ww .j  a va2s.c  o m
    }
    return result;
}

From source file:com.puzzle.module.send.listener.SendPathFileScan.java

public void run() {
    File sc = new File(FileDto.getSingleInstance().fileSendPath);
    if (!sc.exists()) {
        sc.mkdirs();// w  w  w. ja  v  a2 s .  c om
    }
    MessageSendExcutor excutor = new MessageSendExcutor();
    while (true) {

        Collection<File> fs = FileUtils.listFiles(sc, new String[] { "xml" }, false);

        for (File f : fs) {
            excutor.excute(f);

            if (FileDto.getSingleInstance().fileSendIsbak.equals("true")) {
                try {
                    FileUtils.copyFileToDirectory(f,
                            new File(FileDto.getSingleInstance().fileSendBakPath, DateUtil.getCurrDateMM()));
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }

            f.delete();
        }

        try {
            Thread.sleep(100L);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }

    }

}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * (1) Plain text with 4 columns: (1) the rank of the document in the list
 * (2) average agreement rate over queries (3) standard deviation of
 * agreement rate over queries. (4) average length of the document in the
 * rank.// ww  w.  j av  a 2  s . c  o m
 */
public static void statistics1(File inputDir, File outputDir) throws Exception {
    SortedMap<Integer, DescriptiveStatistics> mapDocumentRankObservedAgreement = new TreeMap<>();
    SortedMap<Integer, DescriptiveStatistics> mapDocumentRankDocLength = new TreeMap<>();

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            // add new entries
            if (!mapDocumentRankObservedAgreement.containsKey(rankedResult.rank)) {
                mapDocumentRankObservedAgreement.put(rankedResult.rank, new DescriptiveStatistics());
            }
            if (!mapDocumentRankDocLength.containsKey(rankedResult.rank)) {
                mapDocumentRankDocLength.put(rankedResult.rank, new DescriptiveStatistics());
            }

            Double observedAgreement = rankedResult.observedAgreement;

            if (observedAgreement == null) {
                System.err
                        .println("Observed agreement is null; " + f.getName() + ", " + rankedResult.clueWebID);
            } else {
                // update value
                mapDocumentRankObservedAgreement.get(rankedResult.rank).addValue(observedAgreement);
                mapDocumentRankDocLength.get(rankedResult.rank).addValue(rankedResult.plainText.length());
            }
        }
    }

    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats1.csv")));
    for (Map.Entry<Integer, DescriptiveStatistics> entry : mapDocumentRankObservedAgreement.entrySet()) {
        pw.printf(Locale.ENGLISH, "%d\t%.4f\t%.4f\t%.4f\t%.4f%n", entry.getKey(), entry.getValue().getMean(),
                entry.getValue().getStandardDeviation(), mapDocumentRankDocLength.get(entry.getKey()).getMean(),
                mapDocumentRankDocLength.get(entry.getKey()).getStandardDeviation());
    }
    pw.close();
}

From source file:download.XBRLUnzipper.java

/**
 * Unzips all files in the root folder/*from  w ww  .  ja v a 2  s. c  o  m*/
 *
 * @throws IOException
 * @throws net.lingala.zip4j.exception.ZipException
 */
public void unzipFiles() throws IOException, ZipException {
    File rootFolder = new File(XBRLFilePaths.XBRL_FILING_DIRECTORY);

    // search through the folder strcuture storing only the zip files and not the folder in the variable
    Collection<File> files = FileUtils.listFiles(rootFolder, new String[] { "zip" }, true);

    decompressFiles(files);
}