List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:com.meltmedia.rodimus.DocumentTransformationTest.java
@Test public void diffWithOutWhitespace() throws IOException { for (File expectedHtmlFile : expectedOutputDir.listFiles(new FileFilter() { @Override//from w ww . jav a 2 s . co m public boolean accept(File pathname) { return pathname.isFile(); } })) { File actualHtmlFile = new File(actualOutputDir, expectedHtmlFile.getName()); Diff diff = Diff.diff(expectedHtmlFile, actualHtmlFile, true); if (!diff.isEmpty()) { // build up the output. fail(diff.toUnifiedDiff("expected", "actual", new FileReader(expectedHtmlFile), new FileReader(actualHtmlFile), 3)); } } }
From source file:org.ala.spatial.analysis.index.LayerDistanceIndex.java
/** * @param threadcount number of threads to run analysis. * @param onlyThesePairs array of distances to run as fieldId1 + " " + * fieldId2 where fieldId1.compareTo(fieldId2) < 0 or null for all missing * distances.//from ww w. j a v a2 s . c o m * @throws InterruptedException */ public void occurrencesUpdate(int threadcount, String[] onlyThesePairs) throws InterruptedException { //create distances file if it does not exist. File layerDistancesFile = new File(AlaspatialProperties.getAnalysisWorkingDir() + LAYER_DISTANCE_FILE); if (!layerDistancesFile.exists()) { try { FileWriter fw = new FileWriter(layerDistancesFile); fw.close(); } catch (Exception e) { e.printStackTrace(); } } Map<String, Double> map = loadDistances(); LinkedBlockingQueue<String> todo = new LinkedBlockingQueue(); if (onlyThesePairs != null && onlyThesePairs.length > 0) { for (String s : onlyThesePairs) { todo.add(s); } } else { //find all environmental layer analysis files File root = new File(AlaspatialProperties.getAnalysisLayersDir()); File[] dirs = root.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname != null && pathname.isDirectory(); } }); HashMap<String, String> domains = new HashMap<String, String>(); for (File dir : dirs) { //iterate through files so we get everything File[] files = new File(dir.getPath()).listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".grd") && pathname.getName().startsWith("el"); } }); for (int i = 0; i < files.length; i++) { for (int j = i + 1; j < files.length; j++) { String file1 = files[i].getName().replace(".grd", ""); String file2 = files[j].getName().replace(".grd", ""); //only operate on file names that are valid fields if (Client.getFieldDao().getFieldById(file1) != null && Client.getFieldDao().getFieldById(file2) != null) { String domain1 = domains.get(file1); if (domain1 == null) { String pid1 = Client.getFieldDao().getFieldById(file1).getSpid(); domain1 = Client.getLayerDao().getLayerById(Integer.parseInt(pid1)).getdomain(); domains.put(file1, domain1); } String domain2 = domains.get(file2); if (domain2 == null) { String pid2 = Client.getFieldDao().getFieldById(file2).getSpid(); domain2 = Client.getLayerDao().getLayerById(Integer.parseInt(pid2)).getdomain(); domains.put(file2, domain2); } String key = (file1.compareTo(file2) < 0) ? file1 + " " + file2 : file2 + " " + file1; //domain test if (isSameDomain(parseDomain(domain1), parseDomain(domain2))) { if (!map.containsKey(key) && !todo.contains(key)) { todo.put(key); } } } } } } } LinkedBlockingQueue<String> toDisk = new LinkedBlockingQueue<String>(); CountDownLatch cdl = new CountDownLatch(todo.size()); CalcThread[] threads = new CalcThread[threadcount]; for (int i = 0; i < threadcount; i++) { threads[i] = new CalcThread(cdl, todo, toDisk); threads[i].start(); } ToDiskThread toDiskThread = new ToDiskThread( AlaspatialProperties.getAnalysisWorkingDir() + LAYER_DISTANCE_FILE, toDisk); toDiskThread.start(); cdl.await(); for (int i = 0; i < threadcount; i++) { threads[i].interrupt(); } toDiskThread.interrupt(); }
From source file:com.manydesigns.portofino.dispatcher.DispatcherLogic.java
protected static void appendChildrenToPagesSelectionProvider(File baseDir, File parentDir, String breadcrumb, DefaultSelectionProvider selectionProvider, boolean includeDetailChildren, File... excludes) { FileFilter filter = new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory(); }//from w ww.j a va 2s .c o m }; for (File dir : parentDir.listFiles(filter)) { try { appendToPagesSelectionProvider(baseDir, dir, breadcrumb, selectionProvider, includeDetailChildren, excludes); } catch (Exception e) { logger.error(e.getMessage(), e); } } }
From source file:com.univpm.s1055802.faceplusplustester.Gallery.GalleryVideosFragment.java
/** * Ottiene la lista di tutti gli Uri dei video contenuti in una cartella * @param dir la cartella specificata/* w w w. j a v a 2 s .co m*/ */ public void getFromDir(String dir) { File file = new File(dir); videoFiles = new ArrayList<>(); if (file.isDirectory()) { File[] listDir = file.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } }); filePath = new ArrayList<>(); Log.v("video", String.valueOf(listDir.length)); for (int i = 0; i < listDir.length; i++) { Log.v("i: ", String.valueOf(i)); File[] videoDirFiles = listDir[i].listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { File file = new File(dir.getPath(), name); return (name.toLowerCase().endsWith(".mp4") && file.length() > 10); } }); if (videoDirFiles.length >= 1) { framesDir = new File(listDir[i], "Frames"); if (framesDir.isDirectory()) { File[] listFrames = framesDir.listFiles(); if (framesDir.listFiles().length >= 1) { videoFiles.add(videoDirFiles[0]); filePath.add(Uri.fromFile(listFrames[0]).toString()); /*} else { filePath.add(FileUtils.resourceToUri(GalleryVideosFragment.this.getContext(), R.drawable.fpp_no_video).toString()); */} } } } } }
From source file:org.alex73.skarynka.scan.process.ProcessDaemon.java
boolean process() throws Exception { LOG.debug("check for processing..."); if (Context.getPermissions().ProcessingControls) { // process control files LOG.trace("check for control dir " + Context.getControlDir()); File[] controls = new File(Context.getControlDir()).listFiles(new FileFilter() { public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".do"); }/* w w w. ja v a2 s . co m*/ }); if (controls != null) { LOG.trace("control files found: " + controls.length); for (File c : controls) { LOG.trace("check for control file " + c); File errorFile = new File(c.getPath() + ".err"); File outFile = new File(c.getPath() + ".out"); if (errorFile.exists() || outFile.exists()) { continue; } try { String cmd = FileUtils.readFileToString(c, "UTF-8"); String result = ProcessCommands.call(cmd); FileUtils.writeStringToFile(outFile, result, "UTF-8"); } catch (Throwable ex) { FileUtils.writeStringToFile(errorFile, ex.getMessage(), "UTF-8"); } } } } if (paused) { return false; } if (Context.getPermissions().ProcessingBooks) { // process books LOG.trace("check for book dir " + Context.getBookDir()); File[] ls = new File(Context.getBookDir()).listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.isDirectory() && new File(pathname, "book.properties").isFile(); } }); if (ls == null) { LOG.trace("books not found"); return false; } int count = 0; for (File d : ls) { LOG.trace("check for book dir " + d); File processFile = new File(d, ".process"); if (!processFile.exists()) { // processing wasn't started yet continue; } File processDoneFile = new File(d, ".process.done"); if (processDoneFile.exists()) { // processing finished continue; } File errorFile = new File(d, ".errors"); if (errorFile.exists()) { // if book contains error files - skip this book continue; } LOG.debug("Process book " + d); Book2 book = new Book2(d); if (!book.getErrors().isEmpty()) { FileUtils.writeStringToFile(errorFile, "Error read book: " + book.getErrors(), UTF8); continue; } String command = FileUtils.readFileToString(processFile, UTF8); Script newScript; try { // update compiled script if script file was updated newScript = new Script(command); if (currentScript == null || !currentScript.theSame(newScript)) { currentScript = newScript; currentScript.compile(); } } catch (Throwable ex) { FileUtils.writeStringToFile(errorFile, "Error get script: " + ex.getMessage(), UTF8); continue; } boolean wasError = false; for (String p : book.listPages()) { if (finish) { return false; } // PageFileInfo pfi = new PageFileInfo(book, p); try { if (currentScript.pageResultExist(book, p)) { continue; } currentScript.pageExecute(book, p); count++; } catch (Throwable ex) { LOG.info("Error process page " + p, ex); FileUtils.writeStringToFile(errorFile, "Error process page #" + p + ": " + ex.getMessage(), UTF8); wasError = true; break; } if (count >= 5) { return true; } } // pages process was finished - need to finish book try { if (!wasError) { if (!currentScript.bookResultExist(book)) { currentScript.bookExecute(book); } } } catch (Throwable ex) { LOG.info("Error process book", ex); FileUtils.writeStringToFile(errorFile, "Error process book: " + ex.getMessage(), UTF8); wasError = true; break; } if (!wasError) { // book finished without errors processFile.renameTo(processDoneFile); } } } return false; }
From source file:edu.unc.lib.dl.services.BatchIngestQueue.java
public File[] getFailedDirectories() { File[] batchDirs = this.failedDirectory.listFiles(new FileFilter() { @Override// ww w . jav a 2 s. c o m public boolean accept(File arg0) { return arg0.isDirectory(); } }); if (batchDirs != null) { Arrays.sort(batchDirs, new Comparator<File>() { @Override public int compare(File o1, File o2) { if (o1 == null || o2 == null) return 0; return (int) (o1.lastModified() - o2.lastModified()); } }); return batchDirs; } else { return new File[] {}; } }
From source file:info.dolezel.fatrat.plugins.helpers.JarClassLoader.java
public void loadAllExtensions(String path) throws Exception { File f = new File(path); File[] extensions = f.listFiles(new FileFilter() { @Override//from w w w . j a va 2 s. c o m public boolean accept(File pathname) { return pathname.getName().endsWith(".jar"); } }); for (File e : extensions) addExtension(e.getAbsolutePath()); }
From source file:com.googlecode.t7mp.steps.deployment.ResolveTomcatStep.java
private void copyToTomcatDirectory(File unpackDirectory) throws IOException { File[] files = unpackDirectory.listFiles(new FileFilter() { @Override/*from www . ja v a 2s. c om*/ public boolean accept(File file) { return file.isDirectory(); } }); // should only be one FileUtils.copyDirectory(files[0], this.mojo.getCatalinaBase()); }
From source file:com.splunk.shuttl.server.mbeans.rest.ArchiveBucketEndpoint.java
private File[] listFilesThatAreNotRawdataDirNorDotFiles(LocalBucket localBucket) { return localBucket.getDirectory().listFiles(new FileFilter() { @Override/*from ww w . jav a 2 s .c om*/ public boolean accept(File f) { if (isRawdataOrDotFile(f.getName())) return false; return true; } private boolean isRawdataOrDotFile(String fileName) { return fileName.equals("rawdata") || fileName.startsWith("."); } }); }
From source file:com.tulskiy.musique.library.Library.java
public void rescan(Map<String, Object> progress) { List<String> folders = LibraryConfiguration.getFolders(); if (CollectionUtils.isEmpty(folders)) { return;//from w w w . j a v a2 s. c om } progress.put("processing.file", ""); data.removeDeadItems(); HashMap<TrackData, Track> trackDatas = new HashMap<TrackData, Track>(); for (Track track : data) { trackDatas.put(track.getTrackData(), track); } LinkedList<File> queue = new LinkedList<File>(); for (String path : folders) { File f = new File(path); if (f.exists()) queue.add(f); } HashSet<Track> processed = new HashSet<Track>(); final Set<String> formats = Codecs.getFormats(); ArrayList<Track> temp = new ArrayList<Track>(); while (!queue.isEmpty()) { try { File file = queue.pop(); if (progress != null) { if (progress.get("processing.stop") != null) { break; } progress.put("processing.file", file.getAbsolutePath()); } if (file.isDirectory()) { queue.addAll(0, Arrays.asList(file.listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.isHidden() || !file.canRead()) { return false; } if (file.isDirectory()) return true; String ext = Util.getFileExt(file).toLowerCase(); if (formats.contains(ext)) { String name = Util.removeExt(file.getAbsolutePath()) + ".cue"; return !new File(name).exists(); } return ext.equals("cue"); } }))); } else { TrackData trackData = new TrackData(file.toURI(), 0); Track track = trackDatas.get(trackData); if (track != null) { if (track.getTrackData().getLastModified() != file.lastModified()) { track.getTrackData().clearTags(); TrackIO.getAudioFileReader(file.getName()).reload(track); } processed.add(track); } else { temp.clear(); TrackIO.getAudioFileReader(file.getName()).read(file, temp); for (Track newTrack : temp) { trackData = newTrack.getTrackData(); if (trackDatas.containsKey(trackData)) { // it must be the cue file, so merge the track data trackData.merge(newTrack.getTrackData()); } processed.add(newTrack); } } } } catch (Exception e) { e.printStackTrace(); } } data.clear(); data.addAll(processed); processed.clear(); trackDatas.clear(); rebuildTree(); }