use of java.io.FileFilter in project jabref by JabRef.
the class EntryFromFileCreatorManager method getFileFilterList.
/**
* Returns a list of all {@link FileFilter} instances (i.e.
* {@link EntryFromFileCreator}, plus the file filter that comes with the
* {@link #getFileFilter()} method.
*
* @return A List of all known possible file filters.
*/
public List<FileFilter> getFileFilterList() {
List<FileFilter> filters = new ArrayList<>();
filters.add(getFileFilter());
for (FileFilter creator : entryCreators) {
filters.add(creator);
}
return filters;
}
use of java.io.FileFilter in project CorfuDB by CorfuDB.
the class StreamLogFiles method trimPrefix.
private void trimPrefix() {
// Trim all segments up till the segment that contains the starting address
// (i.e. trim only complete segments)
long endSegment = (startingAddress / RECORDS_PER_LOG_FILE) - 1;
if (endSegment <= 0) {
log.debug("Only one segment detected, ignoring trim");
return;
}
File dir = new File(logDir);
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
String segmentStr = file.getName().split("\\.")[0];
return Long.parseLong(segmentStr) <= endSegment;
}
};
File[] files = dir.listFiles(fileFilter);
for (File file : files) {
if (!file.delete()) {
log.error("Couldn't delete/trim file {}", file.getName());
}
}
log.info("Prefix trim completed, delete segments 0 to {}", endSegment);
}
use of java.io.FileFilter in project sling by apache.
the class AbstractBundleListMojo method copyDirectory.
/**
* Helper method to copy a whole directory
*/
protected void copyDirectory(final File source, final File target, final String[] includes, final String[] excludes) throws IOException {
final String prefix = source.getAbsolutePath() + File.separatorChar;
final int prefixLength = prefix.length();
org.apache.commons.io.FileUtils.copyDirectory(source, target, new FileFilter() {
public boolean accept(final File file) {
final String path = file.getAbsolutePath().substring(prefixLength).replace(File.separatorChar, '/');
if (includes != null) {
boolean matched = false;
for (int i = 0; i < includes.length && !matched; i++) {
if (SelectorUtils.matchPath(includes[i], path)) {
matched = true;
}
}
if (!matched) {
return false;
}
}
if (excludes != null) {
for (final String pattern : excludes) {
if (SelectorUtils.matchPath(pattern, path)) {
return false;
}
}
}
return true;
}
});
}
use of java.io.FileFilter in project sling by apache.
the class Loader method getLauncherJarFiles.
/**
* Returns all files in the <code>launchpadHome</code> directory which may
* be considered as launcher JAR files, sorted based on their bundle version
* information, most recent last. These files all start with the
* {@link SharedConstants#LAUNCHER_JAR_REL_PATH}. This list may be empty if
* the launcher JAR file has not been installed yet.
*
* @return The list of candidate launcher JAR files, which may be empty.
* <code>null</code> is returned if an IO error occurs trying to
* list the files.
*/
private File[] getLauncherJarFiles() {
// Get list of files with names starting with our prefix
final File[] rawList = launchpadHome.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().startsWith(SharedConstants.LAUNCHER_JAR_REL_PATH);
}
});
// Keep only those which have valid Bundle headers, and
// sort them according to the bundle version numbers
final List<FileBundleVersionInfo> list = new ArrayList<FileBundleVersionInfo>();
for (File f : rawList) {
FileBundleVersionInfo fvi = null;
try {
fvi = new FileBundleVersionInfo(f);
} catch (IOException ioe) {
// Cannot read bundle info from jar file - should never happen??
throw new IllegalStateException("Cannot read bundle information from loader file " + f.getAbsolutePath());
}
if (fvi.isBundle()) {
list.add(fvi);
}
}
Collections.sort(list);
final File[] result = new File[list.size()];
int i = 0;
for (FileBundleVersionInfo fvi : list) {
result[i++] = fvi.getSource();
}
return result;
}
use of java.io.FileFilter in project intellij-plugins by JetBrains.
the class FlashBuilderSdkFinder method findFBInstallationPath.
@Nullable
public static String findFBInstallationPath() {
final List<File> fbDirs = new ArrayList<>();
final FileFilter filter = dir -> {
final String name = dir.getName();
return dir.isDirectory() && (name.contains("Flash") || name.contains("Flex")) && name.contains("Builder") && new File(dir, SDKS_FOLDER).isDirectory();
};
final String programsPath = SystemInfo.isMac ? "/Applications" : SystemInfo.isWindows ? System.getenv("ProgramFiles") : null;
final File programsDir = programsPath == null ? null : new File(programsPath);
if (programsDir != null && programsDir.isDirectory()) {
Collections.addAll(fbDirs, programsDir.listFiles(filter));
final File adobeDir = new File(programsDir, "Adobe");
if (adobeDir.isDirectory()) {
Collections.addAll(fbDirs, adobeDir.listFiles(filter));
}
}
if (SystemInfo.isWindows) {
final String programs64Path = System.getenv("ProgramW6432");
final File programs64Dir = programs64Path == null ? null : new File(programs64Path);
if (programs64Dir != null && programs64Dir.isDirectory()) {
Collections.addAll(fbDirs, programs64Dir.listFiles(filter));
final File adobeDir = new File(programs64Dir, "Adobe");
if (adobeDir.isDirectory()) {
Collections.addAll(fbDirs, adobeDir.listFiles(filter));
}
}
}
if (fbDirs.size() == 0)
return null;
if (fbDirs.size() == 1)
return fbDirs.get(0).getPath();
// check the most recent
Pair<String, String> pathAndVersion = null;
for (File fbDir : fbDirs) {
final String version = guessFBVersion(fbDir.getName());
if (pathAndVersion == null || StringUtil.compareVersionNumbers(version, pathAndVersion.second) > 0) {
pathAndVersion = Pair.create(fbDir.getPath(), version);
}
}
assert pathAndVersion != null;
return pathAndVersion.first;
}
Aggregations