Example usage for java.io FilenameFilter accept

List of usage examples for java.io FilenameFilter accept

Introduction

In this page you can find the example usage for java.io FilenameFilter accept.

Prototype

boolean accept(File dir, String name);

Source Link

Document

Tests if a specified file should be included in a file list.

Usage

From source file:org.apache.tajo.catalog.store.XMLCatalogSchemaManager.java

protected String[] listJarResources(URL dirURL, FilenameFilter filter) throws IOException, URISyntaxException {
    String[] files = new String[0];
    String spec = dirURL.getFile();
    int seperator = spec.indexOf("!/");

    if (seperator == -1) {
        return files;
    }//from ww  w  .  ja va  2  s.  c  o  m

    URL jarFileURL = new URL(spec.substring(0, seperator));
    Set<String> filesSet = new HashSet<>();

    try (JarFile jarFile = new JarFile(jarFileURL.toURI().getPath())) {
        Enumeration<JarEntry> entries = jarFile.entries();

        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();

            if (entry.isDirectory()) {
                continue;
            }

            String entryName = entry.getName();

            if (entryName.indexOf(schemaPath) > -1 && filter.accept(null, entryName)) {
                filesSet.add(entryName);
            }
        }
    }

    if (!filesSet.isEmpty()) {
        files = new String[filesSet.size()];
        files = filesSet.toArray(files);
    }

    return files;
}

From source file:com.colorchen.qbase.utils.FileUtil.java

/**
 * ??filter/*  w w w  .  j ava 2s  .  com*/
 *
 * @param dir         
 * @param filter      
 * @param isRecursive ??
 * @return 
 */
public static List<File> listFilesInDirWithFilter(File dir, FilenameFilter filter, boolean isRecursive) {
    if (isRecursive)
        return listFilesInDirWithFilter(dir, filter);
    if (dir == null || !isDir(dir))
        return null;
    List<File> list = new ArrayList<>();
    File[] files = dir.listFiles();
    for (File file : files) {
        if (filter.accept(file.getParentFile(), file.getName())) {
            list.add(file);
        }
    }
    return list;
}

From source file:com.mirth.connect.connectors.file.filesystems.FtpConnection.java

@Override
public List<FileInfo> listFiles(String fromDir, String filenamePattern, boolean isRegex, boolean ignoreDot)
        throws Exception {
    FilenameFilter filenameFilter;

    if (isRegex) {
        filenameFilter = new RegexFilenameFilter(filenamePattern);
    } else {// ww  w.j  ava  2 s. co  m
        filenameFilter = new WildcardFileFilter(filenamePattern.trim().split("\\s*,\\s*"));
    }

    if (!cwd(fromDir)) {
        logger.error(
                "listFiles.changeWorkingDirectory: " + client.getReplyCode() + "-" + client.getReplyString());
        throw new IOException("Ftp error: " + client.getReplyCode());
    }

    FTPFile[] files = client.listFiles();
    if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
        logger.error("listFiles.listFiles: " + client.getReplyCode() + "-" + client.getReplyString());
        throw new IOException("Ftp error: " + client.getReplyCode());
    }

    if (files == null || files.length == 0) {
        return new ArrayList<FileInfo>();
    }

    List<FileInfo> v = new ArrayList<FileInfo>(files.length);

    for (int i = 0; i < files.length; i++) {
        if ((files[i] != null) && files[i].isFile()) {
            if ((filenameFilter == null || filenameFilter.accept(null, files[i].getName()))
                    && !(ignoreDot && files[i].getName().startsWith("."))) {
                v.add(new FtpFileInfo(fromDir, files[i]));
            }
        }
    }
    return v;
}