List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:com.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoExtractor.java
private void print(String rootPath) throws Exception { FileFilter filter = new FileFilter() { @Override//from w ww . jav a2 s.c o m public boolean accept(File pathname) { String lowerCaseName = pathname.getName().toLowerCase(); return (lowerCaseName.endsWith("ifo") && lowerCaseName.startsWith("vts")) || lowerCaseName.endsWith("mkv") || lowerCaseName.endsWith("iso") || lowerCaseName.endsWith("avi"); } }; // parse all the tree under rootPath File rootFolder = new File(rootPath); File[] files = rootFolder.listFiles(); Arrays.sort(files); Map<File, List<File>> mediaMap = new TreeMap<>(); for (File file : files) { System.out.println(file.getName()); // name of the folder -> name of media List<File> fileList; if (file.isDirectory()) { fileList = recurseSubFolder(filter, file); if (!fileList.isEmpty()) { System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } else { if (filter.accept(file)) { fileList = new ArrayList<>(); fileList.add(file); System.out.println("adding " + fileList); mediaMap.put(file, fileList); } } } Set<File> fileNamesSet = mediaMap.keySet(); File outputFile = new File("/home/tagliani/tmp/HD-report.xls"); Workbook wb = new HSSFWorkbook(new FileInputStream(outputFile)); Sheet sheet = wb.createSheet("Toshiba"); MediaInfo MI = new MediaInfo(); int j = 0; for (File mediaFile : fileNamesSet) { List<File> filesList = mediaMap.get(mediaFile); for (File fileInList : filesList) { List<String> audioTracks = new ArrayList<>(); List<String> videoTracks = new ArrayList<>(); List<String> subtitlesTracks = new ArrayList<>(); MI.Open(fileInList.getAbsolutePath()); String durationInt = MI.Get(MediaInfo.StreamKind.General, 0, "Duration", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); System.out.println(fileInList.getName() + " -> " + durationInt); if (StringUtils.isNotEmpty(durationInt) && Integer.valueOf(durationInt) >= 60 * 60 * 1000) { Row row = sheet.createRow(j); String duration = MI.Get(MediaInfo.StreamKind.General, 0, "Duration/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // Create a cell and put a value in it. row.createCell(0).setCellValue(WordUtils.capitalizeFully(mediaFile.getName())); if (fileInList.getName().toLowerCase().endsWith("iso") || fileInList.getName().toLowerCase().endsWith("ifo")) { row.createCell(1).setCellValue("DVD"); } else { row.createCell(1) .setCellValue(FilenameUtils.getExtension(fileInList.getName()).toUpperCase()); } row.createCell(2).setCellValue(FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(mediaFile))); // row.createCell(3).setCellValue(fileInList.getAbsolutePath()); row.createCell(3).setCellValue(duration); // MPEG-2 720x576 @ 25fps 16:9 String format = MI.Get(MediaInfo.StreamKind.Video, 0, "Format", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(4).setCellValue(format); String width = MI.Get(MediaInfo.StreamKind.Video, 0, "Width", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String height = MI.Get(MediaInfo.StreamKind.Video, 0, "Height", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(5).setCellValue(width + "x" + height); String fps = MI.Get(MediaInfo.StreamKind.Video, 0, "FrameRate", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(6).setCellValue(fps); String aspectRatio = MI.Get(MediaInfo.StreamKind.Video, 0, "DisplayAspectRatio/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); row.createCell(7).setCellValue(aspectRatio); int audioStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Audio); for (int i = 0; i < audioStreamNumber; i++) { String audioTitle = MI.Get(MediaInfo.StreamKind.Audio, i, "Title", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String language = MI.Get(MediaInfo.StreamKind.Audio, i, "Language/String3", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String codec = MI.Get(MediaInfo.StreamKind.Audio, i, "Codec", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String channels = MI.Get(MediaInfo.StreamKind.Audio, i, "Channel(s)", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); String sampleRate = MI.Get(MediaInfo.StreamKind.Audio, i, "SamplingRate/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); // AC3 ITA 5.1 48.0KHz StringBuilder sb = new StringBuilder(); if (StringUtils.isEmpty(audioTitle)) { sb.append(codec).append(" ").append(language.toUpperCase()).append(" ") .append(channels); } else { sb.append(audioTitle); } sb.append(" ").append(sampleRate); audioTracks.add(sb.toString()); } int textStreamNumber = MI.Count_Get(MediaInfo.StreamKind.Text); for (int i = 0; i < textStreamNumber; i++) { String textLanguage = MI.Get(MediaInfo.StreamKind.Text, i, "Language/String", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); subtitlesTracks.add(textLanguage); } MI.Close(); row.createCell(8).setCellValue(audioTracks.toString()); row.createCell(9).setCellValue(subtitlesTracks.toString()); j++; } } // System.out.println(mediaName); } try (FileOutputStream fileOut = new FileOutputStream(outputFile)) { wb.write(fileOut); } }
From source file:it.digitalhumanities.dhcpublisher.DHCPublisher.java
private void convert(String unzippedDirName) { File unzippedDir = new File(unzippedDirName); File[] subDirs = unzippedDir.listFiles(new FileFilter() { @Override// w ww. j a va 2s . c om public boolean accept(File pathname) { return pathname.isDirectory(); } }); for (File subDir : subDirs) { System.out.println("Processing directory " + subDir + "..."); try { convertFile(subDir); System.out.println("Conversion in " + subDir + " done."); } catch (Exception e) { e.printStackTrace(); System.out.println("Could not convert HTML in " + subDir); } } }
From source file:gov.nasa.ensemble.common.EnsembleDirectoryWalker.java
public EnsembleDirectoryWalker(File directory) { this(directory, new FileFilter() { @Override/*from w w w . j a va2 s . co m*/ public boolean accept(File pathname) { return true; } }); }
From source file:com.starit.diamond.utils.AppNameUtils.java
private static File[] listFiles(File dir, final String suffix, final String[] excludes) { return dir.listFiles(new FileFilter() { public boolean accept(File file) { return !inExcludes(file, excludes) && file.getName().toLowerCase().endsWith(suffix); }//ww w .j a v a2 s .co m }); }
From source file:azkaban.reportal.util.StreamProviderLocal.java
public String[] getOldFiles(String pathString, final long thresholdTime) throws Exception { File file = new File(pathString); if (!file.exists() || !file.isDirectory()) { return new String[0]; }//from w w w. j a va 2 s . c o m File[] fileList = file.listFiles(new FileFilter() { public boolean accept(File file) { return file.lastModified() < thresholdTime; } }); String[] files = new String[fileList.length]; for (int i = 0; i < fileList.length; i++) { files[i] = fileList[i].getName(); } return files; }
From source file:com.googlecode.t7mp.steps.resources.CopySetenvScriptStep.java
@Override public void execute(Context context) { AbstractT7Mojo mojo = context.getMojo(); File tomcatConfigDirectory = mojo.getTomcatConfigDirectory(); if (tomcatConfigDirectory == null || !tomcatConfigDirectory.exists()) { return;// w w w.java 2s . com } File tomcatDirectory = tomcatConfigDirectory.getParentFile(); File tomcatBinDirectory = new File(tomcatDirectory, "/bin/"); File[] setEnvFiles = tomcatBinDirectory.listFiles(new FileFilter() { @Override public boolean accept(File file) { return (file.isFile() && file.getName().startsWith(PREFIX)); } }); // listFiles returns null if binDirectory does not exist // https://github.com/t7mp/t7mp/issues/28 if (setEnvFiles != null) { for (File scriptFile : setEnvFiles) { try { FileUtils.copyFile(scriptFile, new File(TomcatUtil.getBinDirectory(mojo.getCatalinaBase()), scriptFile.getName())); } catch (IOException e) { throw new TomcatSetupException(e.getMessage(), e); } } } }
From source file:org.apache.fop.cli.Main.java
/** * @return the list of URLs to all libraries. * @throws MalformedURLException In case there is a problem converting java.io.File * instances to URLs.//from w w w .ja va 2 s . c o m */ public static URL[] getJARList() throws MalformedURLException { String fopHome = System.getProperty("fop.home"); File baseDir; if (fopHome != null) { baseDir = new File(fopHome).getAbsoluteFile(); } else { baseDir = new File(".").getAbsoluteFile().getParentFile(); } File buildDir; if ("build".equals(baseDir.getName())) { buildDir = baseDir; baseDir = baseDir.getParentFile(); } else { buildDir = new File(baseDir, "build"); } File fopJar = new File(buildDir, "fop.jar"); if (!fopJar.exists()) { fopJar = new File(baseDir, "fop.jar"); } if (!fopJar.exists()) { throw new RuntimeException( "fop.jar not found in directory: " + baseDir.getAbsolutePath() + " (or below)"); } List jars = new java.util.ArrayList(); jars.add(fopJar.toURI().toURL()); File[] files; FileFilter filter = new FileFilter() { public boolean accept(File pathname) { return pathname.getName().endsWith(".jar"); } }; File libDir = new File(baseDir, "lib"); if (!libDir.exists()) { libDir = baseDir; } files = libDir.listFiles(filter); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { jars.add(files[i].toURI().toURL()); } } String optionalLib = System.getProperty("fop.optional.lib"); if (optionalLib != null) { files = new File(optionalLib).listFiles(filter); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { jars.add(files[i].toURI().toURL()); } } } URL[] urls = (URL[]) jars.toArray(new URL[jars.size()]); /* for (int i = 0, c = urls.length; i < c; i++) { System.out.println(urls[i]); }*/ return urls; }
From source file:de.fatalix.book.importer.BookMigrator.java
private static boolean hasFolderBook(File folder) { return folder.listFiles(new FileFilter() { @Override//w w w . j av a 2s. c om public boolean accept(File file) { return file.getName().contains(".epub") || file.getName().contains(".mobi"); } }).length > 0; }
From source file:com.stratio.mojo.scala.crossbuild.ITs.java
public static boolean verify(final List<String> scalaBinaryVersions, final List<String> artifactNames, final List<String> targetPaths, final List<String> testCases) throws IOException, FileNotFoundException { if (artifactNames.size() != targetPaths.size()) { throw new IllegalArgumentException("artifactNames and modulePaths must be equal size"); }// w w w. j a v a 2s . c o m if (scalaBinaryVersions.isEmpty()) { throw new IllegalArgumentException("At least one scalaBinaryVersion must be provided"); } for (final String scalaBinaryVersion : scalaBinaryVersions) { for (int i = 0; i < artifactNames.size(); i++) { final String artifactName = artifactNames.get(i); final String artifactId = artifactName + "_" + scalaBinaryVersion; final File targetPath = new File(targetPaths.get(i)); final File targetScalaPath = new File(targetPath, scalaBinaryVersion); final File artifactPath = new File(targetScalaPath, artifactId + "-1.jar"); if (!artifactPath.isFile()) { throw new FileNotFoundException("Could not find generated artifact: " + artifactPath); } if (testCases.isEmpty()) { continue; } final File surefireReportsPath = new File(targetScalaPath, "surefire-reports"); if (!surefireReportsPath.isDirectory()) { throw new FileNotFoundException( "Could not find surefire-reports directory: " + surefireReportsPath); } final File[] testReports = surefireReportsPath.listFiles(new FileFilter() { @Override public boolean accept(final File pathname) { return pathname.getName().endsWith(".xml") && pathname.getName().startsWith("TEST-"); } }); if (testReports.length == 0) { throw new FileNotFoundException("Could not find test reports"); } for (final String testCase : testCases) { final String scalaString = "[Scala " + scalaBinaryVersion + "]"; boolean found = false; for (final File testReport : testReports) { final String testReportString = IOUtils.toString(new FileInputStream(testReport)); final String testCaseWithSuffix = testCase + " " + scalaString; if (testReportString.contains(testCaseWithSuffix)) { found = true; break; } } if (!found) { throw new RuntimeException("JUnit XML test report does not contain Scala version string (" + scalaString + ")"); } } } } return true; }
From source file:com.yy.m.filechooser.FileLoader.java
@Override public List<File> loadInBackground() { return FileUtils.getFileList(mPath, mFilter == null ? null : new FileFilter() { @Override//from w w w . j a v a 2 s. c o m public boolean accept(File f) { final String fileName = f.getName().toLowerCase(); return f.isFile() && !fileName.startsWith(FileUtils.HIDDEN_PREFIX) && fileName.endsWith("." + mFilter.toLowerCase()); } }); }