use of java.io.FileFilter in project head by mifos.
the class OSGILauncher method searchFor.
/***************************************************************************
* See org.eclipse.core.launcher [copy of searchFor, findMax,
* compareVersion, getVersionElements] TODO: If these methods were made
* public and static we could use them directly
**************************************************************************/
/**
* Searches for the given target directory starting in the "plugins"
* subdirectory of the given location. If one is found then this location is
* returned; otherwise an exception is thrown.
*
* @param target
*
* @return the location where target directory was found
* @param start
* the location to begin searching
*/
protected String searchFor(final String target, String start) {
FileFilter filter = new FileFilter() {
public boolean accept(File candidate) {
return candidate.getName().equals(target) || //$NON-NLS-1$
candidate.getName().startsWith(target + "_");
}
};
//$NON-NLS-1$
File[] candidates = new File(start).listFiles(filter);
if (candidates == null)
return null;
String[] arrays = new String[candidates.length];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = candidates[i].getName();
}
int result = findMax(arrays);
if (result == -1)
return null;
return candidates[result].getAbsolutePath().replace(File.separatorChar, '/') + //$NON-NLS-1$//$NON-NLS-2$
(candidates[result].isDirectory() ? "/" : "");
}
use of java.io.FileFilter in project nutz by nutzam.
the class UTF8_BOM method main.
public static void main(String[] args) {
final byte[] UTF_BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
final byte[] bom = new byte[3];
Disks.visitFile(new File("."), new FileVisitor() {
public void visit(File file) {
try {
FileInputStream fis = new FileInputStream(file);
fis.read(bom);
if (bom[0] == UTF_BOM[0] && bom[1] == UTF_BOM[1] && bom[2] == UTF_BOM[2]) {
System.out.println("Found BOM --> " + file);
byte[] data = Streams.readBytes(fis);
fis.close();
Files.write(file, data);
System.out.println("Fixed");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}, new FileFilter() {
public boolean accept(File pathname) {
if (pathname.isDirectory())
return true;
return pathname.getName().endsWith(".java") && pathname.length() > 3;
}
});
}
use of java.io.FileFilter in project spring-boot by spring-projects.
the class SampleAntApplicationIT method runJar.
@Test
public void runJar() throws Exception {
File target = new File("target");
File[] jarFiles = target.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.getName().endsWith(".jar");
}
});
assertThat(jarFiles).hasSize(1);
Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
process.waitFor(5, TimeUnit.MINUTES);
assertThat(process.exitValue()).isEqualTo(0);
String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
assertThat(output).contains("Spring Boot Ant Example");
}
use of java.io.FileFilter in project cassandra by apache.
the class AbstractSSTableSimpleWriter method getNextGeneration.
private static int getNextGeneration(File directory, final String columnFamily) {
final Set<Descriptor> existing = new HashSet<>();
directory.listFiles(new FileFilter() {
public boolean accept(File file) {
Descriptor desc = SSTable.tryDescriptorFromFilename(file);
if (desc == null)
return false;
if (desc.cfname.equals(columnFamily))
existing.add(desc);
return false;
}
});
int maxGen = generation.getAndIncrement();
for (Descriptor desc : existing) {
while (desc.generation > maxGen) {
maxGen = generation.getAndIncrement();
}
}
return maxGen;
}
use of java.io.FileFilter in project rest.li by linkedin.
the class ResourceSchemaCollection method createFromIdls.
/**
* Create {@link ResourceSchemaCollection} from idl files.
*
* @param restspecSearchPaths file system paths to search for idl files
* @return constructed ResourceSchemaCollection
*/
public static ResourceSchemaCollection createFromIdls(String[] restspecSearchPaths) {
final RestSpecCodec codec = new RestSpecCodec();
final Map<String, ResourceSchema> resourceSchemaMap = new HashMap<String, ResourceSchema>();
for (String path : restspecSearchPaths) {
final File dir = new File(path);
if (!dir.isDirectory()) {
throw new IllegalArgumentException(String.format("path '%s' is not a directory", dir.getAbsolutePath()));
}
final File[] idlFiles = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(RestConstants.RESOURCE_MODEL_FILENAME_EXTENSION);
}
});
for (File idlFile : idlFiles) {
try {
final FileInputStream is = new FileInputStream(idlFile);
final ResourceSchema resourceSchema = codec.readResourceSchema(is);
resourceSchemaMap.put(resourceSchema.getName(), resourceSchema);
} catch (IOException e) {
throw new RestLiInternalException(String.format("Error loading restspec IDL file '%s'", idlFile.getName()), e);
}
}
}
return new ResourceSchemaCollection(resourceSchemaMap);
}
Aggregations