Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

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

Prototype

FilenameFilter

Source Link

Usage

From source file:czlab.wabbit.CljPodLoader.java

/**
 *//*  w  ww .j a v  a 2  s  . c om*/
private CljPodLoader findUrls(File dir) {
    if (dir.exists()) {
        dir.listFiles(new FilenameFilter() {
            public boolean accept(File f, String n) {
                if (n.endsWith(".jar")) {
                    addUrl(new File(f, n));
                }
                return false;
            }
        });
    }
    return this;
}

From source file:fr.eo.util.dumper.Dumper.java

private static int getDumpLinesNumber() {
    File assertDir = new File(assetFolder);

    String[] dumpFileNames = assertDir.list(new FilenameFilter() {

        @Override//from   w w w.  j av  a 2s .c  o  m
        public boolean accept(File dir, String name) {
            return name.startsWith("dump") && name.endsWith(".sql");
        }
    });

    int nbDumpLines = 0;

    BufferedReader reader = null;
    try {
        for (String name : dumpFileNames) {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(assetFolder + name)));
            String currentLine = null;
            while ((currentLine = reader.readLine()) != null) {
                currentLine = currentLine.trim();
                if (currentLine.length() != 0 && !currentLine.startsWith("--")) {
                    nbDumpLines++;
                }
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return nbDumpLines;
}

From source file:de.uni_koblenz.ist.utilities.license_header.LicenseHeader.java

private void processDirectory(final File toProcess, int level) throws IOException {

    File[] directories = toProcess.listFiles(new FileFilter() {

        @Override// w ww  .  j  a v a2  s. c  om
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !pathname.getName().equals(".svn");
        }
    });

    File[] javaFilesToProcess = toProcess.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && name.toLowerCase().endsWith(".java");
        }
    });

    File[] xmlFilesToProcess = toProcess.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            String lowerCaseName = name.toLowerCase();
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && (lowerCaseName.endsWith(".xml") || lowerCaseName.endsWith(".xmi"));
        }
    });

    File[] tgFilesToProcess = toProcess.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return dir.getAbsolutePath().equals(toProcess.getAbsolutePath())
                    && name.toLowerCase().endsWith(".tg");
        }
    });

    if (fullyRecursive) {
        for (File currentSubdirectory : directories) {
            if (verbose) {
                printIndent(level);
                System.out.println("Entering directory " + currentSubdirectory.getName());
            }
            processDirectory(currentSubdirectory, level + 1);
            if (verbose) {
                printIndent(level);
                System.out.println("Leaving directory " + currentSubdirectory.getName());
            }
        }
    }

    for (File currentJavaFile : javaFilesToProcess) {
        processJavaFile(currentJavaFile, level, JAVA_FIRST_LINE, JAVA_PREFIX, JAVA_LAST_LINE);
    }

    for (File currentXMLFile : xmlFilesToProcess) {
        processXMLFile(currentXMLFile, level, 72);
    }

    for (File currentTGFile : tgFilesToProcess) {
        processTGFile(currentTGFile, level);
    }
}

From source file:de.sub.goobi.persistence.apache.FolderInformation.java

/**
 * Get source directory./*from  ww  w. j a v a  2s  .  c  o m*/
 *
 * @return path
 */
public String getSourceDirectory() {
    SafeFile dir = new SafeFile(getImagesDirectory());
    FilenameFilter filterVerz = new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return (name.endsWith("_" + "source"));
        }
    };
    SafeFile sourceFolder = null;
    String[] verzeichnisse = dir.list(filterVerz);
    if (verzeichnisse == null || verzeichnisse.length == 0) {
        sourceFolder = new SafeFile(dir, title + "_source");
        if (ConfigCore.getBooleanParameter("createSourceFolder", false)) {
            sourceFolder.mkdir();
        }
    } else {
        sourceFolder = new SafeFile(dir, verzeichnisse[0]);
    }

    return sourceFolder.getAbsolutePath();
}

From source file:com.hunch.ImageManager.java

protected FileInputStream getImageFileStreamFromInternal(final Context context, final URL url) {
    final String fileName = fileNameFromURL(url);
    File internalImagesDir = context.getDir(Const.INTERNAL_IMG_DIR, Context.MODE_PRIVATE);

    // the directory is guaranteed to exist by getDir()

    File[] imageFileList = internalImagesDir.listFiles(new FilenameFilter() {

        @Override//from   www  .j  a v a 2s  .co  m
        public boolean accept(File dir, String aFilename) {
            return fileName.equals(aFilename);
        }
    });

    if (imageFileList == null || imageFileList.length == 0) {
        return null;
    }

    if (imageFileList.length > 1) {
        Log.i(Const.TAG,
                "found " + imageFileList.length + " images for url in internal cache! " + "(" + fileName + ")");
    }

    FileInputStream iStream = null;
    try {
        iStream = new FileInputStream(imageFileList[0]);
    } catch (FileNotFoundException e) {
        return null;
    }

    //Log.v( Const.TAG, "found image in internal cache (" + url + ")" );

    return iStream;
}

From source file:com.liferay.server.manager.internal.executor.PluginExecutor.java

protected List<File> getInstalledDirectories(final String context) throws Exception {

    List<File> installedDirs = new ArrayList<>();

    String installedDirName = DeployManagerUtil.getInstalledDir();

    File installedDir = new File(installedDirName, context);

    if (installedDir.exists()) {
        installedDirs.add(installedDir);
    } else {//from   ww w. java  2  s  . c o m
        File deployWarDir = new File(installedDirName, context + ".war");

        installedDirs.add(deployWarDir);
    }

    if (ServerDetector.isTomcat()) {
        File tempDir = new File(SystemProperties.get(SystemProperties.TMP_DIR));

        File[] tempContextDirs = tempDir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                if (name.endsWith("-" + context)) {
                    return true;
                }

                return false;
            }

        });

        if (ArrayUtil.isNotEmpty(tempContextDirs)) {
            Arrays.sort(tempContextDirs, new Comparator<File>() {

                @Override
                public int compare(File file1, File file2) {
                    String fileName1 = file1.getName();
                    String fileName2 = file2.getName();

                    return fileName1.compareTo(fileName2);
                }

            });

            File tempContextDir = tempContextDirs[tempContextDirs.length - 1];

            installedDirs.add(tempContextDir);
        }
    }

    return installedDirs;
}

From source file:com.example.lista3new.SyncService.java

private List<File> getLocalFileList(final String dirPath) {
    List<File> fileList = null;

    FilenameFilter filter = new FilenameFilter() {

        @Override//  ww  w  .  java2s  .  co  m
        public boolean accept(final File dir, final String filename) {
            File sel = new File(dir, filename);
            return ((sel.isFile() || sel.isDirectory()) && !sel.isHidden());
        }
    };
    File file = new File(dirPath);
    if (!file.exists()) {
        file.mkdirs();
    }
    fileList = Arrays.asList(file.listFiles(filter));
    return fileList;
}

From source file:bookkeepr.xmlable.DatabaseManager.java

public synchronized void restore() {
    Logger.getLogger(DatabaseManager.class.getName()).log(Level.INFO,
            "Restoring from " + rootPath.getAbsolutePath());

    long[] count = new long[256];
    Arrays.fill(count, 0);//from  w w w .ja va  2 s.  c  om

    File[] dirList = rootPath.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(".xml.gz");
        }
    });

    Arrays.sort(dirList, new Comparator<File>() {

        public int compare(File o1, File o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
        }
    });

    for (File f : dirList) {
        try {
            Index<IdAble> idx = (Index<IdAble>) XMLReader.read(new GZIPInputStream(new FileInputStream(f)));
            List<IdAble> list = idx.getIndex();
            if (idx.getIndex().size() < 1) {
                continue;// it's an empty list!

            }
            String key = getKey(list.get(0).getId());
            IdAble last = list.get(list.size() - 1);
            int type = getType(last);
            int origin = getOrigin(last);
            if (origin > this.maxOriginId) {
                this.maxOriginId = origin;
            }
            if (last.getId() > latestIds[origin][type]) {
                latestIds[origin][type] = last.getId();
            }
            this.indicies.put(key, idx);

            count[this.getType(list.get(0))] += idx.getSize();

            // notify listeners.
            for (IdAble item : idx.getIndex()) {

                for (Object listener : listeners[this.getType(item)]) {
                    ((ChangeListener) listener).itemUpdated(this, item, this.getOrigin(item) != this.originId,
                            false);
                }
            }
        } catch (SAXException ex) {
            Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    for (int type = 0; type < 256; type++) {
        long latest = latestIds[this.getOriginId()][type] & 0x00000FFFFFFFFFFFL;

        if (latest >= this.nextId[type]) {
            this.nextId[type] = latest + 1;
            Logger.getLogger(DatabaseManager.class.getName()).log(Level.WARNING, "Latest index for type "
                    + Integer.toHexString(type)
                    + " is later than our next ID... Updating next ID to avoid database conflicts (latest is: "
                    + Long.toHexString(latest) + ")");
        }
    }

    Logger.getLogger(DatabaseManager.class.getName()).log(Level.INFO,
            "Loaded " + this.indicies.size() + " indexes");
    for (int t = 0; t < count.length; t++) {
        if (count[t] > 0) {
            Logger.getLogger(DatabaseManager.class.getName()).log(Level.INFO,
                    "Loaded " + count[t] + " items of type " + Integer.toHexString(t));
        }
    }

}

From source file:gov.nasa.ensemble.common.io.FileUtilities.java

/**
 * //from www .j a v  a 2s.  com
 * @param directory
 * @param extensions
 *            the list of acceptable extensions
 * @return A list of fileNames in the directory with the specified extension.
 */
public static String[] getAllFileNamesWithExtension(File directory, final String... extensions) {
    String[] ret = directory.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            boolean ret = false;
            for (String extension : extensions)
                ret |= name.endsWith(extension);
            return ret;
        }
    });
    return ret == null ? new String[0] : ret;
}

From source file:org.callimachusproject.rdfa.test.RDFaGenerationTest.java

private static TestSuite listCases(File dir) {
    TestSuite cases = new TestSuite(dir.getName());

    File[] testFiles = dir.listFiles(new FilenameFilter() {
        public boolean accept(File file, String filename) {
            return (filename.endsWith(TEMPLATE_FILE_SUFFIX)
                    || (new File(file, filename).isDirectory() && !filename.startsWith(".")));
        }/* w  w  w  . j av a2  s.c  o m*/
    });
    // enumerate test files (RDFa templates)
    for (File f : testFiles) {
        if (f.isDirectory()) {
            cases.addTest(listCases(f));
        } else {
            cases.addTest(new RDFaGenerationTest(f.getName() + "!" + f.getPath()));
        }
    }
    return cases;
}