當前位置: 首頁>>代碼示例>>Java>>正文


Java FilenameFilter類代碼示例

本文整理匯總了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;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:22,代碼來源:TracePlayerManager.java

示例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);
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:20,代碼來源:AnvilSaveConverter.java

示例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);
            }
        }
    }

}
 
開發者ID:jt120,項目名稱:take,代碼行數:24,代碼來源:ProxyParseFactoryTest.java

示例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()));
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:20,代碼來源:TestFileChannelIntegrityTool.java

示例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);
	}
}
 
開發者ID:BytingBulldogs3539,項目名稱:BBLIB,代碼行數:22,代碼來源:Logger.java

示例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;
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:23,代碼來源:LocalFileSource.java

示例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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:WriteAheadLog.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:HistoryTest.java

示例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);
	}
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:34,代碼來源:InfluxDbFileReporter.java

示例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];
        }
    }
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:30,代碼來源:ServerRunner.java

示例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;
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:27,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:23,代碼來源:IntrospectionUtils.java

示例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;
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:19,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:JavaProfile.java

示例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;
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:24,代碼來源:FileUtils.java


注:本文中的java.io.FilenameFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。