/** * 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; }
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); } }
/** * 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); } } } }
/** * 只监控文件发送变化,如果是子目录的文件改变,则目录会变,由于没有过滤目录发生变化,则目录下的文件改变不会监控到 * @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(); }
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后面加,则会触发所有文件创建 }
/** * 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()}); } }
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"); } }; }
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"); } }; }
/** * 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; }
/** * 找到满足条件的文件,把结果保存到函数的参数中。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; }
/** * 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); } } } }
/** * 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); }
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; }
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; }
@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; }
@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; }
public static List<CorpusSplit> createCrossValidationSplits(File corpusDir, IOFileFilter corpusFileFilter, IOFileFilter corpusSubDirFilter, final int foldsNum) { List<Set<File>> corpusPartitions = partitionCorpusByFileSize( corpusDir, corpusFileFilter, corpusSubDirFilter, foldsNum); List<CorpusSplit> result = Lists.newArrayListWithExpectedSize(foldsNum); for (int f = 0; f < foldsNum; f++) { Set<File> trainingSet = Sets.newLinkedHashSet(); Set<File> testingSet = corpusPartitions.get(f); // fill training set for (int i = 0; i < corpusPartitions.size(); i++) { if (i != f) { trainingSet.addAll(corpusPartitions.get(i)); } } Function<File, String> relPathFunc = relativePathFunction(corpusDir); result.add(new DefaultCorpusSplit( transform(trainingSet, relPathFunc), transform(testingSet, relPathFunc))); } // sanity check if (result.size() != foldsNum) { throw new IllegalStateException(); } return result; }
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); } }
private IOFileFilter fileFilter() { IOFileFilter fileFileFilter = FileFilterUtils.fileFileFilter(); IOFileFilter[] noes = new IOFileFilter[]{ new RegexFileFilter(B + X + D + "class" + E), new RegexFileFilter(B + X + D + "db" + E), new RegexFileFilter(B + X + D + "ear" + E), new RegexFileFilter(B + X + D + "err" + E), new RegexFileFilter(B + X + D + "gif" + E), new RegexFileFilter(B + X + D + "jar" + E), new RegexFileFilter(B + X + D + "jpg" + E), new RegexFileFilter(B + X + D + "lnk" + E), new RegexFileFilter(B + X + D + "log" + E), new RegexFileFilter(B + X + D + "nbm" + E), new RegexFileFilter(B + X + D + "out" + E), new RegexFileFilter(B + X + D + "png" + E), new RegexFileFilter(B + X + D + "war" + E), new RegexFileFilter(B + X + D + "zip" + E) }; IOFileFilter noesFileFilter = FileFilterUtils.notFileFilter(FileFilterUtils.or(noes)); IOFileFilter filter = FileFilterUtils.and(fileFileFilter, noesFileFilter); return filter; }
/** * Copy newer files from the standalone dir to the working artifactory home dir */ private static void copyNewerDevResources(File devEtcDir, File artHome) throws IOException { File homeEtcDir = new File(artHome, "etc"); IOFileFilter fileFilter = new NewerFileFilter(devEtcDir, homeEtcDir); fileFilter = FileFilterUtils.makeSVNAware(fileFilter); FileUtils.copyDirectory(devEtcDir, homeEtcDir, fileFilter, true); updateDefaultMimetypes(homeEtcDir); deleteHaProps(homeEtcDir); /** * If the bootstrap already exists, it means it's not the first startup, so don't keep the original config file * or the etc folder will flood with bootstrap files */ if (new File(homeEtcDir, ArtifactoryHome.ARTIFACTORY_CONFIG_BOOTSTRAP_FILE).exists()) { new File(homeEtcDir, ArtifactoryHome.ARTIFACTORY_CONFIG_FILE).delete(); } }
private void cleanupIncrementalBackupDirectory(FolderInfo sourceFolder, List<ItemInfo> currentFolderChildren, File targetDir) { //Metadata File filter IOFileFilter metadataFilter = new MetadataFileFilter(); //List all artifacts Collection<File> artifacts = Sets.newHashSet( targetDir.listFiles((FileFilter) new NotFileFilter(metadataFilter))); cleanArtifacts(currentFolderChildren, artifacts); //List all sub-target metadata Collection<File> subTargetMetadataFiles = FileUtils.listFiles(targetDir, metadataFilter, DirectoryFileFilter.INSTANCE); cleanMetadata(currentFolderChildren, subTargetMetadataFiles); //List all target metadata File targetDirMetadataContainerFolder = getMetadataContainerFolder(targetDir); Collection<File> targetMetadataFiles = FileUtils.listFiles(targetDirMetadataContainerFolder, metadataFilter, DirectoryFileFilter.INSTANCE); cleanTargetMetadata(sourceFolder, targetMetadataFiles); }
private void assertContent(IOFileFilter filter, Map<String, List<MetricTuple>> result) throws IOException{ for(Entry<String, List<MetricTuple>> entry: result.entrySet()){ File logFile = new File(metricsDir+"//"+entry.getKey()); assertTrue(filter.accept(logFile)); int lineNum = 0; List<MetricTuple> tuples = entry.getValue(); List<String> lines = FileUtils.readLines(logFile); lines.remove(0); for(MetricTuple tuple: tuples){ String[] pair = lines.get(lineNum).split(","); assertEquals(pair[0], String.valueOf(tuple.getTime())); assertEquals(pair[1], tuple.getValue()); lineNum++; } } }
/** * 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. */ private static void innerListFiles(Collection<File> files, File directory, IOFileFilter filter) { File[] found = directory.listFiles((FileFilter) filter); if (found != null) { for (File file : found) { if (file.isDirectory()) { innerListFiles(files, file, filter); } else { files.add(file); } } } }
/** * Finds files within a given directory (and optionally its * subdirectories). All files found are filtered by an IOFileFilter. * <p> * If your search should recurse into subdirectories you can pass in * an IOFileFilter for directories. You don't need to bind a * DirectoryFileFilter (via logical AND) to this filter. This method does * that for you. * <p> * An example: If you want to search through all directories called * "temp" you pass in <code>FileFilterUtils.NameFileFilter("temp")</code> * <p> * Another common usage of this method is find files in a directory * tree but ignoring the directories generated CVS. You can simply pass * in <code>FileFilterUtils.makeCVSAware(null)</code>. * * @param directory the directory to search in * @param fileFilter filter to apply when finding files. * @param dirFilter optional filter to apply when finding subdirectories. * If this parameter is <code>null</code>, subdirectories will not be included in the * search. Use TrueFileFilter.INSTANCE to match all directories. * @return an collection of java.io.File with the matching files * @see org.apache.commons.io.filefilter.FileFilterUtils * @see org.apache.commons.io.filefilter.NameFileFilter */ public static Collection<File> listFiles( File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) { if (!directory.isDirectory()) { throw new IllegalArgumentException( "Parameter 'directory' is not a directory"); } if (fileFilter == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } //Setup effective file filter IOFileFilter effFileFilter = FileFilterUtils.and(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE)); //Setup effective directory filter IOFileFilter effDirFilter; if (dirFilter == null) { effDirFilter = FalseFileFilter.INSTANCE; } else { effDirFilter = FileFilterUtils.and(dirFilter, DirectoryFileFilter.INSTANCE); } //Find files Collection<File> files = new java.util.LinkedList<File>(); innerListFiles(files, directory, FileFilterUtils.or(effFileFilter, effDirFilter)); return files; }
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); } } }
/** * @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); } }
protected IOFileFilter buildFilterBySuffixs(String directory,String ...suffixs) { IOFileFilter iOFileFilter=FileFilterUtils.directoryFileFilter(); //子目录变化 for(String suffix:suffixs) {//后缀过滤器 iOFileFilter=FileFilterUtils.or(iOFileFilter,FileFilterUtils.suffixFileFilter(suffix)); } return iOFileFilter; }
protected IOFileFilter buildFilterByNames(String directory,String ...fileName) { IOFileFilter iOFileFilter=FileFilterUtils.directoryFileFilter(); //子目录变化 for(String name:fileName) {//名字过滤器 iOFileFilter=FileFilterUtils.or(iOFileFilter,FileFilterUtils.nameFileFilter(name)); } return iOFileFilter; }
/** * 监视目录 * @param directory * @param filter * @throws Exception */ protected void monitorDir(String directory,IOFileFilter filter) throws Exception { FileAlterationObserver observer=new FileAlterationObserver(directory,filter); observer.initialize(); observer.addListener(fileListener); observers.add(observer); }
protected FileAlterationObserver buildFileAlterationObserver(String directory) { //后缀过滤器 IOFileFilter suffixFileFilter=FileFilterUtils.or(FileFilterUtils.suffixFileFilter(".class"),FileFilterUtils.suffixFileFilter(".jar")); //子目录变化 IOFileFilter rootAndSubFilefilter=FileFilterUtils.or(FileFilterUtils.directoryFileFilter(),suffixFileFilter); return new FileAlterationObserver(directory,rootAndSubFilefilter); }
/** * 查找需要合并文件的临时文件信息 * * @param directory 临时文件所在的目录 * @param prefix 临时文件的前缀 * @param caseSensitivity 临时文件的大小写敏感 * @return collection */ public static Collection<File> searchPrefixFile(File directory, String prefix, boolean caseSensitivity) { IOCase iocase = IOCase.INSENSITIVE; if (caseSensitivity) { iocase = IOCase.SENSITIVE; } //创建相关的过滤器 IOFileFilter fileFilter = FileFilterUtils.prefixFileFilter(prefix, iocase); //检查相关的过滤信息 return FileUtils.listFiles(directory, fileFilter, FalseFileFilter.INSTANCE); }
/** * Make the given IOFileFilter aware of directories. * * @param filter The filter to make aware of directories. * @param directoryName The directory name which should be payed attention to. * @return The new generated filter. */ public static IOFileFilter makeDirectoryAware( IOFileFilter filter, String directoryName ) { IOFileFilter directoryAwareFilter = FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.directoryFileFilter(), FileFilterUtils.nameFileFilter( directoryName ) ) ); return FileFilterUtils.andFileFilter( filter, directoryAwareFilter ); }
/** * Make the given IOFileFilter aware of files. * * @param filter The filter to make aware of files. * @param fileName The file name which should be payed attention to. * @return The new generated filter. */ public static IOFileFilter makeFileNameAware( IOFileFilter filter, String fileName ) { IOFileFilter directoryAwareFilter = FileFilterUtils.notFileFilter( FileFilterUtils.andFileFilter( FileFilterUtils.fileFileFilter(), FileFilterUtils.nameFileFilter( fileName ) ) ); return FileFilterUtils.andFileFilter( filter, directoryAwareFilter ); }