List of usage examples for java.io FilenameFilter FilenameFilter
FilenameFilter
From source file:org.killbill.billing.plugin.meter.timeline.persistent.Replayer.java
private List<File> findCandidates() { final File root = new File(path); final FilenameFilter filter = new FilenameFilter() { @Override// w w w . j a v a 2s . co m public boolean accept(final File file, final String s) { return s.endsWith("bin"); } }; final File[] foundFiles = root.listFiles(filter); return foundFiles == null ? ImmutableList.<File>of() : ImmutableList.<File>copyOf(foundFiles); }
From source file:eu.openanalytics.rsb.data.FileResultStore.java
private File getResultFile(final String applicationName, final String userName, final UUID jobId) { final String jobIdAsString = jobId.toString(); final File[] resultFiles = getResultsDirectory(applicationName, userName).listFiles(new FilenameFilter() { public boolean accept(final File dir, final String name) { return jobIdAsString.equals(StringUtils.substringBefore(name, ".")); }//ww w.java2 s .co m }); if ((resultFiles == null) || (resultFiles.length == 0)) { return null; } if (resultFiles.length > 1) { throw new IllegalStateException("Found " + resultFiles.length + " results for job Id: " + jobId); } return resultFiles[0]; }
From source file:com.github.igor_kudryashov.utils.notes.NotesTempFile.java
/** * Seeking notesXXXXXX folder in temporary directory and checks for file ~notetp2.reg in this * folder.// ww w. j a v a 2 s .c om * * @param tempDir * - temporary directory. * @return temporary directory if the file ~notetp2.reg exist in this directory. */ private String getTemDirFromTempDir(String tempDir) { String temp = null; File file = new File(tempDir); String[] directories = file.list(new FilenameFilter() { @Override public boolean accept(File current, String name) { return new File(current, name).isDirectory(); } }); for (int i = 0; i < directories.length; i++) { if (directories[i].startsWith("notes")) { // check "~notetp2.reg" file String regFilename = tempDir + File.separator + directories[i] + File.separator + NOTES_REG_FILENAME; File regFile = new File(regFilename); if (regFile.exists()) { return regFile.getParent(); } } } return temp; }
From source file:net.oualid.maven.plugins.SurefireDashboardPlugin.java
@Override protected void executeReport(Locale locale) throws MavenReportException { getLog().info("Max tests per line: " + maxTestsPerLine); File f = outputDirectory;/* w ww . j a v a 2 s . c om*/ File resourceFile = new File(f, "site"); resourceFile = new File(resourceFile, "surefiredashboard"); flushResource("/surefiredashboard.css", new File(resourceFile, "surefiredashboard.css")); flushResource("/surefiredashboard.js", new File(resourceFile, "surefiredashboard.js")); getLog().info("Looking for surefire reports in " + f + "..."); File surefireReportDirectory = new File(f, "surefire-reports"); Sink sink = getSink(); sink.head(); sink.title(); sink.text("Surefire dashboard"); sink.title_(); SinkEventAttributeSet atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.TYPE, "text/javascript"); atts.addAttribute(SinkEventAttributes.SRC, "surefiredashboard/surefiredashboard.js"); sink.unknown("script", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); sink.unknown("script", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.HREF, "surefiredashboard/surefiredashboard.css"); atts.addAttribute(SinkEventAttributes.REL, "stylesheet"); atts.addAttribute(SinkEventAttributes.TYPE, "text/css"); atts.addAttribute("media", "all"); sink.unknown("link", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); sink.unknown("link", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); sink.head_(); sink.body(); sink.section1(); sink.sectionTitle1(); sink.text("Surefire dashboard"); sink.sectionTitle1_(); sink.section1_(); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "generatedOn"); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); SimpleDateFormat df = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss"); sink.text("Last published: " + df.format(new Date())); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); File[] files = surefireReportDirectory.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".xml"); } }); if (files == null) { getLog().warn("no surefire tests found !"); } else { for (int i = 0; i < files.length; i++) { File file = files[i]; getLog().info("Found surefire report: " + file.getName()); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(files[i]); NodeList nodes = document.getElementsByTagName("testcase"); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "testClassContainer"); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "testClassTitle"); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); Element suite = (Element) document.getElementsByTagName("testsuite").item(0); sink.text(suite.getAttribute("name")); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "testClass"); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); for (int j = 0; j < nodes.getLength(); j++) { if (j > 0 && j % maxTestsPerLine == 0) { sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "testClass"); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); } Element node = (Element) nodes.item(j); String name = node.getAttribute("name"); String time = node.getAttribute("time"); atts = new SinkEventAttributeSet(); boolean error = node.getElementsByTagName("error").getLength() > 0 || node.getElementsByTagName("failure").getLength() > 0; atts.addAttribute(SinkEventAttributes.CLASS, "testCase " + (error ? "error" : "success")); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); atts = new SinkEventAttributeSet(); sink.unknown("span", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); sink.text(name); sink.unknown("span", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); atts = new SinkEventAttributeSet(); atts.addAttribute(SinkEventAttributes.CLASS, "duration"); sink.unknown("span", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_START) }, atts); sink.text(time); sink.unknown("span", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); if (error && webservicesToCallOnError != null && webservicesToCallOnError.size() > 0) { for (String ws : webservicesToCallOnError) { ws = StringUtils.replace(ws, "{{testname}}", name); callWebservice(ws); } } } sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); sink.unknown("div", new Object[] { new Integer(HtmlMarkup.TAG_TYPE_END) }, null); } catch (ParserConfigurationException e) { getLog().error("Cannot generate section for surefire report: " + file.getName()); } catch (SAXException e) { getLog().error("Cannot generate section for surefire report: " + file.getName()); } catch (IOException e) { getLog().error("Cannot generate section for surefire report: " + file.getName()); } } } sink.body_(); sink.flush(); sink.close(); sink.body(); if (!f.exists()) { f.mkdirs(); } }
From source file:net.centro.rtb.monitoringcenter.infos.OperatingSystemInfo.java
private static String resolveLinuxDistributionName() { File etcDirectory = new File("/etc/"); if (etcDirectory.exists() && etcDirectory.isDirectory()) { File[] releaseFiles = etcDirectory.listFiles(new FilenameFilter() { @Override// w ww.j av a 2s . c o m public boolean accept(File dir, String filename) { return filename.endsWith("-release"); } }); if (releaseFiles != null) { for (File file : releaseFiles) { try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { String line = null; while ((line = bufferedReader.readLine()) != null) { for (Pattern pattern : LINUX_DISTRIBUTION_PATTERNS) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { return matcher.group(1); } } } } catch (Exception e) { logger.debug("Error while reading a Linux release file: {}", file.getAbsolutePath(), e); if (InterruptedException.class.isInstance(e)) { Thread.currentThread().interrupt(); } } } } } return null; }
From source file:com.flexive.core.storage.binary.FxBinaryUtils.java
/** * Remove all expired transit files for the given division * * @param divisionId division//from w w w .j ava 2 s. co m * @return number of expired and removed transit files */ public static int removeExpiredTransitFiles(int divisionId) { File baseDir = new File(getTransitDirectory() + File.separatorChar + String.valueOf(divisionId)); if (!baseDir.exists()) return 0; //nothing to do final long now = System.currentTimeMillis(); int count = 0; for (File expired : baseDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { try { if (name.endsWith(TRANSIT_EXT) && name.indexOf("__") > 0) { long ttl = Long.valueOf(name.split("__")[1].split("\\.")[0]); if (new File(dir.getAbsolutePath() + File.separator + name).lastModified() + ttl < now) return true; } } catch (Exception e) { LOG.error(e); return false; } return false; } })) { count++; FxFileUtils.removeFile(expired); } return count; }
From source file:de.blizzy.backup.Utils.java
public static int getMaxBackupFileIndex(File folder) { if (folder.isDirectory()) { List<String> files = Arrays.asList(folder.list(new FilenameFilter() { @Override/*from www . jav a 2 s .c o m*/ public boolean accept(File dir, String name) { return name.indexOf('-') < 0; } })); if (!files.isEmpty()) { Collections.sort(files, new Comparator<String>() { @Override public int compare(String f1, String f2) { int idx1 = toBackupFileIndex(f1); int idx2 = toBackupFileIndex(f2); if (idx1 < idx2) { return -1; } if (idx1 > idx2) { return 1; } return 0; } }); return toBackupFileIndex(files.get(files.size() - 1)); } } return 0; }
From source file:hudson.maven.RedeployPublisherTest.java
@Test public void testTarGzUniqueVersionTrue() throws Exception { j.configureDefaultMaven();//w ww . j a v a 2 s . co m MavenModuleSet m2 = j.createMavenProject(); File repo = tmp.getRoot(); // a fake build m2.setScm(new SingleFileSCM("pom.xml", getClass().getResource("targz-artifact.pom"))); m2.getPublishersList().add(new RedeployPublisher("", repo.toURI().toString(), true, false)); MavenModuleSetBuild b = m2.scheduleBuild2(0).get(); j.assertBuildStatus(Result.SUCCESS, b); File artifactDir = new File(repo, "test/test/0.1-SNAPSHOT/"); String[] files = artifactDir.list(new FilenameFilter() { public boolean accept(File dir, String name) { System.out.print("deployed file " + name); return name.contains("-bin.tar.gz") || name.endsWith(".jar") || name.endsWith("-bin.zip"); } }); System.out.println("deployed files " + Arrays.asList(files)); assertFalse("tar.gz doesn't exist", new File(repo, "test/test/0.1-SNAPSHOT/test-0.1-SNAPSHOT-bin.tar.gz").exists()); assertTrue("tar.gz doesn't exist", !files[0].contains("SNAPSHOT")); for (String file : files) { if (file.endsWith("-bin.tar.gz")) { String ver = StringUtils.remove(file, "-bin.tar.gz"); ver = ver.substring(ver.length() - 1, ver.length()); assertEquals("-bin.tar.gz not ended with 1 , file " + file, "1", ver); } if (file.endsWith(".jar")) { String ver = StringUtils.remove(file, ".jar"); ver = ver.substring(ver.length() - 1, ver.length()); assertEquals(".jar not ended with 1 , file " + file, "1", ver); } if (file.endsWith("-bin.zip")) { String ver = StringUtils.remove(file, "-bin.zip"); ver = ver.substring(ver.length() - 1, ver.length()); assertEquals("-bin.zip not ended with 1 , file " + file, "1", ver); } } }
From source file:org.cbio.portal.pipelines.foundation.FoundationFileTasklet.java
/** * Return a list of xml files sorted by date (oldest-newest). * Source XML filenames are expected to be date-controlled by <filename>_<date of transfer>.xml * if more than one date-controlled version of the source XML file exists. * @param sourceDirectory// ww w . ja v a2 s.c o m * @return */ private File[] getDateSortedFiles(File sourceDirectory) { File[] sourceFiles = sourceDirectory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); // sort files alphabetically by case-insensitive filename Arrays.sort(sourceFiles, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return sourceFiles; }