Example usage for org.apache.commons.io.filefilter FileFilterUtils falseFileFilter

List of usage examples for org.apache.commons.io.filefilter FileFilterUtils falseFileFilter

Introduction

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

Prototype

public static IOFileFilter falseFileFilter() 

Source Link

Document

Returns a filter that always returns false.

Usage

From source file:com.edgenius.core.util.ZipFileUtil.java

/**
 * Creates a ZIP file and places it in the current working directory. The zip file is compressed
 * at the default compression level of the Deflater.
 * /*from  w  w w.  j av  a  2  s .  com*/
 * @param listToZip. Key is file or directory, value is parent directory which will remove from given file/directory because 
 * compression only save relative directory.  For example, c:\geniuswiki\data\repository\somefile, if value is c:\geniuswiki, then only 
 * \data\repository\somefile will be saved.  It is very important, the value must be canonical path, ie, c:\my document\geniuswiki, 
 * CANNOT like this "c:\my doc~1\" 
 * 
 * 
 */
public static void createZipFile(String zipFileName, Map<File, String> listToZip, boolean withEmptyDir)
        throws ZipFileUtilException {
    ZipOutputStream zop = null;
    try {
        zop = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFileName)));
        zop.setMethod(ZipOutputStream.DEFLATED);
        zop.setLevel(Deflater.DEFAULT_COMPRESSION);

        for (Entry<File, String> entry : listToZip.entrySet()) {
            File file = entry.getKey();
            if (!file.exists()) {
                log.warn("Unable to find file " + file + " to zip");
                continue;
            }
            if (file.isDirectory()) {
                Collection<File> list = FileUtils.listFiles(file, null, true);
                for (File src : list) {
                    addEntry(zop, src, createRelativeDir(src.getCanonicalPath(), entry.getValue()));
                }
                if (withEmptyDir) {
                    final List<File> emptyDirs = new ArrayList<File>();
                    if (file.list().length == 0) {
                        emptyDirs.add(file);
                    } else {
                        //I just don't know how quickly to find out all empty sub directories recursively. so use below hack:
                        FileUtils.listFiles(file, FileFilterUtils.falseFileFilter(), new IOFileFilter() {
                            //JDK1.6 @Override
                            public boolean accept(File f) {
                                if (!f.isDirectory())
                                    return false;

                                int size = f.listFiles().length;
                                if (size == 0) {
                                    emptyDirs.add(f);
                                }
                                return true;
                            }

                            //JDK1.6 @Override
                            public boolean accept(File arg0, String arg1) {
                                return true;
                            }
                        });
                    }
                    for (File src : emptyDirs) {
                        addEntry(zop, null, createRelativeDir(src.getCanonicalPath(), entry.getValue()));
                    }
                }
            } else {
                addEntry(zop, file, createRelativeDir(file.getCanonicalPath(), entry.getValue()));
            }

        }
    } catch (IOException e1) {
        throw new ZipFileUtilException(
                "An error has occurred while trying to zip the files. Error message is: ", e1);
    } finally {
        try {
            if (zop != null)
                zop.close();
        } catch (Exception e) {
        }
    }

}

From source file:com.mirth.connect.server.controllers.DefaultExtensionController.java

public List<String> getClientLibraries() {
    List<String> clientLibFilenames = new ArrayList<String>();
    File clientLibDir = new File("client-lib");

    if (!clientLibDir.exists() || !clientLibDir.isDirectory()) {
        clientLibDir = new File("build/client-lib");
    }/*from   w  ww .  j a  v a 2s. c  o m*/

    if (clientLibDir.exists() && clientLibDir.isDirectory()) {
        Collection<File> clientLibs = FileUtils.listFiles(clientLibDir, new SuffixFileFilter(".jar"),
                FileFilterUtils.falseFileFilter());

        for (File clientLib : clientLibs) {
            clientLibFilenames.add(FilenameUtils.getName(clientLib.getName()));
        }
    } else {
        logger.error("Could not find client-lib directory: " + clientLibDir.getAbsolutePath());
    }

    return clientLibFilenames;
}

From source file:ome.services.blitz.repo.PublicRepositoryI.java

/**
  * Get a filtered file listing based on the config options.
  *//  w w  w.  j  av a2  s . c o  m
  * @param file
  *            A File object representing the directory to be listed.
  * @param config
  *            A RepositoryListConfig object holding the filter options.
  * @return A list of File objects
  *
  */
private List<File> filteredFiles(File file, RepositoryListConfig config) throws ServerError {
    List<File> files;
    IOFileFilter filter;

    // If hidden is true list all files otherwise only those files not starting with "."
    if (config.hidden) {
        filter = FileFilterUtils.trueFileFilter();
    } else {
        filter = FileFilterUtils.notFileFilter(FileFilterUtils.prefixFileFilter("."));
    }

    // Now decorate the filter to restrict to files or directories,
    // the else case is for a bizarre config of wanting nothing returned!
    if (!(config.dirs && config.files)) {
        if (config.dirs) {
            filter = FileFilterUtils.makeDirectoryOnly(filter);
        } else if (config.files) {
            filter = FileFilterUtils.makeFileOnly(filter);
        } else {
            filter = FileFilterUtils.falseFileFilter();
        }
    }

    files = Arrays.asList(file.listFiles((FileFilter) filter));

    return files;
}

From source file:ome.services.blitz.test.mock.TemporaryRepositoryTest.java

@Test
public void testFileUtils() throws Exception {
    String tmpPath = System.getProperty("java.io.tmpdir");
    File tmpDir = new File(tmpPath).getAbsoluteFile();
    tmpDir.list();//from ww w . j a v a 2  s.  com
    System.out.println(
            FileUtils.listFiles(tmpDir, FileFilterUtils.fileFileFilter(), FileFilterUtils.falseFileFilter()));

}

From source file:org.duracloud.chunk.FileChunkerTest.java

@Test
public void testInputFilters() throws Exception {
    createContentTree();/*www. j  a  v a2  s .c om*/

    int id = 0;
    IOFileFilter fileFilter = FileFilterUtils.trueFileFilter();
    IOFileFilter dirFilter = FileFilterUtils.trueFileFilter();
    doTestInputFilters(fileFilter, dirFilter, id, 13);

    id = 1;
    fileFilter = FileFilterUtils.trueFileFilter();
    dirFilter = FileFilterUtils.nameFileFilter("dir-0-b");
    doTestInputFilters(fileFilter, dirFilter, id, 2);

    id = 2;
    fileFilter = FileFilterUtils.trueFileFilter();
    dirFilter = FileFilterUtils.orFileFilter(FileFilterUtils.nameFileFilter("dir-0-b"),
            FileFilterUtils.nameFileFilter("dir-0-c"));
    doTestInputFilters(fileFilter, dirFilter, id, 3);

    id = 3;
    fileFilter = FileFilterUtils.trueFileFilter();
    dirFilter = FileFilterUtils.falseFileFilter();
    doTestInputFilters(fileFilter, dirFilter, id, 1);

    id = 4;
    fileFilter = FileFilterUtils.falseFileFilter();
    dirFilter = FileFilterUtils.trueFileFilter();
    try {
        doTestInputFilters(fileFilter, dirFilter, id, 0);
        Assert.fail("exception expected since no files found.");
    } catch (Exception e) {
        // Expected exception
    }

}

From source file:org.sonar.ce.log.CeLogging.java

@VisibleForTesting
void purgeDir(File dir) {
    if (dir.exists()) {
        int maxLogs = settings.getInt(MAX_LOGS_PROPERTY);
        if (maxLogs < 0) {
            throw new IllegalArgumentException(
                    format("Property %s must be positive. Got: %d", MAX_LOGS_PROPERTY, maxLogs));
        }/*from   ww  w .j a v  a  2  s .  com*/
        List<File> logFiles = newArrayList(
                FileUtils.listFiles(dir, FileFilterUtils.fileFileFilter(), FileFilterUtils.falseFileFilter()));
        if (logFiles.size() > maxLogs) {
            Collections.sort(logFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
            for (File logFile : from(logFiles).limit(logFiles.size() - maxLogs)) {
                logFile.delete();
            }
        }
    }
}