Example usage for org.apache.commons.io.filefilter IOFileFilter IOFileFilter

List of usage examples for org.apache.commons.io.filefilter IOFileFilter IOFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter IOFileFilter IOFileFilter.

Prototype

IOFileFilter

Source Link

Usage

From source file:de.jwi.zip.Zipper.java

public static void main(String[] args) throws Exception {
    ZipOutputStream z = new ZipOutputStream(new FileOutputStream("d:/temp/myfirst.zip"));

    IOFileFilter filter = new IOFileFilter() {

        public boolean accept(java.io.File file) {
            return true;
        }//from  w w  w .j ava  2  s.c  o m

        public boolean accept(java.io.File dir, java.lang.String name) {
            return true;
        }
    };

    Collection c = FileUtils.listFiles(new File("/java/javadocs/j2sdk-1.4.1/docs/tooldocs"), filter, filter);

    new Zipper().zip(z, c, new File("/java/javadocs/j2sdk-1.4.1"));

    z.close();

}

From source file:neembuu.uploader.zip.generator.utils.NUFileUtils.java

/**
 * Get all the files with the given extension.
 * @param file The directory where there are all the files.
 * @param extension The extension of the files to search for.
 * @return The list of the files./*  ww  w .ja  va 2  s  . com*/
 */
public static Collection<File> listAllFilesWithExt(File file, final String extension) {
    return FileUtils.listFiles(file, new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            // to prevent old libs compiled by netbeans from getting into.
            // i know since we are using git this should not happen, but when the code
            // was been tweaked for testing, this statement was reqired.
            if (file.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(file.getName(), extension);
        }

        @Override
        public boolean accept(File dir, String name) {
            if (dir.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(name, extension);
        }
    }, TrueFileFilter.INSTANCE);
}

From source file:AIR.Common.Utilities.Path.java

public static Collection<File> getFilesMatchingExtensions(String folder, final String[] extensions) {
    return (Collection<File>) FileUtils.listFiles(new File(folder), new IOFileFilter() {
        @Override//from   w w  w.  j ava2  s. c om
        public boolean accept(File arg0) {
            return matches(arg0.getAbsolutePath());
        }

        @Override
        public boolean accept(File arg0, String arg1) {
            return matches(arg1);
        }

        private boolean matches(String file) {
            for (int counter1 = 0; counter1 < extensions.length; ++counter1) {
                if (StringUtils.endsWithIgnoreCase(file, extensions[counter1]))
                    return true;
            }
            return false;
        }

    }, TrueFileFilter.INSTANCE);
}

From source file:com.yifanlu.PSXperiaTool.ZpakCreate.java

public void create(boolean noCompress) throws IOException {
    Logger.info("Generating zpak file from directory %s with compression = %b", mDirectory.getPath(),
            !noCompress);/*from ww  w  . j  a v  a  2 s.com*/
    IOFileFilter filter = new IOFileFilter() {
        public boolean accept(File file) {
            if (file.getName().startsWith(".")) {
                Logger.debug("Skipping file %s", file.getPath());
                return false;
            }
            return true;
        }

        public boolean accept(File file, String s) {
            if (s.startsWith(".")) {
                Logger.debug("Skipping file %s", file.getPath());
                return false;
            }
            return true;
        }
    };
    Iterator<File> it = FileUtils.iterateFiles(mDirectory, filter, TrueFileFilter.INSTANCE);
    ZipOutputStream out = new ZipOutputStream(mOut);
    out.setMethod(noCompress ? ZipEntry.STORED : ZipEntry.DEFLATED);
    while (it.hasNext()) {
        File current = it.next();
        FileInputStream in = new FileInputStream(current);
        ZipEntry zEntry = new ZipEntry(
                current.getPath().replace(mDirectory.getPath(), "").substring(1).replace("\\", "/"));
        if (noCompress) {
            zEntry.setSize(in.getChannel().size());
            zEntry.setCompressedSize(in.getChannel().size());
            zEntry.setCrc(getCRC32(current));
        }
        out.putNextEntry(zEntry);
        Logger.verbose("Adding file %s", current.getPath());
        int n;
        while ((n = in.read(mBuffer)) != -1) {
            out.write(mBuffer, 0, n);
        }
        in.close();
        out.closeEntry();
    }
    out.close();
    Logger.debug("Done with ZPAK creation.");
}

From source file:fr.fastconnect.factory.tibco.bw.codereview.BWProjectBuilder.java

private void addSources(ProjectDefinition project) {
    final File basedir = project.getBaseDir();

    logger.debug(basedir.getAbsolutePath());

    // TODO: ignore child modules folders more properly
    IOFileFilter custom = new IOFileFilter() {
        @Override//  w w w  .jav  a 2s.  co m
        public boolean accept(File file) {
            return file.isDirectory() && !(new File(file, "pom.xml").exists())
                    || file.getAbsolutePath().equals(basedir.getAbsolutePath());
        }

        @Override
        public boolean accept(File dir, String name) {
            return false;
        }
    };

    Collection<File> files = FileUtils.listFiles(basedir, new SuffixFileFilter(".process"),
            new AndFileFilter(new NotFileFilter(new PrefixFileFilter("target")), custom));

    project.addSources(files.toArray(new File[0]));
}

From source file:mx.itesm.imb.EcoreImbEditor.java

/**
 * /*w  w  w  . j  a v a 2  s. c o  m*/
 * @param ecoreProject
 */
@SuppressWarnings("unchecked")
public static void generateProvidersArtifacts(final File ecoreProject, final File templateProject) {
    File provider;
    File imbProject;
    List<File> imbTypes;
    Iterator<File> files;
    List<String> types;
    String typesPackage;

    // Get imb types
    imbProject = new File(ecoreProject.getParent(), ecoreProject.getName() + ".edit");
    files = FileUtils.iterateFiles(new File(imbProject, "/src/imb"), new String[] { "java" }, true);
    imbTypes = new ArrayList<File>();
    while (files.hasNext()) {
        imbTypes.add(files.next());
    }

    // Get providers files
    files = FileUtils.iterateFiles(imbProject, new IOFileFilter() {

        @Override
        public boolean accept(final File file) {
            return file.getName().endsWith("ItemProvider.java");
        }

        @Override
        public boolean accept(File directory, String file) {
            return file.endsWith("ItemProvider.java");
        }
    }, TrueFileFilter.INSTANCE);

    typesPackage = null;
    types = new ArrayList<String>();
    while (files.hasNext()) {
        try {
            provider = files.next();
            types.add(provider.getName().replace("ItemProvider.java", ""));
            typesPackage = provider.getPath()
                    .substring(provider.getPath().indexOf("src") + "src".length() + 1,
                            provider.getPath().indexOf(provider.getName().replace(".java", "")) - 1)
                    .replace('/', '.');

            EcoreImbEditor.writeEcoreAspect(provider, imbTypes);
            EcoreImbEditor.writeEcoreController(imbProject, templateProject, provider, imbTypes);
            System.out.println("Artifacts for " + provider + " successfully generated");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error generating Artifacts: " + e.getMessage());
        }
    }

    // Configuration properties file
    try {
        FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"),
                new File(imbProject, "/src/mx/itesm/imb/configuration.properties"));
        FileUtils.copyFile(new File(templateProject, "/templates/configuration-template.properties"),
                new File(ecoreProject.getParent(),
                        ecoreProject.getName() + ".editor/src/mx/itesm/imb/configuration.properties"));
    } catch (IOException e) {
        System.out.println("Unable to generate configuration properties file: " + e.getMessage());
    }

    // Selection aspect
    typesPackage = typesPackage.replace(".provider", "");
    EcoreImbEditor.writeSelectionAspect(ecoreProject, typesPackage, types);
}

From source file:com.jfinal.ext.plugin.sqlinxml.SqlKit.java

public static void init() {
    File file = new File(SqlKit.class.getClassLoader().getResource("").getFile());
    Collection<File> files = FileUtils.listFiles(file, new IOFileFilter() {

        @Override//  ww w  .  j a  v a2  s. c  om
        public boolean accept(File dir, String name) {
            return name.endsWith("sql.xml");
        }

        @Override
        public boolean accept(File file) {
            return file.getName().endsWith("sql.xml");
        }
    }, TrueFileFilter.INSTANCE);

    for (File xmlfile : files) {
        parseSql(xmlfile, false, sqlMap, modelMapping);
    }
    LOG.debug("sqlMap" + sqlMap);
}

From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java

private static IOFileFilter definitionsFilter() {
    return new IOFileFilter() {
        @Override//from  ww  w.  j  ava 2 s .co m
        public boolean accept(File file) {
            return file.isFile();
        }

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".json");
        }
    };
}

From source file:me.dags.creativeblock.blockpack.FolderBlockPack.java

private static IOFileFilter textureFilter() {
    return new IOFileFilter() {
        @Override/*from   w  w w .  j a v a 2 s. c  o  m*/
        public boolean accept(File file) {
            return file.isFile();
        }

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".png");
        }
    };
}

From source file:media_organizer.MediaInspector.java

@SuppressWarnings("unchecked")
public void unique_file_generator() {
    Iterator<File> iter = FileUtils.iterateFilesAndDirs(topStartDirectory.toFile(), TrueFileFilter.INSTANCE,
            new IOFileFilter() {
                @Override/*  w  w w .  ja  va 2  s .com*/
                public boolean accept(File file) {
                    try {
                        return pureDirectory(file);
                    } catch (IOException ex) {
                        return false;
                    }
                }

                @Override
                public boolean accept(File dir, String name) {
                    try {
                        return pureDirectory(dir);
                    } catch (IOException ex) {
                        return false;
                    }
                }
            });

    File n;
    try {
        while (iter.hasNext()) {
            n = iter.next();

            if (!pureDirectory(n)) {
                if (n.getAbsolutePath().contains("DS_Store")) {
                    continue;
                }
                String cksm = getChecksum(n, false);
                if (!globalChecksumList.contains(cksm)) {
                    globalChecksumList.add(cksm);
                    // Rename or copy file into the new name and store the file path in list
                    String create_time_str = get_file_creation_time(n);
                    String temp_name = create_time_str + "_" + cksm + "."
                            + FilenameUtils.getExtension(n.getAbsolutePath());
                    File tempFile = new File(tempDirectory.toString() + "/" + temp_name);
                    System.out.println("Copying " + n.getAbsolutePath() + " to temp location as "
                            + tempFile.getAbsolutePath());
                    Files.copy(n.toPath(), tempFile.toPath(), COPY_ATTRIBUTES);

                    String new_create_time_str = get_file_creation_time(tempFile);
                    String new_name = new_create_time_str + "_" + cksm + "."
                            + FilenameUtils.getExtension(n.getAbsolutePath());
                    File newFile = new File(destDirectory.toString() + "/" + new_name);
                    System.out.println(
                            "Moving " + tempFile.getAbsolutePath() + " as " + newFile.getAbsolutePath());
                    Files.move(tempFile.toPath(), newFile.toPath(), ATOMIC_MOVE);
                } else {
                    System.out.println("\nSkipping Duplicate file: " + n.getName() + "\n");
                }
            }
        }
        System.out.println("\n");
    } catch (IOException ex) {
        System.out.format(ex.getMessage());
    } finally {
        if (tmp_directory.exists()) {
            tmp_directory.delete();
        }
    }
}