List of usage examples for java.io FileFilter accept
boolean accept(File pathname);
From source file:org.apache.webdav.lib.WebdavFile.java
public File[] listFiles(FileFilter filter) { WebdavResource res = null;//from w w w. j av a 2 s.c o m try { res = createRes(); WebdavResource allFiles[] = res.listWebdavResources(); if (allFiles == null) return null; ArrayList filtered = new ArrayList(); for (int i = 0; i < allFiles.length; i++) { WebdavFile file = new WebdavFile(allFiles[i].getHttpURL()); if (filter == null || filter.accept(file)) filtered.add(file); } return toFileArray(filtered); } catch (Exception e) { throw new WebdavException(e); } finally { closeRes(res); } }
From source file:org.zeroturnaround.zip.Zips.java
/** * Adds a file entry. If given file is a dir, adds it and all subfiles recursively. * Adding takes precedence over removal of entries. * * @param file file to add.// w ww . j a v a 2 s .c om * @param preserveRoot if file is a directory, true indicates we want to preserve this dir in the zip. * otherwise children of the file are added directly under root. * @param filter a filter to accept files for adding, null means all files are accepted * @return this Zips for fluent api */ public Zips addFile(File file, boolean preserveRoot, FileFilter filter) { if (!file.isDirectory()) { this.changedEntries.add(new FileSource(file.getName(), file)); return this; } Collection files = FileUtils.listFiles(file, null, true); for (Iterator iter = files.iterator(); iter.hasNext();) { File entryFile = (File) iter.next(); if (filter != null && !filter.accept(entryFile)) { continue; } String entryPath = getRelativePath(file, entryFile); if (File.separator.equals("\\")) { // replace directory separators on windows as at least 7zip packs zip with entries having "/" like on linux entryPath = entryPath.replace('\\', '/'); } if (preserveRoot) { entryPath = file.getName() + entryPath; } if (entryPath.startsWith("/")) { entryPath = entryPath.substring(1); } this.changedEntries.add(new FileSource(entryPath, entryFile)); } return this; }
From source file:org.dbflute.helper.io.compress.DfZipArchiver.java
/** * Extract the archive file to the directory. * @param baseDir The base directory to compress. (NotNull) * @param filter The file filter, which doesn't need to accept the base directory. (NotNull) *//*from w ww.j a v a 2 s . c o m*/ public void extract(File baseDir, FileFilter filter) { if (baseDir == null) { String msg = "The argument 'baseDir' should not be null."; throw new IllegalArgumentException(msg); } if (baseDir.exists() && !baseDir.isDirectory()) { String msg = "The baseDir should be directory but not: " + baseDir; throw new IllegalArgumentException(msg); } baseDir.mkdirs(); final String baseDirPath = resolvePath(baseDir); InputStream ins = null; ZipArchiveInputStream archive = null; try { ins = new FileInputStream(_zipFile); archive = new ZipArchiveInputStream(ins, "UTF-8", true); ZipArchiveEntry entry; while ((entry = archive.getNextZipEntry()) != null) { final String entryName = resolveFileSeparator(entry.getName()); // just in case final File file = new File(baseDirPath + "/" + entryName); if (!filter.accept(file)) { continue; } if (entry.isDirectory()) { file.mkdirs(); } else { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } OutputStream out = null; try { out = new FileOutputStream(file); IOUtils.copy(archive, out); out.close(); } catch (IOException e) { String msg = "Failed to IO-copy the file: " + file.getPath(); throw new IllegalStateException(msg, e); } finally { if (out != null) { try { out.close(); } catch (IOException ignored) { } } } } } } catch (IOException e) { String msg = "Failed to extract the files from " + _zipFile.getPath(); throw new IllegalArgumentException(msg, e); } finally { if (archive != null) { try { archive.close(); } catch (IOException ignored) { } } if (ins != null) { try { ins.close(); } catch (IOException ignored) { } } } }
From source file:com.bluexml.side.util.deployer.war.DirectWebAppsDeployer.java
@Override protected void deployProcess(File fileToDeploy, DeployMode mode) throws Exception { System.out.println("DirectWebAppsDeployer.deployProcess() :" + this); FileFilter fileFilter = getFileFilter(mode); File deployedWebbAppFolder = getDeployedWebbAppFolder(); if (!deployedWebbAppFolder.exists()) { this.clean(fileToDeploy); }/* w ww. j a v a 2 s . c o m*/ if (fileToDeploy.exists() && fileToDeploy.isDirectory()) { for (File f : fileToDeploy.listFiles(fileFilter)) { List<String> list = deployFile(f).getList(); deployedFiles.addAll(list); // check if files are copied more than one time, this detect file collision // for (String file : deployedFiles) { // int frequency = Collections.frequency(deployedFiles, file); // if (frequency > 1) { // // conflict detected ... // monitor.addWarningTextAndLog("Beware the file "+file+"have been overrided by module :"+fileToDeploy, ""); // } // } } } else if (fileToDeploy.exists() && fileToDeploy.isFile() && fileFilter.accept(fileToDeploy)) { deployedFiles.addAll(deployFile(fileToDeploy).getList()); } else { monitor.addWarningTextAndLog(Activator.Messages.getString("WarDeployer.5"), ""); } // deploy process is done, we need to mark the deployed webapp File incrementalLastDeploeydFlag = getIncrementalLastDeployedFlag(); System.out.println("DirectWebAppsDeployer.deployProcess() touch " + incrementalLastDeploeydFlag); FileUtils.touch(incrementalLastDeploeydFlag); if (webappReloading) { System.out.println("DirectWebAppsDeployer.deployProcess() touch " + getWebAppXMLFile()); // we touch web.xml too to let tomcat reload the webapp, some webapps should not be restarted FileUtils.touch(getWebAppXMLFile()); } }
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 w w . j a v 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:org.dkf.jed2k.android.LollipopFileSystem.java
@Override public File[] listFiles(File file, org.dkf.jed2k.android.FileFilter filter) { try {/*w w w . ja va 2 s .c om*/ File[] files = file.listFiles(filter); if (files != null) { return files; } } catch (Exception e) { // ignore, try with SAF } LOG.warn("Using SAF for listFiles, could be a costly operation"); DocumentFile f = getDirectory(app, file, false); if (f == null) { return null; // does not exists } DocumentFile[] files = f.listFiles(); if (filter != null && files != null) { List<File> result = new ArrayList<>(files.length); for (int i = 0; i < files.length; i++) { Uri uri = files[i].getUri(); String path = getDocumentPath(uri); if (path == null) { continue; } File child = new File(path); if (filter.accept(child)) { result.add(child); } } return result.toArray(new File[0]); } return new File[0]; }