use of java.io.FileFilter in project opennms by OpenNMS.
the class TemporaryDatabasePostgreSQL method findIpLikeLibrary.
protected File findIpLikeLibrary() {
File topDir = ConfigurationTestUtils.getTopProjectDirectory();
File ipLikeDir = new File(topDir, "opennms-iplike");
assertTrue("iplike directory exists at ../opennms-iplike: " + ipLikeDir.getAbsolutePath(), ipLikeDir.exists());
File[] ipLikePlatformDirs = ipLikeDir.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.getName().matches("opennms-iplike-.*") && file.isDirectory()) {
return true;
} else {
return false;
}
}
});
assertTrue("expecting at least one opennms iplike platform directory in " + ipLikeDir.getAbsolutePath() + "; got: " + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "), ipLikePlatformDirs.length > 0);
File ipLikeFile = null;
for (File ipLikePlatformDir : ipLikePlatformDirs) {
assertTrue("iplike platform directory does not exist but was listed in directory listing: " + ipLikePlatformDir.getAbsolutePath(), ipLikePlatformDir.exists());
File ipLikeTargetDir = new File(ipLikePlatformDir, "target");
if (!ipLikeTargetDir.exists() || !ipLikeTargetDir.isDirectory()) {
// Skip this one
continue;
}
File[] ipLikeFiles = ipLikeTargetDir.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isFile() && file.getName().matches("opennms-iplike-.*\\.(so|dylib)")) {
return true;
} else {
return false;
}
}
});
assertFalse("expecting zero or one iplike file in " + ipLikeTargetDir.getAbsolutePath() + "; got: " + StringUtils.arrayToDelimitedString(ipLikeFiles, ", "), ipLikeFiles.length > 1);
if (ipLikeFiles.length == 1) {
ipLikeFile = ipLikeFiles[0];
}
}
assertNotNull("Could not find iplike shared object in a target directory in any of these directories: " + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "), ipLikeFile);
return ipLikeFile;
}
use of java.io.FileFilter in project jdk8u_jdk by JetBrains.
the class NulFile method test.
@SuppressWarnings("deprecation")
private static void test(File testFile, boolean derived) {
boolean exceptionThrown = false;
if (testFile == null) {
throw new RuntimeException("test file should not be null.");
}
// getPath()
if (testFile.getPath().indexOf(CHAR_NUL) < 0) {
throw new RuntimeException("File path should contain Nul character");
}
// getAbsolutePath()
if (testFile.getAbsolutePath().indexOf(CHAR_NUL) < 0) {
throw new RuntimeException("File absolute path should contain Nul character");
}
// getAbsoluteFile()
File derivedAbsFile = testFile.getAbsoluteFile();
if (derived) {
if (derivedAbsFile.getPath().indexOf(CHAR_NUL) < 0) {
throw new RuntimeException("Derived file path should also contain Nul character");
}
} else {
test(derivedAbsFile, true);
}
// getCanonicalPath()
try {
exceptionThrown = false;
testFile.getCanonicalPath();
} catch (IOException ex) {
if (ExceptionMsg.equals(ex.getMessage()))
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("getCanonicalPath() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
}
// getCanonicalFile()
try {
exceptionThrown = false;
testFile.getCanonicalFile();
} catch (IOException ex) {
if (ExceptionMsg.equals(ex.getMessage()))
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("getCanonicalFile() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
}
// toURL()
try {
exceptionThrown = false;
testFile.toURL();
} catch (MalformedURLException ex) {
if (ExceptionMsg.equals(ex.getMessage()))
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("toURL() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
}
// canRead()
if (testFile.canRead())
throw new RuntimeException("File should not be readable");
// canWrite()
if (testFile.canWrite())
throw new RuntimeException("File should not be writable");
// exists()
if (testFile.exists())
throw new RuntimeException("File should not be existed");
// isDirectory()
if (testFile.isDirectory())
throw new RuntimeException("File should not be a directory");
// isFile()
if (testFile.isFile())
throw new RuntimeException("File should not be a file");
// isHidden()
if (testFile.isHidden())
throw new RuntimeException("File should not be hidden");
// lastModified()
if (testFile.lastModified() != 0L)
throw new RuntimeException("File last modified time should be 0L");
// length()
if (testFile.length() != 0L)
throw new RuntimeException("File length should be 0L");
// createNewFile()
try {
exceptionThrown = false;
testFile.createNewFile();
} catch (IOException ex) {
if (ExceptionMsg.equals(ex.getMessage()))
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("createNewFile() should throw IOException with" + " message \"" + ExceptionMsg + "\"");
}
// delete()
if (testFile.delete())
throw new RuntimeException("Delete operation should fail");
// list()
if (testFile.list() != null)
throw new RuntimeException("File list() should return null");
// list(FilenameFilter)
FilenameFilter fnFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return false;
}
};
if (testFile.list(fnFilter) != null) {
throw new RuntimeException("File list(FilenameFilter) should" + " return null");
}
// listFiles()
if (testFile.listFiles() != null)
throw new RuntimeException("File listFiles() should return null");
// listFiles(FilenameFilter)
if (testFile.listFiles(fnFilter) != null) {
throw new RuntimeException("File listFiles(FilenameFilter)" + " should return null");
}
// listFiles(FileFilter)
FileFilter fFilter = new FileFilter() {
@Override
public boolean accept(File file) {
return false;
}
};
if (testFile.listFiles(fFilter) != null) {
throw new RuntimeException("File listFiles(FileFilter)" + " should return null");
}
// mkdir()
if (testFile.mkdir()) {
throw new RuntimeException("File should not be able to" + " create directory");
}
// mkdirs()
if (testFile.mkdirs()) {
throw new RuntimeException("File should not be able to" + " create directories");
}
// renameTo(File)
if (testFile.renameTo(new File("dest")))
throw new RuntimeException("File rename should fail");
if (new File("dest").renameTo(testFile))
throw new RuntimeException("File rename should fail");
try {
exceptionThrown = false;
testFile.renameTo(null);
} catch (NullPointerException ex) {
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("File rename should thrown NPE");
}
// setLastModified(long)
if (testFile.setLastModified(0L)) {
throw new RuntimeException("File should fail to set" + " last modified time");
}
try {
exceptionThrown = false;
testFile.setLastModified(-1);
} catch (IllegalArgumentException ex) {
if ("Negative time".equals(ex.getMessage()))
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("File should fail to set" + " last modified time with message \"Negative time\"");
}
// setReadOnly()
if (testFile.setReadOnly())
throw new RuntimeException("File should fail to set read-only");
// setWritable(boolean writable, boolean ownerOnly)
if (testFile.setWritable(true, true))
throw new RuntimeException("File should fail to set writable");
if (testFile.setWritable(true, false))
throw new RuntimeException("File should fail to set writable");
if (testFile.setWritable(false, true))
throw new RuntimeException("File should fail to set writable");
if (testFile.setWritable(false, false))
throw new RuntimeException("File should fail to set writable");
// setWritable(boolean writable)
if (testFile.setWritable(false))
throw new RuntimeException("File should fail to set writable");
if (testFile.setWritable(true))
throw new RuntimeException("File should fail to set writable");
// setReadable(boolean readable, boolean ownerOnly)
if (testFile.setReadable(true, true))
throw new RuntimeException("File should fail to set readable");
if (testFile.setReadable(true, false))
throw new RuntimeException("File should fail to set readable");
if (testFile.setReadable(false, true))
throw new RuntimeException("File should fail to set readable");
if (testFile.setReadable(false, false))
throw new RuntimeException("File should fail to set readable");
// setReadable(boolean readable)
if (testFile.setReadable(false))
throw new RuntimeException("File should fail to set readable");
if (testFile.setReadable(true))
throw new RuntimeException("File should fail to set readable");
// setExecutable(boolean executable, boolean ownerOnly)
if (testFile.setExecutable(true, true))
throw new RuntimeException("File should fail to set executable");
if (testFile.setExecutable(true, false))
throw new RuntimeException("File should fail to set executable");
if (testFile.setExecutable(false, true))
throw new RuntimeException("File should fail to set executable");
if (testFile.setExecutable(false, false))
throw new RuntimeException("File should fail to set executable");
// setExecutable(boolean executable)
if (testFile.setExecutable(false))
throw new RuntimeException("File should fail to set executable");
if (testFile.setExecutable(true))
throw new RuntimeException("File should fail to set executable");
// canExecute()
if (testFile.canExecute())
throw new RuntimeException("File should not be executable");
// getTotalSpace()
if (testFile.getTotalSpace() != 0L)
throw new RuntimeException("The total space should be 0L");
// getFreeSpace()
if (testFile.getFreeSpace() != 0L)
throw new RuntimeException("The free space should be 0L");
// getUsableSpace()
if (testFile.getUsableSpace() != 0L)
throw new RuntimeException("The usable space should be 0L");
// compareTo(File null)
try {
exceptionThrown = false;
testFile.compareTo(null);
} catch (NullPointerException ex) {
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("compareTo(null) should throw NPE");
}
// toString()
if (testFile.toString().indexOf(CHAR_NUL) < 0) {
throw new RuntimeException("File path should contain Nul character");
}
// toPath()
try {
exceptionThrown = false;
testFile.toPath();
} catch (InvalidPathException ex) {
exceptionThrown = true;
}
if (!exceptionThrown) {
throw new RuntimeException("toPath() should throw" + " InvalidPathException");
}
}
use of java.io.FileFilter in project voldemort by voldemort.
the class HadoopStoreBuilderTest method testRowsLessThanNodes.
/**
* Issue 258 : 'node--1' produced during store building if some reducer does
* not get any data.
*
* @throws Exception
*/
@Test
public void testRowsLessThanNodes() throws Exception {
Map<String, String> values = new HashMap<String, String>();
File testDir = TestUtils.createTempDir();
File tempDir = new File(testDir, "temp");
File outputDir = new File(testDir, "output");
// write test data to text file
File inputFile = File.createTempFile("input", ".txt", testDir);
inputFile.deleteOnExit();
StringBuilder contents = new StringBuilder();
for (Map.Entry<String, String> entry : values.entrySet()) contents.append(entry.getKey() + "\t" + entry.getValue() + "\n");
FileUtils.writeStringToFile(inputFile, contents.toString());
String storeName = "test";
SerializerDefinition serDef = new SerializerDefinition("string");
Cluster cluster = ServerTestUtils.getLocalCluster(10);
// Test backwards compatibility
StoreDefinition def = new StoreDefinitionBuilder().setName(storeName).setType(ReadOnlyStorageConfiguration.TYPE_NAME).setKeySerializer(serDef).setValueSerializer(serDef).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(1).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
HadoopStoreBuilder builder = new HadoopStoreBuilder("testRowsLessThanNodes", new Props(), new JobConf(), TextStoreMapper.class, TextInputFormat.class, cluster, def, new Path(tempDir.getAbsolutePath()), new Path(outputDir.getAbsolutePath()), new Path(inputFile.getAbsolutePath()), CheckSumType.MD5, saveKeys, false, 64 * 1024, false, 0L, false);
builder.build();
File[] nodeDirectories = outputDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
// We are only interested in counting directories, not files.
return pathname.isDirectory();
}
});
// Should not produce node--1 directory + have one folder for every node
Assert.assertEquals(cluster.getNumberOfNodes(), nodeDirectories.length);
for (File f : outputDir.listFiles()) {
Assert.assertFalse(f.toString().contains("node--1"));
}
// Check if individual nodes exist, along with their metadata file
for (int nodeId = 0; nodeId < 10; nodeId++) {
File nodeFile = new File(outputDir, "node-" + Integer.toString(nodeId));
Assert.assertTrue(nodeFile.exists());
Assert.assertTrue(new File(nodeFile, ".metadata").exists());
}
}
use of java.io.FileFilter in project Small by wequick.
the class AnalyticsManager method getNumCores.
private static int getNumCores() {
// Private Class to display only CPU devices in the directory listing
class CpuFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
// Check if filename is "cpu", followed by a single digit number
return (Pattern.matches("cpu[0-9]", pathname.getName()));
}
}
try {
// Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
// Filter to only list the devices we care about
File[] files = dir.listFiles(new CpuFilter());
// Return the number of cores (virtual CPU devices)
return files.length;
} catch (Exception e) {
// Default to return 1 core
return 1;
}
}
use of java.io.FileFilter in project intellij-community by JetBrains.
the class FilteredResourceRootDescriptor method createFileFilter.
@NotNull
@Override
public FileFilter createFileFilter() {
final JpsProject project = getTarget().getModule().getProject();
final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
return file -> !excludes.isExcluded(file) && configuration.isResourceFile(file, getRootFile());
}
Aggregations