本文整理匯總了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;
}