List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:com.addthis.hydra.task.map.DataPurgeServiceImpl.java
protected void safeDelete(String directoryPrefix, DateTimeFormatter dateTimeFormatter, DateTime oldestDataAllowed, File directory, boolean fileBasedPurge, int dateStartIndex, int dateStringLength) { String dateString;/*w w w .j a va2s . co m*/ if (fileBasedPurge) { File[] fileList = directory.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isFile(); } }); if (fileList != null && fileList.length > 0) { for (File file : fileList) { String fileName = file.getName(); dateString = fileName.substring(dateStartIndex, dateStringLength + dateStartIndex); if (shouldDelete(dateTimeFormatter, oldestDataAllowed, dateString)) { delete(file); } } } } else { String directoryStr = directory.getPath().replace(directoryPrefix, ""); if (directoryStr.startsWith(dirSeperator)) { directoryStr = directoryStr.substring(1); } if (shouldDelete(dateTimeFormatter, oldestDataAllowed, directoryStr)) { delete(directory); } } }
From source file:com.geewhiz.pacify.test.TestUtil.java
private static List<File> getFiles(File folder) { List<File> files = new ArrayList<File>(); Collections.addAll(files, folder.listFiles(new FileFilter() { public boolean accept(File pathName) { return pathName.isFile(); }/*from w w w.ja v a 2 s . c o m*/ })); for (File subFolder : folder.listFiles(new DirFilter())) { files.addAll(getFiles(subFolder)); } return files; }
From source file:com.google.appengine.tck.jsp.JspMojo.java
@Test public void compile() throws Exception { final PathHandler servletPath = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); JspMojo mojo = TL.get();//from w ww . j a v a 2 s .co m final File root = mojo.getJspLocation(); getLog().info(String.format("JSP location: %s", root)); final FileFilter filter = new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(".jsp"); } }; ServletInfo servlet = JspServletBuilder.createServlet("Default Jsp Servlet", "*.jsp"); servlet.addInitParam("mappedfile", Boolean.TRUE.toString()); DeploymentInfo builder = new DeploymentInfo().setClassLoader(JspMojo.class.getClassLoader()) .setContextPath("/tck").setClassIntrospecter(DefaultClassIntrospector.INSTANCE) .setDeploymentName("tck.war").setResourceManager(new FileResourceManager(root, Integer.MAX_VALUE)) .setTempDir(mojo.getTempDir()).setServletStackTraces(ServletStackTraces.NONE).addServlet(servlet); JspServletBuilder.setupDeployment(builder, new HashMap<String, JspPropertyGroup>(), new HashMap<String, TagLibraryInfo>(), new HackInstanceManager()); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); servletPath.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(servletPath); HttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager()); try { for (File jsp : root.listFiles(filter)) { touchJsp(client, jsp.getName()); } } finally { client.getConnectionManager().shutdown(); } }
From source file:maltcms.ui.nb.pipelineRunner.actions.RunMaltcmsPipelinesAction.java
private Action[] buildActions(Lookup lookup) { final IChromAUIProject project = LookupUtils.ensureSingle(lookup, IChromAUIProject.class); Collection<Action> topLevelActions = new ArrayList<>(); File projectPipelinesPath = new File(FileUtil.toFile(project.getLocation()), "pipelines"); File[] maltcmsVersions = projectPipelinesPath.listFiles(new FileFilter() { @Override/* www .jav a 2 s. co m*/ public boolean accept(File f) { return f.isDirectory(); } }); if (maltcmsVersions == null) { return new Action[0]; } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found maltcms versions: {0}", Arrays.deepToString(maltcmsVersions)); for (File maltcmsVersion : maltcmsVersions) { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Checking pipelines below {0}", maltcmsVersion); List<File> c = new ArrayList<>(FileUtils.listFiles(maltcmsVersion, new String[] { "mpl" }, true)); Collections.sort(c, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found {0} pipeline definitions!", c.size()); Collection<Action> actions = new ArrayList<>(); for (File pipelineFile : c) { FileObject fo = FileUtil.toFileObject(pipelineFile); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding pipeline {0}", pipelineFile.getName()); DataObject dobj; try { dobj = DataObject.find(fo); if (dobj instanceof MaltcmsPipelineFormatDataObject) { final MaltcmsPipelineFormatDataObject mpfdo = (MaltcmsPipelineFormatDataObject) dobj; AbstractAction pipelineRunAction = new AbstractAction(fo.getName()) { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Creating PipelineRunOpenSupport"); PipelineRunOpenSupport pos = new PipelineRunOpenSupport( mpfdo.getPrimaryEntry()); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Calling pos.open()!"); pos.open(); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Done!"); } }); } }; Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding dataobject action"); actions.add(pipelineRunAction); // subMenu.add(new JMenuItem(pipelineRunAction)); } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding {0} Pipeline specific actions!", actions.size()); topLevelActions.add(Lookup.getDefault().lookup(INodeFactory.class) .createMenuItem(maltcmsVersion.getName(), actions.toArray(new Action[actions.size()]))); } return topLevelActions.toArray(new Action[topLevelActions.size()]); }
From source file:org.apache.druid.indexing.common.tasklogs.FileTaskLogs.java
@Override public void killOlderThan(final long timestamp) throws IOException { File taskLogDir = config.getDirectory(); if (taskLogDir.exists()) { if (!taskLogDir.isDirectory()) { throw new IOE("taskLogDir [%s] must be a directory.", taskLogDir); }//from w w w . j a va2s.c om File[] files = taskLogDir.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.lastModified() < timestamp; } }); for (File file : files) { log.info("Deleting local task log [%s].", file.getAbsolutePath()); FileUtils.forceDelete(file); if (Thread.currentThread().isInterrupted()) { throw new IOException( new InterruptedException("Thread interrupted. Couldn't delete all tasklogs.")); } } } }
From source file:com.mgmtp.jfunk.core.JFunk.java
/** * Creates a JFunk instance.//from w w w.ja v a 2 s . co m * * @param scriptExecutor * Used to execute the script. * @param threadCount * Number of threads to be used. Allows for parallel execution of test scripts. * @param parallel * Allows a single script to be executed in parallel depending on the number of * threads specified. The argument is ignored if multiple scripts are specified. * @param scripts * A list of test scripts. Must contain at least one script. * @param scriptProperties * script properties passed in with {@code -S<key>=<value>} */ @Inject public JFunk(final ScriptExecutor scriptExecutor, final EventBus eventBus, @Assisted final int threadCount, @Assisted final boolean parallel, @Assisted final List<File> scripts, @Assisted final Properties scriptProperties) { super(eventBus); this.scriptExecutor = scriptExecutor; this.threadCount = threadCount; this.scriptProperties = scriptProperties; List<File> tmpScripts = Lists.newArrayList(); boolean dirChosen = false; boolean fileChosen = false; Set<String> dirNames = newHashSet(); for (File file : scripts) { if (file.isDirectory()) { if (fileChosen) { throw new IllegalArgumentException("Directories and files as arguments cannot be mixed"); } dirNames.add(file.getName()); File[] scriptFiles = file.listFiles(new FileFilter() { @Override public boolean accept(final File f) { return !f.isDirectory() && f.getName().endsWith("groovy"); } }); if (scriptFiles.length == 0) { throw new IllegalArgumentException( "Directory " + file + " does not contain any jFunk script files"); } tmpScripts.addAll(Arrays.asList(scriptFiles)); dirChosen = true; } else { if (dirChosen) { throw new IllegalArgumentException("Directories and files as arguments cannot be mixed"); } dirNames.add(file.getParentFile().getName()); tmpScripts.add(file); fileChosen = true; } } name = on(',').join(dirNames); if (parallel) { if (tmpScripts.size() > 1) { LOG.warn("The '-parallel' argument is ignored because multiple scripts were specified."); } else { // Add the single script to the list, so we have it in there once per thread. File script = tmpScripts.get(0); for (int i = 0; i < threadCount - 1; ++i) { tmpScripts.add(script); } } } this.scripts = tmpScripts; for (File file : this.scripts) { RESULT_LOG.info("Adding " + file.getName() + " to processing queue"); } }
From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java
private static void listEmptyDirectory(File dir, List<File> dataFiles) { if (!dir.isDirectory()) { return;//w w w .j ava2 s. c om } File[] subDirs = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return !pathname.isHidden(); } }); if (subDirs.length == 0) { System.out.println(dir.getAbsolutePath()); dataFiles.add(dir); return; } for (File f : subDirs) { if (f.isDirectory()) { listEmptyDirectory(f, dataFiles); } } }
From source file:com.meltmedia.rodimus.DocumentTransformationTest.java
@Parameters public static Collection<Object[]> parameters() throws URISyntaxException { List<Object[]> fileComparisons = new ArrayList<Object[]>(); URL testRoot = DocumentTransformationTest.class.getClassLoader().getResource("testCases"); File testCaseDir = new File(testRoot.toURI()); for (File docFile : testCaseDir.listFiles(new FileFilter() { @Override// w w w . j a va2 s. c om public boolean accept(File pathname) { return pathname.getName().matches(".*\\.docx"); } })) { File expectedDir = new File(testCaseDir, docFile.getName().replaceFirst("\\A(.*)\\.docx\\Z", "$1")); fileComparisons.add(new Object[] { docFile, expectedDir }); } return fileComparisons; }
From source file:de.tudarmstadt.lt.lm.app.GenerateNgrams.java
public static File generateNgrams(File src_dir, AbstractStringProvider prvdr, int from_cardinality, int to_cardinality, boolean overwrite) { final File ngram_file = new File(src_dir, String.format("%s.%s", src_dir.getName(), "ngrams.txt.gz")); int n_b = from_cardinality, n_e = to_cardinality; if (ngram_file.exists()) { LOG.info("Output file already exists: '{}'.", ngram_file.getAbsolutePath()); if (overwrite) { ngram_file.delete();/*www. j a v a 2 s . c o m*/ LOG.info("Overwriting file: '{}'.", ngram_file.getAbsolutePath()); } else return ngram_file; } File[] src_files = src_dir.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".txt") && (!f.equals(ngram_file)); } }); String[] basenames = new String[src_files.length]; for (int i = 0; i < basenames.length; i++) basenames[i] = src_files[i].getName(); LOG.info(String.format("Reading txt files from dir: '%s'; Files: %s.", src_dir.getAbsolutePath(), StringUtils.abbreviate(Arrays.toString(basenames), 200))); LOG.info(String.format("Writing ngrams to file: '%s'.", ngram_file.getAbsolutePath())); PrintWriter pw = null; try { pw = new PrintWriter( new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(ngram_file)), "UTF-8")); } catch (IOException e) { LOG.error("Could not open writer for file: '{}'.", ngram_file.getAbsolutePath(), e); return null; } long num_ngrams = 0l; List<String>[] ngrams = null; for (int i = 0; i < src_files.length; i++) { File src_file = src_files[i]; LOG.info("Processing file {} / {} ('{}')", i + 1, src_files.length, src_file.getAbsolutePath()); long num_ngrams_f = 0l; try { LineIterator liter = new LineIterator( new BufferedReader(new InputStreamReader(new FileInputStream(src_file), "UTF-8"))); int lc = 0; while (liter.hasNext()) { if (++lc % 1000 == 0) LOG.debug("Processing line {} ({})", lc, src_file); String line = liter.next(); for (String sentence : prvdr.splitSentences(line)) { for (int n = n_b; n <= n_e; n++) { ngrams = null; try { List<String> tokens = prvdr.tokenizeSentence(sentence); if (tokens.isEmpty()) continue; ngrams = AbstractLanguageModel.getNgramSequence(tokens, n); } catch (Exception e) { LOG.warn( "Could not get ngram of cardinality {} from String '{}' in line '{}' from file '{}'.", n, StringUtils.abbreviate(line, 100), lc, src_file.getAbsolutePath()); continue; } for (List<String> ngram : ngrams) pw.println(StringUtils.join(ngram, " ")); pw.flush(); num_ngrams_f += ngrams.length; } } } liter.close(); } catch (Exception e) { LOG.warn("Could not read file '{}'.", src_file.getAbsolutePath(), e); } LOG.debug("Generated {} ngrams from file {}.", num_ngrams_f, src_file); num_ngrams += num_ngrams_f; } if (pw != null) pw.close(); LOG.info("Generated {} ngrams.", num_ngrams); return ngram_file; }
From source file:net.lyonlancer5.mcmp.unmapi.xejon.XejonLoader.java
/** * Enumerates the extensions present and checks for dupes *//*from w w w . j a va 2 s .c o m*/ public void enumerate() { if (success) { LOGGER.info("Enumerating sources from " + Constants.EXTENSIONS_DIR.getAbsolutePath()); List<String> registeredID = Lists.newArrayList(); for (File directory : Constants.EXTENSIONS_DIR.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory(); } })) { LOGGER.trace("Looking in " + directory.getPath()); List<File> jsonFilesInDir = FSTools.findRecursively(directory, TXT_JSON); for (File jsonFile : jsonFilesInDir) { if (jsonFile.getName().endsWith("pack-info.json") || jsonFile.getName().endsWith("pack-info.txt")) { LOGGER.debug("Found JSON pack info in " + directory.getPath()); try { JsonParser parser = new JsonParser(); JsonObject rootObject = parser.parse(new FileReader(jsonFile)).getAsJsonObject(); String str = rootObject.get("id").getAsString(); if (!(str.equals("null") && registeredID.contains(str))) { registeredID.add(str); jsonPackIds.add(Pair.of(str, Pair.of(jsonFile.getParentFile(), rootObject))); LOGGER.debug("Registered an extension pack with ID: " + str); } } catch (IOException | JsonParseException e) { LOGGER.warn("Cannot read pack-info.json in " + jsonFile.getParent() + ", ignoring"); } } } LOGGER.info("Read through " + jsonPackIds.size() + " candidate directories"); } } else { LOGGER.warn("Reflection failed, all extensions will fail to load!"); jsonPackIds.clear(); } }