Example usage for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY

List of usage examples for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY

Introduction

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

Prototype

IOFileFilter DIRECTORY

To view the source code for org.apache.commons.io.filefilter DirectoryFileFilter DIRECTORY.

Click Source Link

Document

Singleton instance of directory filter.

Usage

From source file:org.ednovo.data.handlers.FileInputProcessor.java

@Override
public void handleRow(Object row) throws Exception {
    File folder = new File(fileInputData.get("file-path"));
    Collection<File> files = FileUtils.listFiles(folder,
            new WildcardFileFilter(fileInputData.get("path-pattern")), DirectoryFileFilter.DIRECTORY);
    StopWatch sw = new StopWatch();
    for (final File file : files) {
        LOG.info("processing file {}", file.getAbsolutePath());
        sw.start();/*from  w w w . ja  va2 s .  c o m*/
        long lines = 0;
        try {
            LineIterator it = FileUtils.lineIterator(file, "UTF-8");
            try {
                while (it.hasNext()) {
                    final String line = it.nextLine();

                    // Send the row to the next process handler.
                    getNextRowHandler().processRow(line);

                    lines++;
                    if (lines % 1000 == 0) {
                        LOG.info("file-lines: {} ", lines);
                    }
                }
            } finally {
                LineIterator.closeQuietly(it);
            }
        } catch (IOException e) {
            LOG.error("Error processing file {} ", file.getAbsolutePath(), e);
        }
        sw.stop("file:" + file.getAbsolutePath() + ": lines= " + lines + " ");
        LOG.info(sw.toString(Integer.parseInt(lines + "")));
    }
}

From source file:org.everit.i18n.propsxlsconverter.internal.I18nConverterImpl.java

private Collection<File> getFilesWithSorted(final String fileRegularExpression,
        final File workingDirectoryFile) {
    Collection<File> files = FileUtils.listFiles(workingDirectoryFile,
            new RegexFileFilter(fileRegularExpression), DirectoryFileFilter.DIRECTORY);

    if (files instanceof List<?>) {
        // guarantees that the first file is the default language file.
        Collections.sort((List<File>) files, (file1, file2) -> file1.getName().compareTo(file2.getName()));
    }//  w w  w.ja va2 s  .  c  o m
    return files;
}

From source file:org.geoserver.importer.web.MosaicPanel.java

@Override
protected void initFileChooser(GeoServerFileChooser fileChooser) {
    fileChooser.setFilter(new Model((Serializable) DirectoryFileFilter.DIRECTORY));
}

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 va  2  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.guvnor.m2repo.backend.server.GuvnorM2Repository.java

protected Collection<File> getFiles(final List<String> wildcards) {
    return FileUtils.listFiles(new File(M2_REPO_DIR), new WildcardFileFilter(wildcards, IOCase.INSENSITIVE),
            DirectoryFileFilter.DIRECTORY);
}

From source file:org.guvnor.m2repo.backend.server.repositories.FileSystemArtifactRepository.java

@Override
public Collection<File> listFiles(final List<String> wildcards) {
    return FileUtils.listFiles(new File(this.getRepositoryDirectory()),
            new WildcardFileFilter(wildcards, IOCase.INSENSITIVE), DirectoryFileFilter.DIRECTORY);
}

From source file:org.jainy.tools.ValidatePropertyConfig.java

private static void searchDir(File root, List list) {

    File[] dirList = root.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory() && !file.getName().equals("target");
        }/* w  w  w. j  a  v  a  2 s . co m*/
    });

    //See if we have src as one of the child folders and if yes, note down the index
    int srcDirIdx = -1;
    for (int i = 0; i < dirList.length; i++) {
        if (dirList[i].getName().equals("src"))
            srcDirIdx = i;
    }

    // If src is present, no need to recurse for other folders, directly look at the file
    if (srcDirIdx > -1) {
        File finalDir = new File(dirList[srcDirIdx].getAbsolutePath() + "\\" + MAIN_RESOURCES_INSTALL_UPDATES);
        if (finalDir.exists()) {

            Collection<File> propertyConfigFiles = FileUtils.listFiles(finalDir, new IOFileFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return false;
                }

                @Override
                public boolean accept(File file) {
                    if (file.getName().endsWith(PROPERTY_CONFIG_XML)
                            && !file.getAbsolutePath().contains(APSF_PLUGIN_ARCHETYPE)) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }, DirectoryFileFilter.DIRECTORY);
            list.addAll(propertyConfigFiles);
        }
    } else {
        //src is not present as sibling so go through everything. if src would have been parent, we would not have landed in this situation
        for (File dir : dirList) {
            searchDir(dir, list);
        }
    }

}

From source file:org.jts.docGenerator.util.DirectoryScanner.java

public static void main(String[] args) {
    File sourceDir = new File("C:/Users/idurkan/Documents/NetBeansProjects/JAUSToolset/output/framed_html");

    // filter all xml files
    FileFilter serviceSetFilter = new FileFilter() {

        /**/*from w  w  w . j  a v  a 2  s.com*/
         * Accepts Files Ending in .xml extension.
         * @param name File Name.
         * @return Accept or Reject Flag
         */
        public boolean accept(File file) {
            if (file.getName().endsWith(".xml") && !file.isDirectory()) {
                return true;
            } else {
                return false;
            }
        }
    };

    // file suffix scanners.
    DirectoryScanner scanner = new DirectoryScanner(sourceDir, serviceSetFilter);

    List<File> result1list = scanner.getFileList();

    IOFileFilter xmlFilter = FileFilterUtils.suffixFileFilter(".xml");
    Collection<File> result2 = FileUtils.listFiles(sourceDir, xmlFilter, TrueFileFilter.INSTANCE);
    ArrayList<File> result2list = new ArrayList<File>(result2);

    // directory scanners
    DirectoryScanner dirscanner = new DirectoryScanner(sourceDir, null);
    List<File> result3list = scanner.getDirList();

    Collection<File> result4 = FileUtils.listFiles(sourceDir, DirectoryFileFilter.DIRECTORY,
            TrueFileFilter.INSTANCE);
    ArrayList<File> result4list = new ArrayList<File>(result4);

    Collections.sort(result1list);
    Collections.sort(result2list);
    Collections.sort(result3list);
    Collections.sort(result4list);

    compareAndPrint(result1list, result2list);
    compareAndPrint(result3list, result4list);
}

From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java

private void backupAdditionalFiles() throws IOException {
    LOGGER.info("Backing up additional files...");

    if (backupAdditionalFilesRegexPattern != null) {
        final IOFileFilter addFilesFilter = new RegexFileFilter(backupAdditionalFilesRegexPattern);

        final IOFileFilter filter = FileFilterUtils.and(addFilesFilter,
                FileFilterUtils.or(DirectoryFileFilter.DIRECTORY,
                        FileFilterUtils.and(getFileAgeDiffFilter(), getExcludedFilesFilter())));

        FileUtils.copyDirectory(hudsonHome, backupDirectory, filter);
    } else {//from   w  ww. ja  v a  2 s  .  c om
        LOGGER.info("No Additional File regex was provided: selecting no Additional Files to back up.");
    }

    LOGGER.info("DONE backing up Additional Files.");
}

From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java

private void backupBuildFiles(final File source, final File destination) throws IOException {
    if (source.isDirectory()) {
        final IOFileFilter changelogFilter = FileFilterUtils.and(DirectoryFileFilter.DIRECTORY,
                FileFilterUtils.nameFileFilter(CHANGELOG_HISTORY_PLUGIN_DIR_NAME));
        final IOFileFilter fileFilter = FileFilterUtils.and(FileFileFilter.FILE, getFileAgeDiffFilter());

        IOFileFilter filter = FileFilterUtils.and(FileFilterUtils.or(changelogFilter, fileFilter),
                getExcludedFilesFilter(),
                FileFilterUtils.notFileFilter(FileFilterUtils.suffixFileFilter(ZIP_FILE_EXTENSION)));
        FileUtils.copyDirectory(source, destination, filter);
    } else if (FileUtils.isSymlink(source)) {
        // TODO: check if copy symlink needed here
    } else if (source.isFile()) {
        FileUtils.copyFile(source, destination);
    }// w  w w.  j  a  va 2s  .c  o  m
}