@Override protected void setUp() throws Exception { testDir = new File(new File(".") , testDirName); if (testDir.exists()) { org.apache.commons.io.FileUtils.cleanDirectory(testDir); } else { testDir.mkdir(); } IOFileFilter files = org.apache.commons.io.filefilter.FileFilterUtils.fileFileFilter(); IOFileFilter javaSuffix = org.apache.commons.io.filefilter.FileFilterUtils.suffixFileFilter(".java"); IOFileFilter fileFilter = org.apache.commons.io.filefilter.FileFilterUtils.and(files, javaSuffix); IOFileFilter directories = org.apache.commons.io.filefilter.FileFilterUtils.directoryFileFilter(); IOFileFilter visible = HiddenFileFilter.VISIBLE; IOFileFilter dirFilter = org.apache.commons.io.filefilter.FileFilterUtils.and(directories, visible); IOFileFilter filter = org.apache.commons.io.filefilter.FileFilterUtils.or(dirFilter, fileFilter); createObserver(testDir, filter); }
/** * 读取post信息 * <br><i>at 2014年7月12日下午4:36:36</i> * @author lichee * @see <a href="http://nicecoder.net">nicecoder.net</a> */ private void loadPosts(){ PostWalker pw = new PostWalker( HiddenFileFilter.VISIBLE, genFilter ); try { Collection<Post> rs = pw.loadPosts(new File(postsDir)); posts = new HashMap<String,Post>(); for(Post p : rs){ posts.put(p.getTitle(), p); } } catch (IOException e) { e.printStackTrace(); } }
/** * Builds a *VisibleFilesTraverser*. * @param startDirectory * @param ignoreFileNames * @return */ public static VisibleFilesTraverser Get(Path startDirectory, String...ignoreFileNames) { return new VisibleFilesTraverser( startDirectory, ignoreFileNames, FileFilterUtils.or( // Show visible directories FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE), // Show visible files FileFilterUtils.and(FileFilterUtils.fileFileFilter(), HiddenFileFilter.VISIBLE) ) ); }
public static List<File> getFilesFromDirectory(File directory) { IOFileFilter fileFilter = FileFilterUtils.makeSVNAware(HiddenFileFilter.VISIBLE); IOFileFilter dirFilter = FileFilterUtils.makeSVNAware(FileFilterUtils.and( FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE)); return new ArrayList<File>(FileUtils.listFiles(directory, fileFilter, dirFilter)); }
private static List<File> extractPossibleDataFile(File dwcFolder) { List<File> dataFiles = new ArrayList<>(); for (String suffix : DATA_FILE_SUFFICES) { FileFilter ff = FileFilterUtils.and( FileFilterUtils.suffixFileFilter(suffix, IOCase.INSENSITIVE), HiddenFileFilter.VISIBLE ); dataFiles.addAll(Arrays.asList(dwcFolder.listFiles(ff))); } return dataFiles; }
static Archive fromCompressed(Path dwcaLocation, Path destination) throws IOException, UnsupportedArchiveException { if (!Files.exists(dwcaLocation)) { throw new FileNotFoundException("dwcaLocation does not exist: " + dwcaLocation.toAbsolutePath()); } if (Files.exists(destination)) { // clean up any existing folder LOG.debug("Deleting existing archive folder [{}]", destination.toAbsolutePath()); org.gbif.utils.file.FileUtils.deleteDirectoryRecursively(destination.toFile()); } FileUtils.forceMkdir(destination.toFile()); // try to decompress archive try { CompressionUtil.decompressFile(destination.toFile(), dwcaLocation.toFile(), true); // we keep subfolder, but often the entire archive is within one subfolder. Remove that root folder if present File[] rootFiles = destination.toFile().listFiles((FileFilter) HiddenFileFilter.VISIBLE); if (rootFiles.length == 1) { File root = rootFiles[0]; if (root.isDirectory()) { // single root dir, flatten structure LOG.debug("Removing single root folder {} found in decompressed archive", root.getAbsoluteFile()); for (File f : FileUtils.listFiles(root, TrueFileFilter.TRUE, null)) { File f2 = new File(destination.toFile(), f.getName()); f.renameTo(f2); } } } // continue to read archive from the tmp dir return fromLocation(destination); } catch (CompressionUtil.UnsupportedCompressionType e) { throw new UnsupportedArchiveException(e); } }
public void loadVaults() throws IOException, JDOMException { GlacierVaultManager gvm; File gRootDir = getGlacierRootDir(); log.debug("loadVaults(): getGlacierRootDir",getGlacierRootDir()); File[] vaults = gRootDir.listFiles((FileFilter) HiddenFileFilter.VISIBLE); if (vaults != null) { log.debug("loadVaults(): Got {} vaults",vaults.length); for (File vault : vaults) { if(!vault.getName().equals(DefaultResourceCacheDirectoryName)){ String vaultName = vault.getName(); log.debug("loadVaults(): Loading vault: {} vaultName: {}",vault, vaultName); if (vault.isDirectory()) { gvm = new GlacierVaultManager(vaultName,gRootDir); gvm.setParentContext(getGlacierServiceContext()); // gvm.loadArchiveRecords(); gvm.loadIndexObjects(); _vaults.put(gvm.name(),gvm); } } } } }
public void loadIndexObjects() throws IOException, JDOMException { Index index; File indexDir = getIndexDir(); File[] indexFiles = indexDir.listFiles((FileFilter) HiddenFileFilter.VISIBLE); if (indexFiles != null) { for (File indexFile : indexFiles) { if (indexFile.isFile()) { index = new Index(indexFile); StringBuilder resourceId = new StringBuilder(); String pathDelimiter = index.getDelimiter(); resourceId //.append(getGlacierServiceContext()) .append(index.getPath()) .append(pathDelimiter) .append(index.getIndexFileConvention()); index.setResourceId(resourceId.toString()); _indexObjects.put(index.getResourceId(),index); _log.debug("Loaded Index. Vault: {} resourceId: {}", name(), index.getResourceId()); } else { _log.debug("Skipping directory/link {}", indexFile); } } } else { _log.debug("No index files found for vault {}", name()); } }
@Override public void close() throws IOException { // Delete all files that weren't written in this run. Collection<File> files = FileUtils.listFiles(target, HiddenFileFilter.VISIBLE, TrueFileFilter.INSTANCE); for (File file : files) { if (!this.files.contains(file)) { file.delete(); deleteEmptyDirectory(file.getParentFile()); } } }
public List<String> getFolders() throws MojoExecutionException { IOFileFilter folders = FileFilterUtils.and( HiddenFileFilter.VISIBLE, DirectoryFileFilter.DIRECTORY ); IOFileFilter makeSVNAware = FileFilterUtils.makeSVNAware( folders ); IOFileFilter makeCVSAware = FileFilterUtils.makeCVSAware( makeSVNAware ); String[] list = folder.list( makeCVSAware ); if ( list == null ) { throw new MojoExecutionException( "The specified folder doesn't exist: " + folder ); } List<File> listOfDirectories = new ArrayList<File>(); for ( String item : list ) { listOfDirectories.add( new File( folder, item ) ); } Collections.sort( listOfDirectories, convertSortOrder() ); List<String> resultList = new ArrayList<String>(); for ( File file : listOfDirectories ) { resultList.add( file.getName() ); } return resultList; }
public List<InputFile> getFiles() { List<InputFile> result = Lists.newArrayList(); if (getSourceDirs() == null) { return result; } IOFileFilter suffixFilter = getFileSuffixFilter(); WildcardPattern[] exclusionPatterns = getExclusionPatterns(true); IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE; for (File dir : getSourceDirs()) { if (dir.exists()) { // exclusion filter IOFileFilter exclusionFilter = new ExclusionFilter(dir,exclusionPatterns); // visible filter List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter, exclusionFilter); // inclusion filter String inclusionPattern = (String) project.getProperty(SpringPlugin.INCLUDE_FILE_FILTER); if (inclusionPattern != null) { fileFilters.add(new InclusionFilter(dir, inclusionPattern)); } fileFilters.addAll(this.filters); // create DefaultInputFile for each file. List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters), HiddenFileFilter.VISIBLE); for (File file : files) { String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir); result.add(new DefaultInputFile(dir, relativePath)); } } } return result; }
public static List<File> getFilesFromDirectory(File directory) { IOFileFilter fileFilter = FileFilterUtils.makeSVNAware(HiddenFileFilter.VISIBLE); IOFileFilter dirFilter = FileFilterUtils .makeSVNAware(FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE)); return new ArrayList<File>(FileUtils.listFiles(directory, fileFilter, dirFilter)); }
@Override public boolean accept(File file) { return FileFilterUtils.fileFileFilter().accept(file) && HiddenFileFilter.VISIBLE.accept(file); }
@Override public boolean accept(File dir, String name) { File file = new File(dir, name); return FileFilterUtils.directoryFileFilter().accept(file) && HiddenFileFilter.VISIBLE.accept(file) && this.accept(file); }
@Override public boolean accept(File file) { return FileFilterUtils.directoryFileFilter().accept(file) && HiddenFileFilter.VISIBLE.accept(file); }
public LicensableFileDirectoryWalker( IOFileFilter fileFilter, String firstLine, String linePrefix, String lastLine ) { super(HiddenFileFilter.VISIBLE,fileFilter,100); this.firstLine = firstLine; this.linePrefix = linePrefix; this.lastLine = lastLine; }
/** * Limit directories to visible directories * * @return */ public static IOFileFilter defaultDirectoryFilter() { return FileFilterUtils.and( FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // 监控根目录,会递归监控子文件夹变化 String rootDir = "D:\\download"; // 轮询间隔 5 秒,通过重新启动 FileAlterationMonitor 实现 long interval = TimeUnit.SECONDS.toMillis(5); // 创建一个文件观察器用于处理文件的格式 // Create a FileFilter IOFileFilter directories = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE); IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter(".java")); IOFileFilter filter = FileFilterUtils.or(directories, files); // Create the File system observer and register File Listeners FileAlterationObserver observer = new FileAlterationObserver(rootDir, filter, null); observer.addListener(new FileMonitorFileListener()); //设置文件变化监听器 //创建文件变化监听器 FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer); // 开始监控 monitor.start(); }