List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Cleans the directory containing old files. * <p/>// w w w .ja va 2 s . co m * This method does not throw any exception. * * @param toCleanDirectory The directory containing old files to clean. */ private void cleanOutOldFiles(File toCleanDirectory) { if (!toCleanDirectory.exists() || !toCleanDirectory.isDirectory() || !toCleanDirectory.canRead() || !toCleanDirectory.canWrite()) { logger.warn("Can not clean directory:" + toCleanDirectory); return; } int numberDeletedFiles = 0; final String regex = wildCardToClean.replace("?", ".?").replace("*", ".*?"); final Calendar currentCalendar = Calendar.getInstance(); currentCalendar.setTime(new Date()); try { File[] candidateFiles = toCleanDirectory.listFiles(new FileFilter() { @Override public boolean accept(File inputFile) { Calendar lastModifiedCalendar = Calendar.getInstance(); lastModifiedCalendar.setTime(new Date(inputFile.lastModified())); lastModifiedCalendar.add(Calendar.DAY_OF_MONTH, ageToCleanInDays); return lastModifiedCalendar.compareTo(currentCalendar) < 0 && inputFile.getName().matches(regex) && inputFile.isFile() && inputFile.canWrite(); } }); for (File candidateFile : candidateFiles) { candidateFile.delete(); numberDeletedFiles++; } logger.info("Old files cleaned: " + numberDeletedFiles); } catch (Exception e) { // Ignore any error, just log it logger.error("Error while cleaning old files", e); } }
From source file:com.vmware.bdd.manager.ClusterManager.java
private void checkExtraRequiredPackages() { logger.info("check if extra required packages(mailx and wsdl4j) have been installed for Ironfan."); if (!extraPackagesExisted) { File yumRepoPath = new File(Constants.SERENGETI_YUM_REPO_PATH); // use hs to record the packages that have not been added final HashSet<String> hs = new HashSet<String>(); hs.addAll(extraRequiredPackages); // scan the files under the serengeti yum repo directory File[] rpmList = yumRepoPath.listFiles(new FileFilter() { @Override//from w ww . j a v a 2 s. c om public boolean accept(File f) { String fname = f.getName(); int idx = fname.indexOf("-"); if (idx > 0) { String packName = fname.substring(0, idx); if (extraRequiredPackages.contains(packName)) { String regx = packName + commRegex; Pattern pat = Pattern.compile(regx); if (pat.matcher(fname).matches()) { hs.remove(packName); return true; } } } return false; } }); if (!hs.isEmpty()) { logger.info("cannot find all the needed packages, stop and return error now. "); throw BddException.EXTRA_PACKAGES_NOT_FOUND(hs.toString()); } logger.info("the check is successful: all needed packages are there."); extraPackagesExisted = true; } }
From source file:gtu._work.ui.ExecuteOpener.java
void reloadCurrentDirPropertiesList() { DefaultListModel model = new DefaultListModel(); for (File file : jarPositionDir.listFiles(new FileFilter() { public boolean accept(File paramFile) { if (paramFile.getName().toLowerCase().endsWith(".properties")) { return true; }//from www .j a va 2 s.c o m return false; } })) { model.addElement(file); } propertiesList.setModel(model); }
From source file:com.pianobakery.complsa.MainGui.java
public void setDocReaderContent(int addRem) { File theSelFile;/* w w w . ja v a 2s . c o m*/ File theParentFolder; if (addRem == 0) { if (selDocdirContent.size() != 0) { selDocdirContent.clear(); } docSelCounter = -1; int row = docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow()); logger.debug("Selected Doc row: " + row + " RowCount: " + docSearchResTable.getRowCount()); DocSearchModel theModel = (DocSearchModel) docSearchResTable.getModel(); theSelFile = theModel.getDocSearchFile(row).getFile(); theParentFolder = new File(theSelFile.getParent()); File[] dirContentArray = theParentFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isFile()) { return true; } else { return false; } } }); logger.debug("The Selected Doc File: " + theModel.getDocSearchFile(row).getFile()); logger.debug("File Array: " + dirContentArray.length); selDocdirContent = new ArrayList<File>(Arrays.asList(dirContentArray)); logger.debug("File List: " + selDocdirContent.toString()); docSelCounter = selDocdirContent.indexOf(theSelFile); logger.debug("Docselcounter: " + docSelCounter); if ((reader != null) && (docSelCounter > 0) && (docSelCounter < (selDocdirContent.size() - 1))) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if (docSelCounter == 0 && reader != null) { reader.setBeforeDocText("Reached Beginning of Text"); ; reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel("None"); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if ((docSelCounter == (selDocdirContent.size() - 1)) && (reader != null)) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText("Reached End of Text"); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel("None"); } } else if (addRem == -1) { if (docSelCounter == 0) { return; } docSelCounter = docSelCounter - 1; logger.debug("Docselcounter: " + docSelCounter); if ((reader != null) && (docSelCounter > 0) && (docSelCounter < (selDocdirContent.size() - 1))) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if (docSelCounter == 0 && reader != null) { reader.setBeforeDocText("Reached Beginning of Text"); ; reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel("None"); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if ((docSelCounter == (selDocdirContent.size() - 1)) && (reader != null)) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText("Reached End of Text"); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel("None"); } } else if (addRem == 1) { if (docSelCounter == selDocdirContent.size() - 1) { return; } docSelCounter = docSelCounter + 1; logger.debug("Docselcounter: " + docSelCounter); if ((reader != null) && (docSelCounter > 0) && (docSelCounter < (selDocdirContent.size() - 1))) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if (docSelCounter == 0 && reader != null) { reader.setBeforeDocText("Reached Beginning of Text"); ; reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter + 1))); reader.setBeforeChunkLabel("None"); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter + 1), wDir)); } else if ((docSelCounter == (selDocdirContent.size() - 1)) && (reader != null)) { reader.setBeforeDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter - 1))); reader.setSelectedDocText(Utilities.readFileToString(selDocdirContent.get(docSelCounter))); reader.setAfterDocText("Reached End of Text"); reader.setBeforeChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter - 1), wDir)); reader.setSelChunkLabel(Utilities.getRelFileName(selDocdirContent.get(docSelCounter), wDir)); reader.setAfterChunkLabel("None"); } } if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } }
From source file:de.unibi.techfak.bibiserv.BiBiTools.java
/** * finalize one WS call, which includes: -tidy up TmpDir -chmod all spool * data, so we can access (clean) later/*from w ww.j ava 2 s. c o m*/ */ @Override public void finalize() throws Throwable { //clean up recursivly tmp dir if (tmpDir != null) { tmpDir.listFiles(new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { pathname.listFiles(this); } if (!pathname.delete()) { log.error("Deletion of '" + pathname + "' failed."); } return false; } }); } //chmod recursivly all directories within the tools spool directory (if they exists ...) if (spoolDir != null) { spoolDir.listFiles(new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { pathname.listFiles(this); if (!chmodDir(pathname)) { log.error("Chmod of '" + pathname + "' failed."); } } return false; } }); } super.finalize(); }
From source file:edu.umass.cs.gigapaxos.SQLPaxosLogger.java
private File[] getJournalFiles(String additionalMatch) { File[] dirFiles = (new File(this.journaler != null ? this.journaler.logdir : this.logDirectory)) .listFiles(new FileFilter() { @Override//from ww w. ja va 2 s .co m public boolean accept(File pathname) { return pathname.toString() .startsWith(SQLPaxosLogger.this.journaler != null ? SQLPaxosLogger.this.journaler.getLogfilePrefix() : Journaler.getLogfilePrefix(SQLPaxosLogger.this.logDirectory, SQLPaxosLogger.this.strID)) || (additionalMatch != null ? pathname.toString().startsWith(additionalMatch) : false); } }); return dirFiles; }
From source file:edu.mit.viral.shen.DroidFish.java
private final String[] findFilesInDirectory(String dirName, final FileNameFilter filter) { File extDir = Environment.getExternalStorageDirectory(); String sep = File.separator; File dir = new File(extDir.getAbsolutePath() + sep + dirName); File[] files = dir.listFiles(new FileFilter() { public boolean accept(File pathname) { if (!pathname.isFile()) return false; return (filter == null) || filter.accept(pathname.getAbsolutePath()); }/*ww w .j ava 2 s. c o m*/ }); if (files == null) files = new File[0]; final int numFiles = files.length; String[] fileNames = new String[numFiles]; for (int i = 0; i < files.length; i++) fileNames[i] = files[i].getName(); Arrays.sort(fileNames, String.CASE_INSENSITIVE_ORDER); return fileNames; }