List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:eu.esdihumboldt.hale.common.headless.impl.WorkspaceServiceImpl.java
/** * Triggers the service scanning for workspace folders where the lease time * has ended and deletes them./*from w ww . j av a 2 s . c o m*/ */ public void trigger() { for (File candidate : parentDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isHidden() && file.isDirectory() && configFile(file).exists(); } })) { // retrieve lease end time DateTime leaseEnd = null; try { PropertiesFile configFile = new PropertiesFile(configFile(candidate)); leaseEnd = DateTime.parse(configFile.getProperty(PROPERTY_LEASE_END)); } catch (Exception e) { log.error("Failed to retrieve workspace folder lease end time.", e); } if (leaseEnd != null) { if (leaseEnd.isBeforeNow()) { // delete folder try { FileUtils.deleteDirectory(candidate); } catch (IOException e) { log.error("Error deleting workspace folder", e); } if (candidate.exists()) { log.error("Failed to delete workspace folder, leaving it for next time."); } else { configFile(candidate).delete(); log.info("Removed workspace " + candidate.getName() + " after lease expired."); } } } } }
From source file:com.freedomotic.environment.impl.EnvironmentRepositoryImpl.java
/** * * * @param folder//from w ww . j av a2s . c om * @throws RepositoryException */ private static void deleteEnvFiles(File folder) throws RepositoryException { if ((folder == null) || !folder.isDirectory()) { throw new IllegalArgumentException("Unable to delete environment files in a null or not valid folder"); } // this filter only returns thing files FileFilter objectFileFileter = new FileFilter() { @Override public boolean accept(File file) { if (file.isFile() && file.getName().endsWith(ENVIRONMENT_FILE_EXTENSION)) { return true; } else { return false; } } }; File[] files = folder.listFiles(objectFileFileter); for (File file : files) { boolean deleted = file.delete(); if (!deleted) { throw new RepositoryException("Unable to delete file " + file.getAbsoluteFile()); } } }
From source file:org.atomserver.core.filestore.FileBasedContentStorage.java
/** * {@inheritDoc}//from w w w . j a va 2s .co m */ public List<String> listCollections(String workspace) { List<String> collections = new ArrayList<String>(); for (File file : pathFromRoot(workspace).listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.exists() && pathname.isDirectory() && pathname.canRead() && pathname.canWrite() && !pathname.isHidden(); } })) { collections.add(file.getName()); } return collections; }
From source file:de.blizzy.documentr.subscription.SubscriptionStore.java
public Set<String> getSubscriberEmails(String projectName, String branchName, String path) throws IOException { ILockedRepository repo = null;//w w w . j a v a2 s . co m try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().endsWith(SUBSCRIPTIONS_SUFFIX); } }; List<File> files = Lists.newArrayList(workingDir.listFiles(fileFilter)); Function<File, String> loginNamesFunction = new Function<File, String>() { @Override public String apply(File file) { return StringUtils.removeEnd(file.getName(), SUBSCRIPTIONS_SUFFIX); } }; List<String> loginNames = Lists.transform(files, loginNamesFunction); Set<String> emails = Sets.newHashSet(); for (Iterator<String> iter = loginNames.iterator(); iter.hasNext();) { String loginName = iter.next(); User user = userStore.getUser(loginName); if (isSubscribed(projectName, branchName, path, user, repo)) { emails.add(user.getEmail()); } } log.debug("emails subscribed to {}/{}/{}: {}", projectName, branchName, Util.toUrlPagePath(path), //$NON-NLS-1$ emails); return emails; } finally { Closeables.closeQuietly(repo); } }
From source file:net.paoding.analysis.analyzer.impl.CompiledFileDictionaries.java
public synchronized void startDetecting(int interval, DifferenceListener l) { if (detector != null || interval < 0) { return;//from w w w . ja v a 2s.co m } Detector detector = new Detector(); detector.setHome(dicHome); detector.setFilter(null); detector.setFilter(new FileFilter() { public boolean accept(File pathname) { return pathname.getPath().endsWith(".dic.compiled") || pathname.getPath().endsWith(".metadata"); } }); detector.setLastSnapshot(detector.flash()); detector.setListener(l); detector.setInterval(interval); detector.start(true); this.detector = detector; }
From source file:com.github.scizeron.jidr.maven.plugin.JidrPackageApp.java
/** * //from w ww. jav a 2 s.c o m * @param inputDirectoryName * @param outputDirName * @throws Exception */ private void addExtraFiles(String inputDirectoryName, String outputDirName) throws Exception { final File inputDirectory = new File(inputDirectoryName); final File outputDirectory = new File(outputDirName); if (!inputDirectory.exists()) { return; } getLog().info(String.format("Add the \"%s\" file(s) in %s.", inputDirectoryName, outputDirName)); FileUtils.copyDirectory(inputDirectory, outputDirectory, new FileFilter() { @Override public boolean accept(File file) { return true; } }, true); getLog().info(String.format("The \"%s\" contains :", outputDirName)); final String[] files = outputDirectory.list(); for (String file : files) { getLog().info(String.format(" - %s", file)); } }
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileUtility.java
/** * Retrieves the set of backup directories located in the base-directory/backup directory. * //from w w w .j av a2 s .com * @param baseDirectory Used as the base to form the backup directory. * @return The set of backup directories (in the form yyyy-MM-dd_HH-mm-ss) located in the backup directory. */ public Set<String> getLatestBackupDirectories(String baseDirectory) { Set<String> fileSet = new TreeSet<String>(); File fileDirectory = new File(baseDirectory + "/backup"); if (fileDirectory.isDirectory()) { File[] backupDirectories = fileDirectory.listFiles(new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }); for (File directory : backupDirectories) { fileSet.add(directory.getName()); } } return fileSet; }
From source file:gov.va.vinci.leo.cr.BaseFileCollectionReader.java
/** * Find the list of files that meet the requirements. * * @param f the file to search. This should be a directory. *//*from ww w. java 2 s . co m*/ protected void findFiles(File f) { if (f == null || !f.exists()) return; File[] files; if (filenameFilter != null) { files = f.listFiles(filenameFilter); File[] directories = f.listFiles(new FileFilter() { public boolean accept(File f) { return f.isDirectory(); } }); files = ArrayUtils.addAll(files, directories); } else { files = f.listFiles(); } for (File file : files) { if (!file.isDirectory()) { mFileCollection.add(file); } else if (mRecurse) { findFiles(file); } //else if mRecurse } //for }
From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java
/** * Main execution method for the transport mode. Imports the SIP files in * the sourceRoot to DESA repository (configured in config property file). * The status of the import of each SIP is written in the results XML file * named TRANSF_packageid.xml in the resultsRoot folder. The JDK logging * output is mirrored in the packageid.log file in the logRoot folder. * * @param sourceRoot//from w w w.j a v a 2 s . c om * @param resultsRoot * @param logRootIn */ public int[] transport(String sourceRoot, String resultsRoot, String logRootIn) { long timeStart = System.currentTimeMillis(); logRoot = logRootIn; Handler handler = null; File[] sourceFiles; File resultsFolder; try { try { initJAXB(); File sourceFolder = new File(sourceRoot); if (!sourceFolder.exists()) { handler = setupLogHandler(sourceFolder.getName()); log.log(Level.SEVERE, "Source folder doesn't exist: " + sourceFolder.getAbsolutePath()); throw new IllegalStateException( "Source folder doesn't exist: " + sourceFolder.getAbsolutePath()); } sourceFiles = sourceFolder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return (pathname.getName().endsWith(".zip")); } }); if (sourceFiles == null || sourceFiles.length == 0) { handler = setupLogHandler(sourceFolder.getName()); log.log(Level.SEVERE, "Empty source folder: " + sourceFolder.getAbsolutePath()); throw new IllegalStateException("Empty source folder: " + sourceFolder.getAbsolutePath()); } preprocessFiles(sourceFolder, sourceFiles); handler = setupLogHandler(packageid); resultsFolder = checkDirectory(resultsRoot); log.info("Loaded source folder: " + sourceFolder); log.info("Results directory: " + resultsFolder); } catch (Exception e) { log.log(Level.SEVERE, "Error in transporter initialization.", e); throw new IllegalStateException("Error in transporter initialization.", e); } try { for (int i = 0; i < sourceFiles.length; i++) { if (i != filesIndex && i != mtdpspIndex) { uploadFile(sourceFiles[i], SipType.RECORD, true); } } if (mtdpspIndex > -1) { uploadFile(sourceFiles[mtdpspIndex], SipType.RECORD, true); } if (filesIndex >= 0) { uploadFile(sourceFiles[filesIndex], SipType.FILE, true); } } catch (Throwable th) { log.log(Level.SEVERE, "Error in file upload: ", th); throw new IllegalStateException("Error in file upload: ", th); } finally { results.setPspResultCode("progress"); try { marshaller.marshal(results, new File(resultsFolder, "TRANSF_" + packageid + ".xml")); } catch (JAXBException e) { log.log(Level.SEVERE, "Error writing results file: ", e); throw new IllegalStateException(e); } } long timeFinish = System.currentTimeMillis(); log.info("Elapsed time: " + ((timeFinish - timeStart) / 1000.0) + " seconds. " + sourceFiles.length + " SIP packages transported."); log.info("RESULT: OK"); } finally { if (handler != null) { removeLogHandler(handler); } } return countSip(); }
From source file:de.thorstenberger.examServer.webapp.action.PDFBulkExport.java
/** * @param tasklet/*from w ww. j a va2 s.co m*/ * @param userId * @return */ private FileFilter getPdfFileFilter(final Tasklet tasklet, final String userId) { return new FileFilter() { public boolean accept(final File pathname) { return pathname.getName().contains(userId + "-" + tasklet.getTaskId() + "-"); } }; }