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:it.plugins.Project.java

public static Iterable<String> allFilesInDir(final String dirPath) {
    Collection<File> files = FileUtils.listFiles(new File(basedir(), dirPath), null, true);
    return from(files).transform(new Function<File, String>() {
        @Nullable/*from   w  w w.  ja  v a2  s.c om*/
        public String apply(File file) {
            // transforms /absolute/path/to/src/java/Foo.java to src/java/Foo.java
            String filePath = FilenameUtils.separatorsToUnix(file.getPath());
            return dirPath + StringUtils.substringAfterLast(filePath, dirPath);
        }
    });
}

From source file:es.molabs.io.utils.FileHelper.java

public static URL[] getFiles(URL path, boolean recursive, String... extensions) throws IOException {
    URL[] urls = null;/*w w w . j  a  va2  s. c  o  m*/

    try {
        Collection<File> fileCollection = FileUtils.listFiles(new File(path.toURI()), extensions, recursive);
        urls = new URL[fileCollection.size()];

        Iterator<File> iterator = fileCollection.iterator();
        int index = 0;
        while (iterator.hasNext()) {
            File file = iterator.next();

            urls[index++] = file.toURI().toURL();
        }
    } catch (URISyntaxException USe) {
        throw new IOException(USe);
    }

    return urls;
}

From source file:com.codercowboy.photo.organizer.service.PhotoIndexer.java

public static List<Photo> indexDirectory(String directoryAbsolutePath) throws Exception {
    File directory = new File(directoryAbsolutePath);
    if (!directory.exists()) {
        throw new IOException("Directory for indexing does not exist: " + directoryAbsolutePath);
    }//from w ww .  j  ava 2  s  . c o  m
    if (!directory.canRead()) {
        throw new IOException(
                "Cannot read directory for indexing, permission denied: " + directoryAbsolutePath);
    }
    List<Photo> photos = new LinkedList<>();
    for (File f : FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        //TODO: this should be externally configurable
        if (".DS_Store".equals(f.getName())) {
            continue;
        }
        photos.add(indexFile(f));
    }
    return photos;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java

/**
 * Lists all xml files and throw an IOException if no XML files were found
 *
 * @param inputDir input dir//from  ww w.j a va 2  s .c  o  m
 * @return list of xml files
 * @throws IOException exception
 */
public static List<File> listXmlFiles(File inputDir) throws IOException {
    ArrayList<File> files = new ArrayList<>(FileUtils.listFiles(inputDir, new String[] { "xml" }, false));

    if (files.isEmpty()) {
        throw new IOException("No xml files found in " + inputDir);
    }

    return files;
}

From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.Features2Arff.java

@SuppressWarnings("unchecked")
private static void toArffFile(Dataset dataset) throws IOException {
    System.out.println("Generating ARFF file");

    Collection<File> files = FileUtils.listFiles(new File(FEATURES_DIR + "/" + dataset.toString()),
            new String[] { "txt" }, true);

    String arffString = toArffString(dataset, files);

    FileUtils.writeStringToFile(new File(MODELS_DIR + "/" + dataset.toString() + ".arff"), arffString);

    System.out.println(" - done");
}

From source file:ch.cyberduck.core.aquaticprime.License.java

/**
 * @return Null if no license found//from  w  w  w.  j  a  va  2  s  .  c  om
 */
public static License find() {
    final Collection<File> licenses = FileUtils.listFiles(new File(LocalFactory
            .createLocal(Preferences.instance().getProperty("application.support.path")).getAbsolute()),
            new SuffixFileFilter(".cyberducklicense"), FalseFileFilter.FALSE);
    for (File license : licenses) {
        return new License(LocalFactory.createLocal(license));
    }
    log.info("No license found");
    return License.EMPTY;
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.data.util.DataUtil.java

public static Map<String, String> getAllDatasets(String path, String[] extensions) throws IOException {

    Map<String, String> datasetMap = new HashMap<String, String>();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (Resource resource : resolver.getResources(path)) {
        for (File datasetFile : FileUtils.listFiles(resource.getFile(), extensions, true)) {
            datasetMap.put(datasetFile.getAbsolutePath(), datasetFile.getParentFile().getName());
        }//from  w  w  w  .j  a v a 2 s  .com
    }

    return datasetMap;
}

From source file:net.bpelunit.util.ZipUtil.java

public static void zipDirectory(File directory, File zipFile) throws IOException {
    @SuppressWarnings("unchecked")
    Collection<File> files = FileUtils.listFiles(directory, null, true);

    FileOutputStream fzos = null;
    ZipOutputStream zos = null;/*from ww w  .  j a  v a 2 s  .c o  m*/
    try {
        fzos = new FileOutputStream(zipFile);
        zos = new ZipOutputStream(fzos);

        for (File f : files) {
            String fileNameInZIP = directory.toURI().relativize(f.toURI()).getPath();
            ZipEntry zipEntry = new ZipEntry(fileNameInZIP);
            zos.putNextEntry(zipEntry);
            FileInputStream fileInputStream = new FileInputStream(f);
            try {
                IOUtils.copy(fileInputStream, zos);
            } finally {
                IOUtils.closeQuietly(fileInputStream);
            }
        }
    } finally {
        IOUtils.closeQuietly(zos);
        IOUtils.closeQuietly(fzos);
    }
}

From source file:com.sun.star.lib.loader.FileFind.java

/**
 * Looks for files recursively in a directory tree
 * @param inFolder/*from   w  ww  .j  a v a  2 s  .c o  m*/
 * @param findTheseFiles
 * @return
 */
public static URL[] findFiles(String inFolder, String[] findTheseFiles) {
    List<URL> urls = new ArrayList<URL>(0);
    Collection<File> files = FileUtils.listFiles(new File(inFolder), new NameFileFilter(findTheseFiles),
            TrueFileFilter.INSTANCE);
    for (File file : files) {
        try {
            urls.add(file.toURI().toURL());
        } catch (MalformedURLException ex) {
            log.error("error while locating jar", ex);
        }
    }
    return urls.toArray(new URL[urls.size()]);
}

From source file:cso.AdvancedBox.java

public void setToApplicantBox() {
    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 ww w .j av  a 2s.  co  m*/
    this.setModel(new javax.swing.DefaultComboBoxModel(al));
    type = "applicant";
}