List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:dk.netarkivet.harvester.harvesting.controller.AbstractJMXHeritrixController.java
/** * Change an environment to be suitable for running Heritrix. * * At the moment, this involves the following: * * Prepend the Jar files from the lib/heritrix/lib dir to the classpath. * Make sure the Heritrix jar file is at the front. * * @param environment//from w w w .j a v a 2 s .com * The environment from a process builder * @throws IOFailure * If a Heritrix jarfile is not found. */ private static void updateEnvironment(Map<String, String> environment) { List<String> classPathParts = SystemUtils.getCurrentClasspath(); File heritrixLibDir = new File("lib/heritrix/lib"); File[] jars = heritrixLibDir.listFiles(new FilenameFilter() { public boolean accept(File file, String string) { return string.endsWith(".jar"); } }); // Reverse sort the file list in order to add in alphabetical order // before the basic jars. Arrays.sort(jars, new Comparator<File>() { public int compare(File file, File file1) { return file1.compareTo(file); } }); String heritixJar = null; for (File lib : jars) { final String jarPath = new File(heritrixLibDir, lib.getName()).getAbsolutePath(); if (lib.getName().startsWith("heritrix-")) { // Heritrix should be at the very head, as it redefines some // of the functions in its dependencies (!). Thus, we have to // save it for later insertion at the head. heritixJar = jarPath; } else { classPathParts.add(0, jarPath); } } if (heritixJar != null) { classPathParts.add(0, heritixJar); } else { throw new IOFailure("Heritrix jar file not found"); } environment.put("CLASSPATH", StringUtils.conjoin(FILE_PATH_SEPARATOR, classPathParts)); }
From source file:com.github.nethad.clustermeister.integration.JPPFTestNode.java
private File getTargetDir(String currentDirPath) { File currentDir = new File(currentDirPath); if (!currentDir.isDirectory()) { throw new RuntimeException("user.dir is not a directory."); }//from w w w . j a v a 2 s . c om File[] listFiles = currentDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.equals("target"); } }); for (File file : listFiles) { if (file.getName().equals("target") && file.isDirectory()) { return file; } } File targetDir = new File(currentDir, "target"); if (targetDir.mkdir()) { return targetDir; } else { throw new RuntimeException("Could not create target directory."); } }
From source file:org.deshang.content.indexing.scheduling.ContentIndexingTask.java
@Override public void run() { List<WpSite> sites = siteService.getAllSites(); Map<WpUser, Map<Long, List<WpPost>>> allUserPosts = new HashMap<WpUser, Map<Long, List<WpPost>>>(); Map<String, Map<Long, List<WpComment>>> allUserComments = new HashMap<String, Map<Long, List<WpComment>>>(); Map<Long, List<WpPost>> allSitePosts = new HashMap<Long, List<WpPost>>(); Map<Long, List<WpComment>> allSiteComments = new HashMap<Long, List<WpComment>>(); for (WpSite site : sites) { LOGGER.debug(//from ww w. j av a2 s.c om "Site info: [id=" + site.getBlogId() + ";domain_path=" + site.getDomain() + site.getPath()); WpUser user = site.getOwner(); LOGGER.debug(" User Info: [id=" + user.getId() + ";login=" + user.getLoginName() + "]"); List<WpPost> publishPosts = postService.getSiteAllPublishPost(site.getBlogId()); LOGGER.debug("Site " + site.getPath() + " with id [" + site.getBlogId() + "] has " + publishPosts.size() + " post(s)."); for (WpPost post : publishPosts) { LOGGER.debug("Post info: [id=" + post.getId() + ";title=" + post.getTitle() + ";content=" + post.getContent() + ";authorUser=" + (post.getAuthorUser() != null ? post.getAuthorUser().getLoginName() : "null") + "]"); // add post into user post map Map<Long, List<WpPost>> userPostMap = allUserPosts.get(post.getAuthorUser()); if (userPostMap == null) { userPostMap = new HashMap<Long, List<WpPost>>(); userPostMap.put(site.getBlogId(), new ArrayList<WpPost>()); allUserPosts.put(post.getAuthorUser(), userPostMap); } List<WpPost> userPosts = userPostMap.get(site.getBlogId()); if (userPosts == null) { userPosts = new ArrayList<WpPost>(); userPostMap.put(site.getBlogId(), userPosts); } userPosts.add(post); // add post into site post map List<WpPost> sitePosts = allSitePosts.get(site.getBlogId()); if (sitePosts == null) { sitePosts = new ArrayList<WpPost>(); allSitePosts.put(site.getBlogId(), sitePosts); } sitePosts.add(post); List<WpComment> comments = post.getAllComments(); LOGGER.debug("Post with id [" + post.getId() + "] has " + comments.size() + " comment(s)."); for (WpComment comment : comments) { String commentAuthorName = comment.getAuthor(); LOGGER.debug("Comment info: [id=" + comment.getId() + ";content=" + comment.getContent() + ";authorUser=" + (comment.getAuthorUser() != null ? comment.getAuthorUser().getLoginName() : "null") + "]"); Map<Long, List<WpComment>> userCommentMap = allUserComments.get(commentAuthorName); if (userCommentMap == null) { userCommentMap = new HashMap<Long, List<WpComment>>(); userCommentMap.put(site.getBlogId(), new ArrayList<WpComment>()); allUserComments.put(commentAuthorName, userCommentMap); } List<WpComment> userComments = userCommentMap.get(site.getBlogId()); if (userComments == null) { userComments = new ArrayList<WpComment>(); userCommentMap.put(site.getBlogId(), userComments); } userComments.add(comment); // add comment into site comment map List<WpComment> siteComments = allSiteComments.get(site.getBlogId()); if (siteComments == null) { siteComments = new ArrayList<WpComment>(); allSiteComments.put(site.getBlogId(), siteComments); } siteComments.add(comment); } } } countDown = new CountDownLatch(allUserPosts.size() + 1); taskScheduler.schedule(new UserContentIndexingTask(INDEX_TOTAL_PATH_NAME, allSitePosts, allSiteComments), new Date()); for (Map.Entry<WpUser, Map<Long, List<WpPost>>> userPostMapEntry : allUserPosts.entrySet()) { Map<Long, List<WpPost>> userPosts = userPostMapEntry.getValue(); WpUser user = userPostMapEntry.getKey(); Map<Long, List<WpComment>> userComments = allUserComments.get(user.getLoginName()); if (userComments == null) { userComments = new HashMap<Long, List<WpComment>>(); } taskScheduler.schedule(new UserContentIndexingTask(user.getLoginName(), userPosts, userComments), new Date()); } try { countDown.await(); } catch (InterruptedException e) { LOGGER.error("Waiting all count down latch error", e); e.printStackTrace(); } File totalDir = new File(rootPath + FILE_SEPARATOR + INDEX_TOTAL_PATH_NAME); TermDocFreqStatistics totalStatistics = new TermDocFreqStatistics(); try { IndexReader reader = DirectoryReader.open(FSDirectory.open(totalDir)); calcPersonTermDocFreqInfo(totalStatistics, reader); totalStatistics.switchPersonToTotal(); } catch (IOException e) { LOGGER.error("Reading index for user error", e); } File rootDir = new File(rootPath); File[] indices = rootDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return !INDEX_TOTAL_PATH_NAME.equals(name); } }); Map<String, TermDocFreqStatistics> userStatistics = new HashMap<String, TermDocFreqStatistics>(); for (File index : indices) { TermDocFreqStatistics personStatistics = totalStatistics.clone(); userStatistics.put(index.getName(), personStatistics); try { IndexReader reader = DirectoryReader.open(FSDirectory.open(index)); calcPersonTermDocFreqInfo(personStatistics, reader); } catch (IOException e) { LOGGER.error("Reading index for user error", e); } } LOGGER.debug("Total terms' statistics are as following."); for (String term : totalStatistics.getAllTotalTerms()) { LOGGER.debug("Term=" + term + "; DocFreq=" + totalStatistics.getTermPersonDocFreq(term) + "; DocFreqPercent=" + totalStatistics.getTermPersonDocFreqPercent(term) + "; TotalDocFreq=" + totalStatistics.getTermTotalDocFreq(term) + "; TotalDocFreqPercent=" + totalStatistics.getTermTotalDocFreqPercent(term)); } Map<String, Map<String, String>> usersPopTerms = new HashMap<String, Map<String, String>>(); for (Map.Entry<String, TermDocFreqStatistics> entry : userStatistics.entrySet()) { LOGGER.debug("User " + entry.getKey() + " terms' statistics are as following."); TermDocFreqStatistics statistics = entry.getValue(); Map<String, String> userPopTerms = usersPopTerms.get(entry.getKey()); if (userPopTerms == null) { userPopTerms = new HashMap<String, String>(); usersPopTerms.put(entry.getKey(), userPopTerms); } for (String term : statistics.getAllPersonTerms()) { LOGGER.debug("Term=" + term + "; DocFreq=" + statistics.getTermPersonDocFreq(term) + "; DocFreqPercent=" + statistics.getTermPersonDocFreqPercent(term) + "; TotalDocFreq=" + statistics.getTermTotalDocFreq(term) + "; TotalDocFreqPercent=" + statistics.getTermTotalDocFreqPercent(term)); double userTermShare = ((double) statistics.getTermPersonDocFreq(term)) / statistics.getTermTotalDocFreq(term); if (statistics.getTermPersonDocFreqPercent(term) > .25 && userTermShare < .90 && statistics.getTermTotalDocFreqPercent(term) < .75) { String termFeatures = statistics.getTermPersonDocFreq(term) + "|" + statistics.getTermPersonDocFreqPercent(term) + "|" + statistics.getTermTotalDocFreq(term) + "|" + statistics.getTermTotalDocFreqPercent(term); userPopTerms.put(term, termFeatures); } } } for (Map.Entry<String, Map<String, String>> entry : usersPopTerms.entrySet()) { LOGGER.info("User " + entry.getKey() + " popular terms' statistics are as following."); for (Map.Entry<String, String> termFeatures : entry.getValue().entrySet()) { LOGGER.info("Term=" + termFeatures.getKey() + "; Features=" + termFeatures.getValue()); } } }
From source file:com.eviware.loadui.launcher.LoadUILauncher.java
private void loadExternalJarsAsBundles() { File source = new File(WORKING_DIR, "ext"); if (source.isDirectory()) { for (File ext : source.listFiles(new FilenameFilter() { @Override/* w ww .jav a 2 s .c om*/ public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".jar"); } })) { try { File tmpFile = File.createTempFile(ext.getName(), ".jar"); BndUtils.wrap(ext, tmpFile); framework.getBundleContext().installBundle(tmpFile.toURI().toString()).start(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:gov.nasa.ensemble.common.io.FileUtilities.java
/** * /* ww w . ja v a 2 s . co m*/ * @param directory * @param extension * @return A list of files in the directory with the specified extension. */ public static File[] getAllFilesWithExtension(File directory, final String extension) { File[] ret = directory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(extension); } }); return ret == null ? new File[0] : ret; }
From source file:com.flexive.core.storage.binary.FxBinaryUtils.java
/** * Remove all files related to a binary/*from w w w . j a v a 2 s .com*/ * * @param divisionId division id * @param binaryId binary id */ public static void removeBinary(int divisionId, final long binaryId) { File baseDir = new File(getBinaryDirectory() + File.separatorChar + String.valueOf(divisionId) + getBinarySubDirectory(binaryId)); if (!baseDir.exists()) return; for (File rm : baseDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith(String.valueOf(binaryId) + "_"); } })) FxFileUtils.removeFile(rm); }
From source file:com.sinosoft.one.mvc.web.instruction.ViewInstruction.java
/** * ???????//from w ww . j a va 2s . c o m * * @param tempHome * @param subDirPath * @return */ private File searchDirectory(File tempHome, String subDirPath) { // String[] subDirs = StringUtils.split(subDirPath, "/"); for (final String subDir : subDirs) { File file = new File(tempHome, subDir); if (!file.exists()) { String[] candidates = tempHome.list(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.equalsIgnoreCase(subDir)) { return true; } return false; } }); if (candidates.length == 0) { tempHome = null; break; } else { tempHome = new File(tempHome, candidates[0]); } } else { tempHome = file; } } return tempHome; }
From source file:com.laxser.blitz.web.instruction.ViewInstruction.java
/** * //from w w w .ja v a 2s .c o m * @param fileNameToFind * @param directoryFile * @param ignoreCase * @return */ private String searchViewFile(File directoryFile, final String fileNameToFind, final boolean ignoreCase) { String[] viewFiles = directoryFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String fileName) { String _notDirectoryViewName = fileNameToFind; String _fileName = fileName; if (ignoreCase) { _fileName = fileName.toLowerCase(); _notDirectoryViewName = fileNameToFind.toLowerCase(); } // ? if (_fileName.startsWith(_notDirectoryViewName) && new File(dir, fileName).isFile()) { if (fileName.length() == fileNameToFind.length() && fileNameToFind.lastIndexOf('.') != -1) { return true; } if (fileName.length() > fileNameToFind.length() && fileName.charAt(fileNameToFind.length()) == '.') { return true; } } return false; } }); Arrays.sort(viewFiles); return viewFiles.length == 0 ? null : viewFiles[0]; }
From source file:com.clican.pluto.orm.dynamic.impl.DynamicORMManagePojoHibernateImpl.java
public void deleteORM(ModelDescription modelDescription) throws ORMManageException { modelContainer.remove(modelDescription); final ModelDescription md = modelDescription; File filePath = new File(tempORMCfgPojoFolder + "/" + Constants.DYNAMIC_MODEL_PACKAGE_PATH); File[] files = filePath.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { if (name.equals(md.getFirstCharUpperName() + ".java") || name.equals(md.getFirstCharUpperName() + ".class") || name.equals("Template" + md.getFirstCharUpperName() + "SiteRelation.java") || name.equals("Template" + md.getFirstCharUpperName() + "SiteRelation.class")) { return true; } else { return false; }//from ww w . j a va2 s. com } }); for (File f : files) { f.delete(); } VelocityContext velocityContext = new VelocityContext(); List<ModelDescription> modelDescriptionList = new ArrayList<ModelDescription>( modelContainer.getModelDescs()); velocityContext.put(modelDescListTempName, modelDescriptionList); generate(filePath.getAbsolutePath() + "/Directory.java", directoryTemplate, velocityContext); generate(filePath.getAbsolutePath() + "/Template.java", templateTemplate, velocityContext); compile(filePath.getAbsolutePath()); try { dynamicClassLoader.refreshClasses(); } catch (ClassNotFoundException e) { throw new ORMManageException(e); } }
From source file:eu.optimis.ip.gui.server.IPManagerWebServiceImpl.java
@Override public ArrayList<String> getLogList(String selectedComponent) { ArrayList<String> ret = new ArrayList<String>(); File dir = new File( ConfigManager.getFilePath(ConfigManager.COMPONENT_LOGGING_FOLDER) + "/" + selectedComponent); File[] files = dir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { File file = new File(dir.getAbsolutePath() + "/" + name); return !file.isDirectory(); }/*from w w w . j a v a 2s.c o m*/ }); for (File file : files) { ret.add(file.getName()); } return ret; }