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);
}
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();
}
}
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;
}
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."));
}
}
}
}
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);
}
Aggregations