Search in sources :

Example 1 with FileFilter

use of java.io.FileFilter in project hadoop by apache.

the class JournalNode method getJournalsStatus.

// JournalNodeMXBean
@Override
public String getJournalsStatus() {
    // jid:{Formatted:True/False}
    Map<String, Map<String, String>> status = new HashMap<String, Map<String, String>>();
    synchronized (this) {
        for (Map.Entry<String, Journal> entry : journalsById.entrySet()) {
            Map<String, String> jMap = new HashMap<String, String>();
            jMap.put("Formatted", Boolean.toString(entry.getValue().isFormatted()));
            status.put(entry.getKey(), jMap);
        }
    }
    // It is possible that some journals have been formatted before, while the 
    // corresponding journals are not in journalsById yet (because of restarting
    // JN, e.g.). For simplicity, let's just assume a journal is formatted if
    // there is a directory for it. We can also call analyzeStorage method for
    // these directories if necessary.
    // Also note that we do not need to check localDir here since
    // validateAndCreateJournalDir has been called before we register the
    // MXBean.
    File[] journalDirs = localDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });
    for (File journalDir : journalDirs) {
        String jid = journalDir.getName();
        if (!status.containsKey(jid)) {
            Map<String, String> jMap = new HashMap<String, String>();
            jMap.put("Formatted", "true");
            status.put(jid, jMap);
        }
    }
    return JSON.toString(status);
}
Also used : HashMap(java.util.HashMap) FileFilter(java.io.FileFilter) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 2 with FileFilter

use of java.io.FileFilter in project hackpad by dropbox.

the class MozillaSuiteTest method main.

/**
     * The main class will run all the test files that are *not* covered in
     * the *.tests files, and print out a list of all the tests that pass.
     */
public static void main(String[] args) throws IOException {
    PrintStream out = new PrintStream("fix-tests-files.sh");
    try {
        for (int i = 0; i < OPT_LEVELS.length; i++) {
            int optLevel = OPT_LEVELS[i];
            File testDir = getTestDir();
            File[] allTests = TestUtils.recursiveListFiles(testDir, new FileFilter() {

                public boolean accept(File pathname) {
                    return ShellTest.DIRECTORY_FILTER.accept(pathname) || ShellTest.TEST_FILTER.accept(pathname);
                }
            });
            HashSet<File> diff = new HashSet<File>(Arrays.asList(allTests));
            File[] testFiles = getTestFiles(optLevel);
            diff.removeAll(Arrays.asList(testFiles));
            ArrayList<String> skippedPassed = new ArrayList<String>();
            int absolutePathLength = testDir.getAbsolutePath().length() + 1;
            for (File testFile : diff) {
                try {
                    (new MozillaSuiteTest(testFile, optLevel)).runMozillaTest();
                    // strip off testDir
                    String canonicalized = testFile.getAbsolutePath().substring(absolutePathLength);
                    canonicalized = canonicalized.replace('\\', '/');
                    skippedPassed.add(canonicalized);
                } catch (Throwable t) {
                // failed, so skip
                }
            }
            // appropriate *.tests file.
            if (skippedPassed.size() > 0) {
                out.println("cat >> " + getTestFilename(optLevel) + " <<EOF");
                String[] sorted = skippedPassed.toArray(new String[0]);
                Arrays.sort(sorted);
                for (int j = 0; j < sorted.length; j++) {
                    out.println(sorted[j]);
                }
                out.println("EOF");
            }
        }
        System.out.println("Done.");
    } finally {
        out.close();
    }
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with FileFilter

use of java.io.FileFilter in project druid by druid-io.

the class LocalFileTimestampVersionFinder method mostRecentInDir.

private URI mostRecentInDir(final Path dir, final Pattern pattern) throws IOException {
    long latestModified = Long.MIN_VALUE;
    URI latest = null;
    for (File file : dir.toFile().listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.exists() && pathname.isFile() && (pattern == null || pattern.matcher(pathname.getName()).matches());
        }
    })) {
        final long thisModified = file.lastModified();
        if (thisModified >= latestModified) {
            latestModified = thisModified;
            latest = file.toURI();
        }
    }
    return latest;
}
Also used : FileFilter(java.io.FileFilter) URI(java.net.URI) File(java.io.File)

Example 4 with FileFilter

use of java.io.FileFilter in project druid by druid-io.

the class FileTaskLogs method killOlderThan.

@Override
public void killOlderThan(final long timestamp) throws IOException {
    File taskLogDir = config.getDirectory();
    if (taskLogDir.exists()) {
        if (!taskLogDir.isDirectory()) {
            throw new IOException(String.format("taskLogDir [%s] must be a directory.", taskLogDir));
        }
        File[] files = taskLogDir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.lastModified() < timestamp;
            }
        });
        for (File file : files) {
            log.info("Deleting local task log [%s].", file.getAbsolutePath());
            FileUtils.forceDelete(file);
            if (Thread.currentThread().isInterrupted()) {
                throw new IOException(new InterruptedException("Thread interrupted. Couldn't delete all tasklogs."));
            }
        }
    }
}
Also used : IOException(java.io.IOException) FileFilter(java.io.FileFilter) File(java.io.File)

Example 5 with FileFilter

use of java.io.FileFilter in project jetty.project by eclipse.

the class Slf4jHelper method createTestClassLoader.

public static ClassLoader createTestClassLoader(ClassLoader parentClassLoader) throws MalformedURLException {
    File testJarDir = MavenTestingUtils.getTargetFile("test-jars");
    // trigger @Ignore if dir not there
    Assume.assumeTrue(testJarDir.exists());
    File[] jarfiles = testJarDir.listFiles(new FileFilter() {

        public boolean accept(File path) {
            if (!path.isFile()) {
                return false;
            }
            return path.getName().endsWith(".jar");
        }
    });
    // trigger @Ignore if no jar files.
    Assume.assumeTrue(jarfiles.length > 0);
    URL[] urls = new URL[jarfiles.length];
    for (int i = 0; i < jarfiles.length; i++) {
        urls[i] = jarfiles[i].toURI().toURL();
    // System.out.println("Adding test-jar => " + urls[i]);
    }
    return new URLClassLoader(urls, parentClassLoader);
}
Also used : URLClassLoader(java.net.URLClassLoader) FileFilter(java.io.FileFilter) File(java.io.File) URL(java.net.URL)

Aggregations

FileFilter (java.io.FileFilter)232 File (java.io.File)218 ArrayList (java.util.ArrayList)50 IOException (java.io.IOException)40 Test (org.junit.Test)13 FilenameFilter (java.io.FilenameFilter)11 URL (java.net.URL)10 HashMap (java.util.HashMap)10 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 HashSet (java.util.HashSet)8 JarFile (java.util.jar.JarFile)8 Pattern (java.util.regex.Pattern)8 Map (java.util.Map)7 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6 Pair (edu.stanford.nlp.util.Pair)6 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)6 EvaluateTreebank (edu.stanford.nlp.parser.lexparser.EvaluateTreebank)5