List of usage examples for java.io FilenameFilter accept
boolean accept(File dir, String name);
From source file:com.mirth.connect.connectors.file.filesystems.SftpConnection.java
@Override public List<FileInfo> listFiles(String fromDir, String filenamePattern, boolean isRegex, boolean ignoreDot) throws Exception { lastDir = fromDir;//from w w w .j ava 2 s. c om FilenameFilter filenameFilter; if (isRegex) { filenameFilter = new RegexFilenameFilter(filenamePattern); } else { filenameFilter = new WildcardFileFilter(filenamePattern.trim().split("\\s*,\\s*")); } cwd(fromDir); @SuppressWarnings("unchecked") Vector<ChannelSftp.LsEntry> entries = client.ls("."); List<FileInfo> files = new ArrayList<FileInfo>(entries.size()); for (Iterator<ChannelSftp.LsEntry> iter = entries.iterator(); iter.hasNext();) { ChannelSftp.LsEntry entry = iter.next(); if (!entry.getAttrs().isDir() && !entry.getAttrs().isLink()) { if (((filenameFilter == null) || filenameFilter.accept(null, entry.getFilename())) && !(ignoreDot && entry.getFilename().startsWith("."))) { files.add(new SftpFileInfo(fromDir, entry)); } } } return files; }
From source file:org.apache.hadoop.hdfs.server.datanode.BlockReportTestBase.java
private List<File> findAllFiles(File top, FilenameFilter mask) { if (top == null) { return null; }// w w w . j a v a 2 s . c om ArrayList<File> ret = new ArrayList<>(); for (File f : top.listFiles()) { if (f.isDirectory()) { ret.addAll(findAllFiles(f, mask)); } else if (mask.accept(f, f.getName())) { ret.add(f); } } return ret; }
From source file:com.vobject.appengine.java.io.File.java
private File[] listChildrenAsFileArray(final FilenameFilter filter, final FileObject dir, final boolean recursive) throws FileSystemException { if (dir.getType() == FileType.FOLDER) { final FileObject[] children = dir.getChildren(); final List list = new ArrayList(); for (int i = 0; i < children.length; i++) { final FileObject child = children[i]; final String fileName = child.getName().getBaseName(); if (filter != null) { if (filter.accept(null, fileName)) { list.add(new File(child)); }// www . j a v a 2s .c o m } else { list.add(new File(child)); } if (child.getType() == FileType.FOLDER) { if (recursive) { File[] childs = listChildrenAsFileArray(filter, child, recursive); list.addAll(Arrays.asList(childs)); } } } return (File[]) list.toArray(new File[0]); } else { return null; } }
From source file:com.vobject.appengine.java.io.File.java
/** * Lists the children of a folder./*w w w. j a va2 s . c o m*/ */ private String[] listChildrenAsStringArray(final FilenameFilter filter, final FileObject dir, final boolean recursive) throws FileSystemException { if (dir.getType() == FileType.FOLDER) { final FileObject[] children = dir.getChildren(); final List list = new ArrayList(); for (int i = 0; i < children.length; i++) { final FileObject child = children[i]; final String fileName = child.getName().getBaseName(); if (filter != null) { if (filter.accept(null, fileName)) { list.add(fileName); } } else { list.add(fileName); } if (child.getType() == FileType.FOLDER) { if (recursive) { String[] childNames = listChildrenAsStringArray(filter, child, recursive); list.addAll(Arrays.asList(childNames)); } } } return (String[]) list.toArray(new String[0]); } else { return null; } }
From source file:org.geoserver.importer.VFSWorker.java
/** * /*from w w w.j a v a2 s . c om*/ * @param archiveFile * @param filter * * @return */ public List<String> listFiles(final File archiveFile, final FilenameFilter filter) { FileSystemManager fsManager; try { fsManager = VFS.getManager(); String absolutePath = resolveArchiveURI(archiveFile); FileObject resolvedFile = fsManager.resolveFile(absolutePath); FileSelector fileSelector = new FileSelector() { /** * @see org.apache.commons.vfs.FileSelector#traverseDescendents(org.apache.commons.vfs.FileSelectInfo) */ public boolean traverseDescendents(FileSelectInfo folderInfo) throws Exception { return true; } /** * @see org.apache.commons.vfs.FileSelector#includeFile(org.apache.commons.vfs.FileSelectInfo) */ public boolean includeFile(FileSelectInfo fileInfo) throws Exception { File folder = archiveFile.getParentFile(); String name = fileInfo.getFile().getName().getFriendlyURI(); return filter.accept(folder, name); } }; FileObject fileSystem; if (fsManager.canCreateFileSystem(resolvedFile)) { fileSystem = fsManager.createFileSystem(resolvedFile); } else { fileSystem = resolvedFile; } LOGGER.fine("Listing spatial data files archived in " + archiveFile.getName()); FileObject[] containedFiles = fileSystem.findFiles(fileSelector); List<String> names = new ArrayList<String>(containedFiles.length); for (FileObject fo : containedFiles) { // path relative to its filesystem (ie, to the archive file) String pathDecoded = fo.getName().getPathDecoded(); names.add(pathDecoded); } LOGGER.fine("Found " + names.size() + " spatial data files in " + archiveFile.getName() + ": " + names); return names; } catch (FileSystemException e) { e.printStackTrace(); } finally { // fsManager.closeFileSystem(fileSystem.getFileSystem()); } return Collections.emptyList(); }
From source file:org.apache.james.mailbox.maildir.MaildirFolder.java
public SortedMap<Long, MaildirMessageName> getUidMap(MailboxSession session, FilenameFilter filter, long from, long to) throws MailboxException { SortedMap<Long, MaildirMessageName> allUids = getUidMap(session, from, to); SortedMap<Long, MaildirMessageName> filteredUids = new TreeMap<Long, MaildirMessageName>(); for (Entry<Long, MaildirMessageName> entry : allUids.entrySet()) { if (filter.accept(null, entry.getValue().getFullName())) filteredUids.put(entry.getKey(), entry.getValue()); }//w w w . j av a2s. c o m return filteredUids; }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ??filter?//from ww w. jav a 2s . c o m * * @param dir * @param filter * @return */ public static List<File> listFilesInDirWithFilter(File dir, FilenameFilter filter) { if (dir == null || !isDir(dir)) return null; List<File> list = new ArrayList<>(); File[] files = dir.listFiles(); for (File file : files) { if (filter.accept(file.getParentFile(), file.getName())) { list.add(file); } if (file.isDirectory()) { list.addAll(listFilesInDirWithFilter(file, filter)); } } return list; }
From source file:org.apache.james.mailbox.maildir.MaildirFolder.java
/** * Reads all uids from the uid list file which match the given filter * and returns as many of them as a sorted map as the limit specifies. * /*from w w w . ja v a2s . c om*/ * * @param session * @param filter The file names of all returned items match the filter. * The dir argument to {@link FilenameFilter}.accept(dir, name) will always be null. * @param limit The number of items; a limit smaller then 1 disables the limit * @return A {@link Map} with all uids and associated {@link MaildirMessageName}s * @throws MailboxException if there is a problem with the uid list file */ public SortedMap<Long, MaildirMessageName> getUidMap(MailboxSession session, FilenameFilter filter, int limit) throws MailboxException { SortedMap<Long, MaildirMessageName> allUids = getUidMap(session, 0, -1); SortedMap<Long, MaildirMessageName> filteredUids = new TreeMap<Long, MaildirMessageName>(); int theLimit = limit; if (limit < 1) theLimit = allUids.size(); int counter = 0; for (Entry<Long, MaildirMessageName> entry : allUids.entrySet()) { if (counter >= theLimit) break; if (filter.accept(null, entry.getValue().getFullName())) { filteredUids.put(entry.getKey(), entry.getValue()); counter++; } } return filteredUids; }
From source file:com.mirth.connect.connectors.file.filesystems.WebDavConnection.java
private List<FileInfo> list(String fromDir, boolean files, FilenameFilter filenameFilter, boolean ignoreDot) throws Exception { client.setPath(fromDir);//from w w w .ja v a2 s . c o m WebdavResource[] resources = client.listWebdavResources(); if (resources == null || resources.length == 0) { return new ArrayList<FileInfo>(); } List<FileInfo> fileInfoList = new ArrayList<FileInfo>(resources.length); for (int i = 0; i < resources.length; i++) { WebdavFile file = null; String filePath = getFullPath(fromDir, resources[i].getPath()); if (secure) { HttpsURL hrl = new HttpsURL("https://" + client.getHost() + filePath); if (!username.equals("null")) { hrl.setUserinfo(username, password); } file = new WebdavFile(hrl); } else { HttpURL hrl = new HttpURL("http://" + client.getHost() + filePath); if (!username.equals("null")) { hrl.setUserinfo(username, password); } file = new WebdavFile(hrl); } if (files) { if (file.isFile() && filenameFilter.accept(null, file.getName()) && !(ignoreDot && file.getName().startsWith("."))) { fileInfoList.add(new WebDavFileInfo(fromDir, file)); } } else if (file.isDirectory()) { fileInfoList.add(new WebDavFileInfo(fromDir, file)); } } return fileInfoList; }
From source file:com.mirth.connect.connectors.file.filesystems.FtpsConnection.java
@Override public List<FileInfo> listFiles(String fromDir, String filenamePattern, boolean isRegex, boolean ignoreDot) throws Exception { FilenameFilter filenameFilter; if (isRegex) { filenameFilter = new RegexFilenameFilter(filenamePattern); } else {/*from w w w . j a v a2 s . co m*/ filenameFilter = new WildcardFileFilter(filenamePattern.trim().split("\\s*,\\s*")); } if (!cwd(fromDir)) { logger.error( "listFiles.changeWorkingDirectory: " + client.getReplyCode() + "-" + client.getReplyString()); throw new IOException("Ftps error: " + client.getReplyCode()); } FTPFile[] files = client.listFiles(); if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { logger.error("listFiles.listFiles: " + client.getReplyCode() + "-" + client.getReplyString()); throw new IOException("Ftps error: " + client.getReplyCode()); } if (files == null || files.length == 0) { return new ArrayList<FileInfo>(); } List<FileInfo> v = new ArrayList<FileInfo>(files.length); for (int i = 0; i < files.length; i++) { if ((files[i] != null) && files[i].isFile()) { if ((filenameFilter == null || filenameFilter.accept(null, files[i].getName())) && !(ignoreDot && files[i].getName().startsWith("."))) { v.add(new FtpsFileInfo(fromDir, files[i])); } } } return v; }