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

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

Introduction

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

Prototype

public static Iterator iterateFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Allows iteration over the files in a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:org.mili.core.io.DefaultFileWalker.java

@Override
public void walk(UnaryProcedure<File> f) {
    Validate.notNull(f, "walk function cannot be null!");
    Iterator<?> fs = FileUtils.iterateFiles(this.root, new String[] { "jar" }, true);
    while (fs.hasNext()) {
        File f0 = (File) fs.next();
        if (f0.isFile()) {
            f.run(f0);//from   ww w  .j a  v a2s  .c om
        }
    }
}

From source file:org.nanoko.coffee.mill.processors.JpegTranProcessor.java

/**
 * Iterates over project resources and optimize all JPEG files.
 *
 * @throws org.nanoko.coffee.mill.processors.Processor.ProcessorException
 *//*w  ww  .  j  av a  2s.c o m*/
@Override
public void processAll() throws ProcessorException {
    if (jpegTranExec == null) {
        return;
    }

    if (!mojo.getWorkDirectory().exists()) {
        return;
    }

    Iterator<File> files = FileUtils.iterateFiles(mojo.workDir, new String[] { "jpg", "jpeg" }, true);
    while (files.hasNext()) {
        File file = files.next();
        optimize(file);
    }
}

From source file:org.nanoko.coffee.mill.processors.OptiPNGProcessor.java

/**
 * Iterates over project resources and optimize all PNG files.
 *
 * @throws ProcessorException/*from   www  .j  a va  2 s  .  com*/
 */
@Override
public void processAll() throws ProcessorException {
    if (optiPNGExec == null) {
        return;
    }

    if (!mojo.getWorkDirectory().exists()) {
        return;
    }

    Iterator<File> files = FileUtils.iterateFiles(mojo.workDir, new String[] { "png" }, true);
    while (files.hasNext()) {
        File file = files.next();
        optimize(file);
    }
}

From source file:org.nanoko.coffeemill.mojos.processresources.OptiJpegMojo.java

public void execute() throws MojoExecutionException {
    if (isSkipped()) {
        return;//www  . j a v  a 2s  .  c om
    }

    jpegTranExec = FSUtils.findExecutableInPath(EXECUTABLE_NAME);

    if (jpegTranExec == null) {
        getLog().error("Cannot optimize JPEG files - " + EXECUTABLE_NAME + " not installed.");
        return;
    }

    if (!getWorkDirectory().exists()) {
        return;
    }

    getLog().info("Invoking jpegtran : " + jpegTranExec.getAbsolutePath());
    Iterator<File> files = FileUtils.iterateFiles(getWorkDirectory(), new String[] { "jpg", "jpeg" }, true);
    while (files.hasNext()) {
        File file = files.next();
        try {
            optimize(file);
        } catch (WatchingException e) {
            throw new MojoExecutionException("Error during execute() on OptiJpegMojo", e);
        }
    }
}

From source file:org.nanoko.coffeemill.mojos.processresources.OptiPngMojo.java

public void execute() throws MojoExecutionException {

    if (isSkipped()) {
        return;//from  w  w w .j a v a  2  s  .  co m
    }

    optiPNGExec = FSUtils.findExecutableInPath(EXECUTABLE_NAME);

    if (optiPNGExec == null) {
        getLog().error("Cannot optimize PNG files - optipng not installed.");
        return;
    }

    if (!getWorkDirectory().exists()) {
        return;
    }

    getLog().info("Invoking optipng : " + optiPNGExec.getAbsolutePath());
    Iterator<File> files = FileUtils.iterateFiles(getWorkDirectory(), new String[] { "png" }, true);
    while (files.hasNext()) {
        File file = files.next();
        try {
            optimize(file);
        } catch (WatchingException e) {
            throw new MojoExecutionException("Error during execute() on OptiPngMojo", e);
        }
    }
}

From source file:org.nd4j.linalg.util.Paths.java

/**
 * Check if a file exists in the path//  ww w.  ja  va 2s.  c o m
 * @param name the name of the file
 * @return true if the name exists
 * false otherwise
 */
public static boolean nameExistsInPath(String name) {
    String path = System.getenv(PATH_ENV_VARIABLE);
    String[] dirs = path.split(File.pathSeparator);
    for (String dir : dirs) {
        File dirFile = new File(dir);
        if (!dirFile.exists())
            continue;

        if (dirFile.isFile() && dirFile.getName().equals(name))
            return true;
        else {
            Iterator<File> files = FileUtils.iterateFiles(dirFile, null, false);
            while (files.hasNext()) {
                File curr = files.next();
                if (curr.getName().equals(name))
                    return true;
            }

        }
    }

    return false;
}

From source file:org.nickelproject.util.sources.SourceUtil.java

public static Source<File> files(final String directoryName, final String[] suffices, final boolean recursive) {
    return new Source<File>() {

        @Override//ww w . j  a  v a2 s  .c o  m
        public CloseableIterator<File> iterator() {
            return TrivialCloseableIterator
                    .create(FileUtils.iterateFiles(new File(directoryName), suffices, recursive));
        }

        @Override
        public Source<? extends Source<File>> partition(final int sizeGuideline) {
            return Sources.singleton(this);
        }

        @Override
        public int size() {
            return Source.unknownSize;
        }
    };
}

From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java

/**
 * Recursively traverse the directory to find the most recently modified
 * file within it.//from w  w  w . ja  va  2 s .c o  m
 *
 * @param formDir
 * @return lastModifiedDate of the most recently modified file.
 */
public static long getMostRecentlyModifiedDate(File formDir) {
    long lastModifiedDate = formDir.lastModified();
    Iterator<File> allFiles = FileUtils.iterateFiles(formDir, null, true);
    while (allFiles.hasNext()) {
        File f = allFiles.next();
        if (f.lastModified() > lastModifiedDate) {
            lastModifiedDate = f.lastModified();
        }
    }
    return lastModifiedDate;
}

From source file:org.opennms.core.test.rest.AbstractSpringJerseyRestTestCase.java

protected static void cleanUpImports() {
    final Iterator<File> fileIterator = FileUtils.iterateFiles(new File("target/test/opennms-home/etc/imports"),
            null, true);/*  w  ww  .jav  a  2  s  .c o  m*/
    while (fileIterator.hasNext()) {
        if (!fileIterator.next().delete()) {
            LOG.warn("Could not delete file: {}", fileIterator.next().getPath());
        }
    }
}

From source file:org.opennms.web.rest.AbstractSpringJerseyRestTestCase.java

protected void cleanUpImports() {
    final Iterator<File> fileIterator = FileUtils.iterateFiles(new File("target/test/opennms-home/etc/imports"),
            null, true);/*from   w  w  w.j a  v  a2s .  co m*/
    while (fileIterator.hasNext()) {
        fileIterator.next().delete();
    }
}