Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:org.geoserver.importer.VFSWorker.java

@SuppressWarnings("unchecked")
public Collection<File> listFilesInFolder(final File targetFolder, final FilenameFilter fileNameFilter) {
    IOFileFilter fileFilter = new IOFileFilter() {

        public boolean accept(File dir, String name) {
            return fileNameFilter.accept(dir, name);
        }/*from  ww w . jav a 2 s. c o m*/

        public boolean accept(File file) {
            return fileNameFilter.accept(file.getParentFile(), file.getName());
        }
    };
    IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
    Collection<File> listFiles = FileUtils.listFiles(targetFolder, fileFilter, dirFilter);
    return listFiles;
}

From source file:org.geoserver.restupload.ResumableUploadResourceManager.java

public Boolean hasAnyResource() {
    Collection<File> files = FileUtils.listFiles(tmpUploadFolder.dir(), new WildcardFileFilter("*.*"),
            TrueFileFilter.INSTANCE);
    return (files.size() != 0);
}

From source file:org.geoserver.restupload.ResumableUploadResourceManager.java

/**
 * Deletes all the file from temporary folder which aren't modified from more than expirationThreshold
 *//*ww w  .ja  va 2  s.  c o m*/
public void cleanExpiredResources(long expirationThreshold) {
    Collection<File> files = FileUtils.listFiles(tmpUploadFolder.dir(), new WildcardFileFilter("*.*"),
            TrueFileFilter.INSTANCE);
    for (Iterator<File> i = files.iterator(); i.hasNext();) {
        File file = i.next();
        if (file.lastModified() < expirationThreshold) {
            file.delete();
        }
    }
}

From source file:org.geoserver.restupload.ResumableUploadResourceManager.java

private ResumableUploadResource getResource(String uploadId) throws IllegalStateException {
    Collection<File> files = FileUtils.listFiles(tmpUploadFolder.dir(),
            new WildcardFileFilter("*_" + uploadId + ".*"), TrueFileFilter.INSTANCE);
    if (files.size() == 1) {
        return new ResumableUploadResource(uploadId, files.iterator().next());
    }//  w  w  w  .  jav a 2 s . com
    if (files.size() > 1) {
        throw new IllegalStateException("Found multiple files with same uploadId");
    }
    return null;
}

From source file:org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.java

public void run() {

    try {/*from w  w  w  .  ja va 2  s .co  m*/

        //
        // creating the file filters for scanning for files to check and index
        //
        final IOFileFilter finalFilter = createGranuleFilterRules();

        //TODO we might want to remove this in the future for performance
        numFiles = 0;
        for (String indexingDirectory : runConfiguration.getIndexingDirectories()) {
            final File directoryToScan = new File(indexingDirectory);
            final Collection files = FileUtils.listFiles(directoryToScan, finalFilter,
                    runConfiguration.isRecursive() ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);
            numFiles += files.size();
        }
        //
        // walk over the files that have filtered out
        //
        if (numFiles > 0) {
            final List<String> indexingDirectories = runConfiguration.getIndexingDirectories();
            @SuppressWarnings("unused")
            final CatalogBuilderDirectoryWalker walker = new CatalogBuilderDirectoryWalker(indexingDirectories,
                    finalFilter);

        }

    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }

}

From source file:org.geotools.gce.imagemosaic.ImageMosaicDirectoryWalker.java

/**
 * run the directory walker//from w  ww .j  a v a2  s . c  o m
 */
public void run() {

    try {

        //
        // creating the file filters for scanning for files to check and index
        //
        final IOFileFilter finalFilter = createDefaultGranuleExclusionFilter();

        // TODO we might want to remove this in the future for performance
        int numFiles = 0;
        String harvestDirectory = configHandler.getRunConfiguration().getParameter(Prop.HARVEST_DIRECTORY);
        String indexDirs = configHandler.getRunConfiguration().getParameter(Prop.INDEXING_DIRECTORIES);
        if (harvestDirectory != null) {
            indexDirs = harvestDirectory;
        }
        String[] indexDirectories = indexDirs.split("\\s*,\\s*");
        for (String indexingDirectory : indexDirectories) {
            indexingDirectory = Utils.checkDirectory(indexingDirectory, false);
            final File directoryToScan = new File(indexingDirectory);
            final Collection files = FileUtils.listFiles(directoryToScan, finalFilter,
                    Boolean.parseBoolean(configHandler.getRunConfiguration().getParameter(Prop.RECURSIVE))
                            ? TrueFileFilter.INSTANCE
                            : FalseFileFilter.INSTANCE);
            numFiles += files.size();
        }
        //
        // walk over the files that have filtered out
        //
        if (numFiles > 0) {
            setNumFiles(numFiles);
            final List<String> indexingDirectories = new ArrayList<String>(Arrays.asList(indexDirectories));
            new MosaicDirectoryWalker(indexingDirectories, finalFilter, this);

        } else {
            LOGGER.log(Level.INFO, "No files to process!");
        }

    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }

}

From source file:org.grycap.gpf4med.DocumentManager.java

/**
 * Lazy load -> Adapted to consider TRENCADIS storage
 * @return the list of available document Documents.
 *///from  w ww .ja v  a2  s. c o  m
public ImmutableMap<String, Document> documents(int idCenter, String idOntology) {
    if (dont_use == null) {
        synchronized (DocumentManager.class) {
            if (dont_use == null) {
                // Documents can be loaded from class-path, local files, through HTTP or through TRENCADIS plug-in 
                File documentsCacheDir = null;
                List<String> medicalCenters = null;
                try {
                    // prepare local cache directory
                    documentsCacheDir = new File(ConfigurationManager.INSTANCE.getLocalCacheDir(),
                            "reports" + File.separator + ConfigurationManager.INSTANCE.getTemplatesVersion());
                    if (urls == null && ConfigurationManager.INSTANCE.getTrencadisConfigFile() == null) {
                        LOGGER.debug("Source of report not found");
                    }
                    if (ConfigurationManager.INSTANCE.getTrencadisConfigFile() != null
                            && ConfigurationManager.INSTANCE.getTrencadisPassword() != null) {
                        urls = null;
                    }
                    FileUtils.deleteQuietly(documentsCacheDir);
                    FileUtils.forceMkdir(documentsCacheDir);
                    medicalCenters = new ArrayList<String>();
                    if (urls == null) {
                        try {
                            TRENCADIS_SESSION trencadisSession = new TRENCADIS_SESSION(
                                    ConfigurationManager.INSTANCE.getTrencadisConfigFile(),
                                    ConfigurationManager.INSTANCE.getTrencadisPassword());

                            if (idCenter == -1 && idOntology == null) {
                                TRENCADISUtils.getReportsID(trencadisSession);
                            } else if (idCenter != -1 && idOntology == null) {
                                TRENCADISUtils.getReportsID(trencadisSession, idCenter);
                            } else if (idCenter == -1 && idOntology != null) {
                                TRENCADISUtils.getReportsID(trencadisSession, idOntology);
                            } else if (idCenter != -1 && idOntology != null) {
                                TRENCADISUtils.getReportsID(trencadisSession, idCenter, idOntology);
                            }

                            //final ImportReportsGroupTask groupTask = new ImportReportsGroupTask();
                            Vector<TRENCADIS_RETRIEVE_IDS_FROM_DICOM_STORAGE> dicomStorage = TRENCADISUtils
                                    .getDicomStorage();
                            if (dicomStorage != null) {
                                for (TRENCADIS_RETRIEVE_IDS_FROM_DICOM_STORAGE dicomStorageIDS : dicomStorage) {
                                    final List<String> ids = new ArrayList<String>();
                                    final String centerName = dicomStorageIDS.getCenterName().replaceAll(" ",
                                            "_");
                                    medicalCenters.add(centerName);
                                    final BackEnd backend = new BackEnd(
                                            dicomStorageIDS.getBackend().toString());
                                    for (DICOM_SR_ID id : dicomStorageIDS.getDICOM_DSR_IDS()) {
                                        ids.add(id.getValue());
                                        TRENCADISUtils.downloadReport(trencadisSession, backend, centerName,
                                                id.getValue(), documentsCacheDir.getAbsolutePath());
                                    }
                                    //groupTask.addTask(backend, centerName, trencadisSession.getX509VOMSCredential(), ids, PARTITION, documentsCacheDir);
                                }
                                //groupTask.sumbitAll();
                                //TASK_STORAGE.add(groupTask);
                            }

                        } catch (Exception e3) {
                            LOGGER.warn("Failed to get reports from TRENCADIS", e3);
                        }
                    }
                } catch (Exception e) {
                    LOGGER.warn("Failed to prepare reports for access", e);
                }
                checkArgument(documentsCacheDir != null, "Uninitialized reports local cache directory");

                final ImmutableMap.Builder<String, Document> builder = new ImmutableMap.Builder<String, Document>();

                for (final File file : FileUtils.listFiles(documentsCacheDir, TrueFileFilter.INSTANCE,
                        DirectoryFileFilter.DIRECTORY)) {
                    String filename = null;
                    try {
                        filename = file.getCanonicalPath();
                        final Document report = DocumentLoader.create(file).load();
                        checkState(
                                report != null && report.getCONTAINER() != null
                                        && report.getCONTAINER().getCONCEPTNAME().getCODEVALUE() != null,
                                "No report found");
                        final String id = report.getIDTRENCADISReport();
                        checkState(StringUtils.isNotBlank(id), "Uninitialized or invalid TRENCADIS identifier");
                        builder.put(id, report);
                        LOGGER.trace("New report " + report.getIDReport() + ", ontology "
                                + report.getIDOntology() + ", loaded from: " + filename);
                    } catch (Exception e) {
                        LOGGER.error("Failed to load report: " + filename, e);
                    }
                }
                dont_use = builder.build();
            }
        }
    }
    return dont_use;
}

From source file:org.grycap.gpf4med.TemplateManager.java

/**
 * Lazy load -> Adapted to consider TRENCADIS storage
 * @return the list of available templates.
 *///from  www .  j  av a 2 s  . c  o m
private ImmutableMap<String, Template> templates(String idOntology) {
    if (dont_use == null) {
        synchronized (TemplateManager.class) {
            if (dont_use == null) {
                // templates can be loaded from class-path, local files, through HTTP or using TRENCADIS plug-in
                File templatesCacheDir = null;
                try {
                    // prepare local cache directory
                    templatesCacheDir = new File(ConfigurationManager.INSTANCE.getLocalCacheDir(),
                            "templates" + File.separator + ConfigurationManager.INSTANCE.getTemplatesVersion());
                    // read index
                    if (urls == null && ConfigurationManager.INSTANCE.getTrencadisConfigFile() == null) {
                        LOGGER.trace("TRENCADIS configuration file is null");
                        final URL index = ConfigurationManager.INSTANCE.getTemplatesIndex();
                        urls = Arrays.asList(URLUtils.readIndex(index));
                    }
                    if (ConfigurationManager.INSTANCE.getTrencadisConfigFile() != null
                            && ConfigurationManager.INSTANCE.getTrencadisPassword() != null) {
                        urls = null;
                    }
                    FileUtils.deleteQuietly(templatesCacheDir);
                    FileUtils.forceMkdir(templatesCacheDir);
                    // get a local copy of the connectors
                    if (urls != null) {
                        for (final URL url : urls) {
                            try {
                                final File destination = new File(templatesCacheDir, NamingUtils
                                        .genSafeFilename(new String[] { url.toString() }, null, ".xml"));
                                URLUtils.download(url, destination);
                            } catch (Exception e2) {
                                LOGGER.warn("Failed to get template from URL: " + url.toString(), e2);
                            }
                        }
                    } else {
                        try {
                            TRENCADIS_SESSION trencadisSession = new TRENCADIS_SESSION(
                                    ConfigurationManager.INSTANCE.getTrencadisConfigFile(),
                                    ConfigurationManager.INSTANCE.getTrencadisPassword());
                            if (idOntology != null)
                                TRENCADISUtils.downloadOntology(trencadisSession, idOntology,
                                        templatesCacheDir.getAbsolutePath());
                            else
                                TRENCADISUtils.downloadAllOntologies(trencadisSession,
                                        templatesCacheDir.getAbsolutePath());
                        } catch (Exception e3) {
                            LOGGER.warn("Failed to get templates from TRENCADIS", e3);
                        }
                    }
                } catch (Exception e) {
                    LOGGER.error("Failed to prepare templates for access", e);
                }
                // load available templates
                checkArgument(templatesCacheDir != null, "Uninitialized templates local cache directory");
                final ImmutableMap.Builder<String, Template> builder = new ImmutableMap.Builder<String, Template>();
                for (final File file : FileUtils.listFiles(templatesCacheDir, TrueFileFilter.INSTANCE, null)) {
                    String filename = null;
                    try {
                        filename = file.getCanonicalPath();
                        final Template template = TemplateLoader.create(file).load();
                        checkState(
                                template != null && template.getCONTAINER() != null
                                        && template.getCONTAINER().getCONCEPTNAME() != null,
                                "No template found");
                        final String id = Id.getId(template.getCONTAINER().getCONCEPTNAME());
                        checkState(StringUtils.isNotBlank(id), "Uninitialized or invalid concept name");
                        builder.put(id, template);
                        LOGGER.trace("New template " + template.getDescription() + ", ontology "
                                + template.getIDOntology() + ", loaded from: " + filename);
                    } catch (Exception e) {
                        LOGGER.error("Failed to load template: " + filename, e);
                    }
                }
                dont_use = builder.build();
            }
        }
    }
    return dont_use;
}

From source file:org.h819.commons.file.MyFileUtils.java

/**
 * Finds files within a given directory. All files found are filtered by an name filter.
 * (? FileUtils.listFiles ?)//w  ww.  j  av  a 2 s. c  om
 *
 * @param directory       the directory to search in
 * @param fileNames       file names to apply when finding files.
 * @param recursive       if true all subdirectories are searched as well
 * @param caseSensitivity how to handle case sensitivity, null means case-sensitive (IOCase.SENSITIVE ,  IOCase.INSENSITIVE)
 * @return
 */
public static Collection<File> listFiles(File directory, String[] fileNames, boolean recursive,
        IOCase caseSensitivity) {

    if (recursive)
        return FileUtils.listFiles(directory, new NameFileFilter(fileNames, caseSensitivity),
                TrueFileFilter.INSTANCE);
    else
        return FileUtils.listFiles(directory, new NameFileFilter(fileNames, caseSensitivity), null);

}

From source file:org.identityconnectors.test.common.TestHelpers.java

/**
 * Method for convenient testing of local connectors.
 *//*from  ww w  .  j  a va  2 s.c  o m*/
public static APIConfiguration createTestConfiguration(Class<? extends Connector> clazz,
        final PropertyBag configData, String prefix) {
    URL url = clazz.getClassLoader().getResource("");
    Set<String> bundleContents = new HashSet<String>();

    try {
        URI relative = url.toURI();
        for (File file : FileUtils.listFiles(new File(url.toURI()), TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE)) {
            bundleContents.add(relative.relativize(file.toURI()).getPath());
        }
        return getSpi().createTestConfiguration(clazz, bundleContents, configData, prefix);
    } catch (Exception e) {
        throw ConnectorException.wrap(e);
    }
}