本文整理匯總了Java中org.apache.commons.io.filefilter.FileFilterUtils類的典型用法代碼示例。如果您正苦於以下問題:Java FileFilterUtils類的具體用法?Java FileFilterUtils怎麽用?Java FileFilterUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileFilterUtils類屬於org.apache.commons.io.filefilter包,在下文中一共展示了FileFilterUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getResourcesWithExtension
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
public ArrayList<String> getResourcesWithExtension(String ext, String containerName) {
ArrayList<String> ret = new ArrayList<String>();
if (containerName != null) {
String[] names = StringUtils.split(containerName, "/");
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = wsRoot.findMember(new Path("/" + names[0]));
IPath loc = resource.getLocation();
File prjLoc = new File(loc.toString());
Collection<File> res = FileUtils.listFiles(prjLoc, FileFilterUtils.suffixFileFilter(ext, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
for (File file : res)
ret.add(file.getAbsolutePath());
}
return ret;
}
示例2: updatePlugin
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
/**
* 更新插件引擎
* <p>
* 檢測腳本變化時更新
* <p>
* 當新插件引擎初始化成功之後再替換舊插件引擎
*
* @throws Exception
*/
private synchronized static void updatePlugin() throws Exception {
// 清空 algorithm.config 配置
Config.getConfig().setAlgorithmConfig("{}");
boolean oldValue = HookHandler.enableHook.getAndSet(false);
File pluginDir = new File(Config.getConfig().getScriptDirectory());
LOGGER.debug("checker directory: " + pluginDir.getAbsolutePath());
if (!pluginDir.isDirectory()) {
pluginDir.mkdir();
}
File[] pluginFiles = pluginDir.listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".js"));
List<CheckScript> scripts = new LinkedList<CheckScript>();
for (File file : pluginFiles) {
try {
scripts.add(new CheckScript(file));
} catch (Exception e) {
LOGGER.error("", e);
}
}
JSContextFactory.setCheckScriptList(scripts);
HookHandler.enableHook.set(oldValue);
}
示例3: updateConfigurationFiles
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的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);
}
}
示例4: check1
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的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();
}
示例5: check2
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的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後麵加,則會觸發所有文件創建
}
示例6: findGitRepos
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的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;
}
示例7: findFilesToAnalyze
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
public static List<String> findFilesToAnalyze(String dirPath) {
IOFileFilter gitFilter = FileFilterUtils.notFileFilter(
FileFilterUtils.nameFileFilter(".git")
);
File dir = new File(dirPath);
String[] phpExt = new String[] {"php"};
IOFileFilter phpFilter = new SuffixFileFilter(phpExt, IOCase.INSENSITIVE);
List<File> files = (List<File>) FileUtils.listFiles(dir, phpFilter, gitFilter);
List<String> results = new ArrayList<String>();
for (File f : files) {
try {
results.add(f.getCanonicalPath());
} catch (IOException e) {
e.printStackTrace();
}
}
return results;
}
示例8: getSubdirWithLatestCommit
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
private File getSubdirWithLatestCommit(File rootDir) {
File resultDir = rootDir;
long latestTimestamp = GitUtil.getCheckedoutCommitTimestamp(rootDir);
File [] dirs = rootDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
if (dirs != null) {
for (File dir : dirs) {
logger.debug(" checking timestamp for '{}'", dir);
long dirTimestamp = GitUtil.getCheckedoutCommitTimestamp(dir);
if (dirTimestamp > latestTimestamp) {
resultDir = dir;
latestTimestamp = dirTimestamp;
}
}
}
return resultDir;
}
示例9: getPackages
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
@Override
public List<IPackage> getPackages() {
String masterProjectActionPath = JapiClient.getConfig().getPrefixPath() + JapiClient.getConfig().getProjectJavaPath() + JapiClient.getConfig().getPostfixPath() + "/" + JapiClient.getConfig().getActionReletivePath();
File actionFold = new File(masterProjectActionPath);
if (!actionFold.exists()) {
throw new JapiException(masterProjectActionPath + " fold not exists.");
}
final IOFileFilter dirFilter = FileFilterUtils.asFileFilter(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
Collection<File> folds = FileUtils.listFilesAndDirs(actionFold, dirFilter, TrueFileFilter.INSTANCE);
List<IPackage> packages = new ArrayList<>(folds.size());
for (File fold : folds) {
if (!fold.getAbsolutePath().equals(actionFold.getAbsolutePath())) {
PackageImpl packageImpl = new PackageImpl();
packageImpl.setPackageFold(fold);
packages.add(packageImpl);
}
}
return packages;
}
示例10: getActions
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
@Override
public List<IAction> getActions() {
final IOFileFilter dirFilter = FileFilterUtils.asFileFilter(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(".java") && !pathname.getName().equals("package-info.java");
}
});
Collection<File> actionFiles = FileUtils.listFiles(packageFold, dirFilter, null);
List<IAction> actions = new ArrayList<>();
for (File actionFile : actionFiles) {
ActionImpl action = new ActionImpl();
action.setActionFile(actionFile);
actions.add(action);
}
return actions;
}
示例11: importAttachments
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
/**
* Import attachments from backup folder
*/
private boolean importAttachments(File backupDir) {
File attachmentsDir = StorageHelper.getAttachmentDir(this);
// Moving back
File backupAttachmentsDir = new File(backupDir, attachmentsDir.getName());
if (!backupAttachmentsDir.exists()) return true;
boolean result = true;
Collection list = FileUtils.listFiles(backupAttachmentsDir, FileFilterUtils.trueFileFilter(),
TrueFileFilter.INSTANCE);
Iterator i = list.iterator();
int imported = 0;
File file = null;
while (i.hasNext()) {
try {
file = (File) i.next();
FileUtils.copyFileToDirectory(file, attachmentsDir, true);
mNotificationsHelper.setMessage(TextHelper.capitalize(getString(R.string.attachment)) + " " + imported++ + "/" + list.size())
.show();
} catch (IOException e) {
result = false;
Log.e(Constants.TAG, "Error importing the attachment " + file.getName());
}
}
return result;
}
示例12: run
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
private void run() throws ResourceInitializationException, IOException, SAXException {
Collection<File> inputFiles =
FileUtils.listFiles(inputDir, FileFilterUtils.suffixFileFilter(".xml"), null);
if (inputFiles.isEmpty()) {
return;
}
TypeSystemDescription tsd = TypeSystemDescriptionFactory
.createTypeSystemDescription(typeSystemDescName);
CAS cas = CasCreationUtils.createCas(tsd, null, null);
for (File inputFile : inputFiles) {
AXMLReader.read(inputFile, cas);
File outFile = getOutputFile(inputFile);
OutputStream out = FileUtils.openOutputStream(outFile);
try {
XmiCasSerializer.serialize(cas, null, out, true, null);
} finally {
out.close();
cas.reset();
}
}
}
示例13: initialize
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
super.initialize(ctx);
// initialize mappingFactory
mappingFactory = InitializableFactory.create(ctx, mappingFactoryClassName,
BratUimaMappingFactory.class);
// make bratDocIter
File[] annFiles = bratCollectionDir.listFiles(
(FileFilter) FileFilterUtils.suffixFileFilter(BratDocument.ANN_FILE_SUFFIX));
List<BratDocument> bratDocs = Lists.newArrayListWithExpectedSize(annFiles.length);
for (File annFile : annFiles) {
String docBaseName = FilenameUtils.getBaseName(annFile.getPath());
BratDocument bratDoc = new BratDocument(bratCollectionDir, docBaseName);
if (bratDoc.exists()) {
bratDocs.add(bratDoc);
} else {
throw new IllegalStateException(String.format(
"Missing txt file for %s", annFile));
}
}
totalDocsNum = bratDocs.size();
bratDocIter = bratDocs.iterator();
}
示例14: activate
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
public synchronized void activate() throws MojoExecutionException
{
IOFileFilter logFilter = FileFilterUtils.and(
FileFilterUtils.fileFileFilter(),
FileFilterUtils.nameFileFilter(engineLog.getName()));
FileAlterationObserver fileObserver = new FileAlterationObserver(engineLog.getParent(), logFilter);
fileObserver.addListener(new LogModificationListener());
monitor = new FileAlterationMonitor(100);
monitor.addObserver(fileObserver);
try
{
monitor.start();
}
catch (Exception ex)
{
throw new MojoExecutionException("Failed to activate deploy log forwarder", ex);
}
}
示例15: removeCustomDLC
import org.apache.commons.io.filefilter.FileFilterUtils; //導入依賴的package包/類
/**
* Deletes all non-standard DLC folders from the BioGAme/DLC directory
* using the known list of DLCs
*/
private boolean removeCustomDLC() {
// TODO Auto-generated method stub
File rootFolder = new File(ModManager.appendSlash(RestoreFilesWindow.this.BioGameDir) + "DLC");
if (rootFolder.exists()) {
File[] folders = rootFolder.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
for (File dlcfolder : folders) {
String foldername = dlcfolder.getName();
if (!ModTypeConstants.getStandardDLCFolders().contains(foldername)) {
try {
FileUtils.deleteDirectory(dlcfolder);
ModManager.debugLogger.writeMessage("Deleted DLC folder: " + dlcfolder.getAbsolutePath());
} catch (IOException e) {
ModManager.debugLogger.writeErrorWithException("Unabled to delete DLC folder: " + dlcfolder, e);
return false;
}
}
}
ModManager.debugLogger.writeMessage("Deleted all Custom DLC folders (if there were any)");
publish(Integer.toString(completed));
return true;
} else {
return false;
}
}