本文整理汇总了Java中java.io.FilenameFilter类的典型用法代码示例。如果您正苦于以下问题:Java FilenameFilter类的具体用法?Java FilenameFilter怎么用?Java FilenameFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilenameFilter类属于java.io包,在下文中一共展示了FilenameFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEtr
import java.io.FilenameFilter; //导入依赖的package包/类
public Collection<String> getEtr(){
Collection<File> res = new LinkedList<File>();
File[] listdir = new File(Engine.PROJECTS_PATH).listFiles();
for(File s : listdir){
File tracedir = new File(s,"Traces");
if(tracedir.exists()&&tracedir.isDirectory()){
File[] listconnectors = tracedir.listFiles();
for(File s2 : listconnectors){
res.addAll(Arrays.asList(s2.listFiles(new FilenameFilter(){
public boolean accept(File arg0, String arg1) {
return arg1.endsWith(".etr");
}
})));
}
}
}
Collection<String> listetr = new ArrayList<String>(res.size());
for(File f : res)
listetr.add(f.getPath().substring(Engine.PROJECTS_PATH.length()));
return listetr;
}
示例2: addRegionFilesToCollection
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* filters the files in the par1 directory, and adds them to the par2 collections
*/
private void addRegionFilesToCollection(File worldDir, Collection<File> collection)
{
File file1 = new File(worldDir, "region");
File[] afile = file1.listFiles(new FilenameFilter()
{
public boolean accept(File p_accept_1_, String p_accept_2_)
{
return p_accept_2_.endsWith(".mcr");
}
});
if (afile != null)
{
Collections.addAll(collection, afile);
}
}
示例3: test01
import java.io.FilenameFilter; //导入依赖的package包/类
@Test
public void test01() throws Exception {
String basePackage = "/com.jt.core.proxy";
basePackage = basePackage.replaceAll(".", "/");
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(basePackage);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
String file = url.getFile();
File f = new File(file);
if (f.exists()) {
File[] classes = f.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith("class");
}
});
for (File c : classes) {
System.out.println(c);
}
}
}
}
示例4: setUp
import java.io.FilenameFilter; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
checkpointDir = new File(baseDir, "checkpoint");
dataDir = new File(baseDir, "dataDir");
Assert.assertTrue(checkpointDir.mkdirs() || checkpointDir.isDirectory());
Assert.assertTrue(dataDir.mkdirs() || dataDir.isDirectory());
File[] dataFiles = origDataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.contains("lock")) {
return false;
}
return true;
}
});
for (File dataFile : dataFiles) {
Serialization.copyFile(dataFile, new File(dataDir, dataFile.getName()));
}
}
示例5: getAllLogFiles
import java.io.FilenameFilter; //导入依赖的package包/类
public static Collection<File> getAllLogFiles()
{
FilenameFilter logFilter = new FilenameFilter()
{
public boolean accept(File dir, String name)
{
String lowercaseName = name.toLowerCase();
return lowercaseName.matches("\\d\\d\\d\\d.log");
}
};
File logDir = getLogDirectory();
File[] files = logDir.listFiles(logFilter);
if (files == null)
{
return new ArrayList<File>();
}
else
{
return (Collection<File>) Arrays.asList(files);
}
}
示例6: findFile
import java.io.FilenameFilter; //导入依赖的package包/类
private List<File> findFile(File path, boolean isRecurse) {
// 递归查找文件
List<File> files = new ArrayList<File>();
if (path.isDirectory()) {
File[] candidates = path.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if(name.endsWith(".swp")||name.endsWith(fileSuffix)||ignorePattern.matcher(name).matches()){
return false;
}
return true;
}
});
for (int i = 0; i < candidates.length; i++) {
if (candidates[i].isDirectory() && isRecurse) {
files.addAll(findFile(candidates[i], isRecurse));
} else {
files.add(candidates[i]);
}
}
}
return files;
}
示例7: getInprogressFiles
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* Get a list of files which are under process
*
* @return list of file which are currently being used by WAL writers
*/
public String[] getInprogressFiles() {
if (!initialized) {
return null;
}
String[] files = walDirectory.toFile().list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.endsWith(WAL_INPROGRESS_SUFFIX))
return true;
return false;
}
});
if (null != files && files.length > 0) {
Arrays.sort(files, new WALFileComparator());
}
return files;
}
示例8: prepareVersions
import java.io.FilenameFilter; //导入依赖的package包/类
private List<File> prepareVersions (File file) throws Exception {
List<File> revisionList = new LinkedList<File>();
File dataDir = new File(getDataDir(), "versionscache");
File[] revisions = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("rev");
}
});
for (File rev : revisions) {
if (rev.isFile()) {
revisionList.add(0, rev);
Utils.copyStreamsCloseAll(new FileOutputStream(file), new FileInputStream(rev));
commit(new File[] {file});
}
}
return revisionList;
}
示例9: compress
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* Compress.
*
* @param filename
* the filename
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void compress(String filename) throws IOException {
File current = new File(filename);
File dir = new File(metricPath);
FilenameFilter textFileFilter = (f, s) -> s.endsWith(".txt");
File[] directoryListing = dir.listFiles(textFileFilter);
if (directoryListing != null) {
for (File file : directoryListing) {
if (file.getCanonicalPath() != current.getCanonicalPath()) {
try (FileOutputStream fos = new FileOutputStream(file.getPath() + ".gz");
GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
byte[] buffer = new byte[8192];
int length;
try (FileInputStream fis = new FileInputStream(file.getPath())) {
while ((length = fis.read(buffer)) > 0) {
gzos.write(buffer, 0, length);
}
}
}
file.delete();
}
}
} else {
throw new IOException("Directory not listable: " + metricPath);
}
}
示例10: initTasks
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* Initializes a list of {@link IEvaluationTask} represented in XML by
* XSTream serialization. Uses passed directory or current of omitted.
*
* @param args
*/
public void initTasks(String[] args) {
tasks = new ArrayList<File>();
String evalDir = ".";
if (args.length >= 1) {
evalDir = args[0];
}
File x = new File(evalDir);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".eval.xml");
}
};
tasks.addAll(Arrays.asList(x.listFiles(filter)));
if (args.length >= 2) {
isResume = args[1].equals("--resume");
if(!isResume) {
label = args[1];
} else if(args.length >= 3) {
label = args[2];
}
}
}
示例11: listFilesInDirWithFilter
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* 获取目录下所有符合filter的文件
*
* @param dir 目录
* @param filter 过滤器
* @param isRecursive 是否递归进子目录
* @return 文件链表
*/
public static List<File> listFilesInDirWithFilter(File dir, FilenameFilter filter, boolean isRecursive) {
if (isRecursive) {
return listFilesInDirWithFilter(dir, filter);
}
if (dir == null || !isDir(dir)) {
return null;
}
List<File> list = new ArrayList<>();
File[] files = dir.listFiles();
if (files != null && files.length != 0) {
for (File file : files) {
if (filter.accept(file.getParentFile(), file.getName())) {
list.add(file);
}
}
}
return list;
}
示例12: getFilesByExt
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* Return all files with a given extension in a dir
* @deprecated Is used only by deprecated method
*/
@Deprecated
public static String[] getFilesByExt(String ld, String ext) {
File dir = new File(ld);
String[] names = null;
final String lext = ext;
if (dir.isDirectory()) {
names = dir.list(new FilenameFilter() {
@Override
public boolean accept(File d, String name) {
if (name.endsWith(lext)) {
return true;
}
return false;
}
});
}
return names;
}
示例13: searchFiles
import java.io.FilenameFilter; //导入依赖的package包/类
private static List<File> searchFiles(File dir, FilenameFilter filter) {
List<File> result = new ArrayList<File>();
File[] filesFiltered = dir.listFiles(filter), filesAll = dir.listFiles();
if (filesFiltered != null) {
result.addAll(Arrays.asList(filesFiltered));
}
if (filesAll != null) {
for (File file : filesAll) {
if (file.isDirectory()) {
List<File> deeperList = searchFiles(file, filter);
result.addAll(deeperList);
}
}
}
return result;
}
示例14: findFile
import java.io.FilenameFilter; //导入依赖的package包/类
private static String findFile(String[] likelyPlaces, final String namePattern) {
String path = null;
for (String likelyPlace : likelyPlaces) {
File[] f = new File(likelyPlace).listFiles(new FilenameFilter() {
@Override public boolean accept(File dir, String name) {
return name.matches(namePattern);
}
});
if (f != null && f.length == 1) {
try {
path = f[0].getCanonicalPath();
break;
} catch (IOException e) {
}
}
}
;
return path;
}
示例15: listFilesInDirWithFilter
import java.io.FilenameFilter; //导入依赖的package包/类
/**
* 获取目录下所有符合filter的文件包括子目录
*
* @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();
if (files != null && files.length != 0) {
for (File file : files) {
if (filter.accept(file.getParentFile(), file.getName())) {
list.add(file);
}
if (file.isDirectory()) {
list.addAll(listFilesInDirWithFilter(file, filter));
}
}
}
return list;
}