本文整理汇总了Java中org.apache.commons.io.filefilter.IOFileFilter类的典型用法代码示例。如果您正苦于以下问题:Java IOFileFilter类的具体用法?Java IOFileFilter怎么用?Java IOFileFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IOFileFilter类属于org.apache.commons.io.filefilter包,在下文中一共展示了IOFileFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteOldServerResourcesPacks
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Keep only the 10 most recent resources packs, delete the others
*/
private void deleteOldServerResourcesPacks()
{
try
{
List<File> list = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, (IOFileFilter)null));
Collections.sort(list, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
int i = 0;
for (File file1 : list)
{
if (i++ >= 10)
{
LOGGER.info("Deleting old server resource pack {}", new Object[] {file1.getName()});
FileUtils.deleteQuietly(file1);
}
}
}
catch (IllegalArgumentException illegalargumentexception)
{
LOGGER.error("Error while deleting old server resource pack : {}", new Object[] {illegalargumentexception.getMessage()});
}
}
示例2: func_183028_i
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
private void func_183028_i()
{
List<File> list = Lists.newArrayList(FileUtils.listFiles(this.dirServerResourcepacks, TrueFileFilter.TRUE, (IOFileFilter)null));
Collections.sort(list, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
int i = 0;
for (File file1 : list)
{
if (i++ >= 10)
{
logger.info("Deleting old server resource pack " + file1.getName());
FileUtils.deleteQuietly(file1);
}
}
}
示例3: getAbiSoFiles
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Verify the directory of the so file under the abi
*
* @param supportAbis
* @param removeSoFiles
* @param dirs
* @return
*/
public static Map<String, Multimap<String, File>> getAbiSoFiles(Set<String> supportAbis, Set<String> removeSoFiles,
List<File> dirs) {
Map<String, Multimap<String, File>> result = new HashMap<String, Multimap<String, File>>();
IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
for (File dir : dirs) {
Collection<File> files = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
for (File file : files) {
File parentFolder = file.getParentFile();
String parentName = parentFolder.getName();
String shortName = getSoShortName(file);
Multimap<String, File> maps = result.get(parentName);
if (null == maps) {
maps = HashMultimap.create(10, 3);
}
maps.put(shortName, file);
result.put(parentName, maps);
}
}
return result;
}
示例4: copyLocalNativeLibraries
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* @param localNativeLibrariesDirectory
* @param destinationDirectory
* @param supportAbis Type of architecture supported
* @param removeSoFiles
*/
public static void copyLocalNativeLibraries(final File localNativeLibrariesDirectory,
final File destinationDirectory, Set<String> supportAbis,
Set<String> removeSoFiles) {
sLogger.info("Copying existing native libraries from " + localNativeLibrariesDirectory + " to "
+ destinationDirectory);
try {
IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
// First, determine whether there is a file of the same name, if there is a discrepancy
Collection<File> files = FileUtils.listFiles(localNativeLibrariesDirectory, filter, TrueFileFilter.TRUE);
List<String> dumpFiles = new ArrayList<String>();
for (File file : files) {
String relativePath = getRelativePath(localNativeLibrariesDirectory, file);
File destFile = new File(destinationDirectory, relativePath);
if (destFile.exists()) {
String orgFileMd5 = MD5Util.getFileMD5(file);
String destFileMd5 = MD5Util.getFileMD5(destFile);
if (!orgFileMd5.equals(destFileMd5)) {
dumpFiles.add(file.getAbsolutePath() + " to " + destFile.getAbsolutePath());
}
}
}
if (dumpFiles.size() > 0) {
throw new RuntimeException("Copy native so error,duplicate file exist!:\n"
+ StringUtils.join(dumpFiles, "\n"));
}
FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory, filter);
} catch (IOException e) {
throw new RuntimeException("Could not copy native dependency.", e);
}
}
示例5: updateConfigurationFiles
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
private void updateConfigurationFiles() throws EngineException {
try {
IOFileFilter fileFilter = FileFilterUtils.or(FileFilterUtils.suffixFileFilter("json"),FileFilterUtils.suffixFileFilter("xml"),FileFilterUtils.suffixFileFilter("js"));
IOFileFilter dirFilter = FileFilterUtils.or(FileFilterUtils.nameFileFilter("config"));
for (File f: FileUtils.listFiles(ionicWorkDir, fileFilter, dirFilter)) {
String content = FileUtils.readFileToString(f, "UTF-8");
content = content.replaceAll("../DisplayObjects","../../DisplayObjects");
content = content.replaceAll("../Flashupdate","../../Flashupdate");
writeFile(f, content, "UTF-8");
}
Engine.logEngine.debug("(MobileBuilder) Configuration files updated for ionic project '"+ project.getName() +"'");
}
catch (Exception e) {
throw new EngineException("Unable to update configuration files for ionic project '"+ project.getName() +"'",e);
}
}
示例6: innerListFiles
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Finds files within a given directory (and optionally its
* subdirectories). All files found are filtered by an IOFileFilter.
*
* @param files the collection of files found.
* @param directory the directory to search in.
* @param filter the filter to apply to files and directories.
* @param includeSubDirectories indicates if will include the subdirectories themselves
*/
private static void innerListFiles(Collection<File> files, File directory,
IOFileFilter filter, boolean includeSubDirectories) {
File[] found = directory.listFiles((FileFilter) filter);
if (found != null) {
for (File file : found) {
if (file.isDirectory()) {
if (includeSubDirectories) {
files.add(file);
}
innerListFiles(files, file, filter, includeSubDirectories);
} else {
files.add(file);
}
}
}
}
示例7: check1
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* 只监控文件发送变化,如果是子目录的文件改变,则目录会变,由于没有过滤目录发生变化,则目录下的文件改变不会监控到
* @param dir
* @throws Exception
*/
public void check1(String dir) throws Exception
{
File directory = new File(dir);
// 轮询间隔 5 秒
long interval = TimeUnit.SECONDS.toMillis(5);
// 创建一个文件观察器用于处理文件的格式
IOFileFilter filter=FileFilterUtils.or(FileFilterUtils.suffixFileFilter(".class"),
FileFilterUtils.suffixFileFilter(".jar"));
FileAlterationObserver observer = new FileAlterationObserver(directory,filter);
//设置文件变化监听器
observer.addListener(new MyFileListener());
FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
monitor.addObserver(observer);//文件观察
monitor.start();
}
示例8: check2
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
public void check2(String dir) throws Exception
{
File directory = new File(dir);
// 轮询间隔 5 秒
long interval = TimeUnit.SECONDS.toMillis(5);
//后缀过滤器
IOFileFilter filefilter=FileFilterUtils.or(FileFilterUtils.suffixFileFilter(".class"),
FileFilterUtils.suffixFileFilter(".jar"));
//子目录的后缀
IOFileFilter subFilefilter=FileFilterUtils.or(FileFilterUtils.directoryFileFilter(),filefilter);
//根目录和子目录变化
IOFileFilter filter = FileFilterUtils.or(filefilter,subFilefilter);
FileAlterationObserver observer = new FileAlterationObserver(directory,filter);
//设置文件变化监听器
observer.addListener(new MyFileListener());
FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
monitor.addObserver(observer);//文件观察
monitor.start();
// monitor.addObserver(observer);//文件观察,如果在start后面加,则会触发所有文件创建
}
示例9: definitionsFilter
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
private static IOFileFilter definitionsFilter()
{
return new IOFileFilter()
{
@Override
public boolean accept(File file)
{
return file.isFile();
}
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".json");
}
};
}
示例10: textureFilter
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
private static IOFileFilter textureFilter()
{
return new IOFileFilter()
{
@Override
public boolean accept(File file)
{
return file.isFile();
}
@Override
public boolean accept(File dir, String name)
{
return name.endsWith(".png");
}
};
}
示例11: getFilesFilter
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Get a IOFileFilter instance which filter files containing filter value.
*
* @param filter
* @return
*/
public IOFileFilter getFilesFilter(final String filter) {
IOFileFilter fileFilter = new IOFileFilter() {
@Override
public boolean accept(File dir, String name) {
return dir.getName().contains(name);
}
@Override
public boolean accept(File file) {
return file.getName().contains(filter);
}
};
return fileFilter;
}
示例12: listFiles
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* 找到满足条件的文件,把结果保存到函数的参数中。files 不能在本函数中初始化,因为用到了递归,如果初始化的话,会
*/
private Collection<File> listFiles(File directory, IOFileFilter filter, boolean includeSubDirectories) {
File[] found = directory.listFiles((FileFilter) filter);
if (found != null) {
for (File file : found) {
if (file.isDirectory()) {
if (includeSubDirectories) {
files.add(file);
}
listFiles(file, filter, includeSubDirectories);
} else {
files.add(file);
}
}
}
return files;
}
示例13: innerListFiles
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Finds files within a given directory (and optionally its
* subdirectories). All files found are filtered by an IOFileFilter.
*
* @param files the collection of files found.
* @param directory the directory to search in.
* @param filter the filter to apply to files and directories.
* @param includeSubDirectories indicates if will include the subdirectories themselves
*/
private static void innerListFiles(final Collection<File> files, final File directory,
final IOFileFilter filter, final boolean includeSubDirectories) {
final File[] found = directory.listFiles((FileFilter) filter);
if (found != null) {
for (final File file : found) {
if (file.isDirectory()) {
if (includeSubDirectories) {
files.add(file);
}
innerListFiles(files, file, filter, includeSubDirectories);
} else {
files.add(file);
}
}
}
}
示例14: scan
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
/**
* Scan all {@link File} {@link Set} that are accepted by {@link IOFileFilter} under root directory
*
* @param rootDirectory
* Root directory
* @param recursive
* is recursive on sub directories
* @param ioFileFilter
* {@link IOFileFilter}
* @return Read-only {@link Set} , and the order be dependent on {@link File#listFiles()} implementation
* @see IOFileFilter
* @since 1.0.0
*/
@Nonnull
public Set<File> scan(File rootDirectory, boolean recursive, IOFileFilter ioFileFilter) {
final Set<File> filesSet = Sets.newLinkedHashSet();
if (ioFileFilter.accept(rootDirectory)) {
filesSet.add(rootDirectory);
}
File[] subFiles = rootDirectory.listFiles();
if (subFiles != null) {
for (File subFile : subFiles) {
if (ioFileFilter.accept(subFile)) {
filesSet.add(subFile);
}
if (recursive && subFile.isDirectory()) {
filesSet.addAll(this.scan(subFile, recursive, ioFileFilter));
}
}
}
return Collections.unmodifiableSet(filesSet);
}
示例15: findGitRepos
import org.apache.commons.io.filefilter.IOFileFilter; //导入依赖的package包/类
public static List<String> findGitRepos(String dirPath) {
File dir = new File(dirPath);
IOFileFilter gitDirFilter = (IOFileFilter) FileFilterUtils.suffixFileFilter(".git");
IOFileFilter notFile = FileFilterUtils.notFileFilter(TrueFileFilter.INSTANCE);
IOFileFilter compositeFilter = FileFilterUtils.and(notFile, gitDirFilter);
List<File> files = (List<File>) FileUtils.listFilesAndDirs(dir,compositeFilter,DirectoryFileFilter.INSTANCE);
List<String> results = new ArrayList<String>();
for(File f: files) {
try {
if(!f.getCanonicalPath().endsWith("/.git"))
continue;
String gitStripped = f.getCanonicalPath().replace("/.git", "");
System.out.println(gitStripped);
results.add(gitStripped);
} catch (IOException e) {
e.printStackTrace();
}
}
return results;
}