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

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

Introduction

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

Prototype

IOFileFilter INSTANCE

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

Click Source Link

Document

Singleton instance of false filter.

Usage

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

/**
 * run the directory walker//from w  w w .  j ava 2s . com
 */
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.jahia.tools.files.FileWatcher.java

/**
 * Verify if the Folder to watch exists.
 * Create the Archive Folder if not exist.
 *
 * @exception IOException//from  ww w .  j  a  va 2 s  . c o  m
 */
protected void initialize() throws IOException {

    logger.debug("Initializing file watcher");

    /*
       For Test Purpose
       ToChange : restore the last check time from ext. file !
    */
    lastCheckTime = System.currentTimeMillis();
    logger.debug("Watching directory=" + getFolderPath());
    File tmpFile = new File(getFolderPath());
    if (tmpFile.isDirectory() && !tmpFile.canWrite()) {
        logger.debug("No write access to directory " + getFolderPath() + " tmpFile=" + tmpFile.toString());
    } else if (!tmpFile.exists()) {
        logger.debug("Directory " + tmpFile.toString() + " does not exist, creating...");
        tmpFile.mkdirs();
        logger.debug("Directory " + tmpFile.toString() + " created successfully.");
    }
    m_Folder = tmpFile;
    if (removedFiles) {
        IOFileFilter filter = getIgnoreFilter();
        if (filter == null) {
            filter = TrueFileFilter.INSTANCE;
        }
        if (m_FileOnly) {
            previousFiles = FileUtils.listFiles(m_Folder, filter,
                    recursive ? filter : FalseFileFilter.INSTANCE);
        } else {
            previousFiles = FileUtils.listFilesAndDirs(m_Folder, filter,
                    recursive ? filter : FalseFileFilter.INSTANCE);
        }
    }
}

From source file:org.jahia.tools.files.FileWatcherJob.java

/**
 * Checks new files and builds the List of files to pass to Observers
 * //  w w  w  .  j  av a2 s .  co m
 * @param folder
 *            the root folder where to watch files
 * @param fileOnly
 *            if <code>true</code> we consider only files; otherwise we also consider folders
 * @param recursive
 *            should we recurse into sub-folders
 * @param checkDate
 *            do we need to check the last modification date or in case of <code>false</code> value just return all found files
 * @param lastCheckTime
 *            the last check time
 * @return a list of files and folders matching the provided criteria
 */
protected List<File> checkFiles(File folder, boolean fileOnly, boolean recursive, boolean checkDate,
        long lastCheckTime, IOFileFilter ignoreFilter) {
    if (!folder.isDirectory()) {
        return Collections.emptyList();
    }
    List<File> files = null;
    if (fileOnly || !checkDate) {
        IOFileFilter fileFilter;
        IOFileFilter dirFilter;
        if (ignoreFilter != null) {
            fileFilter = checkDate ? new AndFileFilter(new AgeFileFilter(lastCheckTime, false), ignoreFilter)
                    : ignoreFilter;
            dirFilter = recursive ? ignoreFilter : FalseFileFilter.INSTANCE;
        } else {
            fileFilter = checkDate ? new AgeFileFilter(lastCheckTime, false) : TrueFileFilter.INSTANCE;
            dirFilter = recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE;
        }
        Collection<File> foundFiles = fileOnly ? FileUtils.listFiles(folder, fileFilter, dirFilter)
                : FileUtils.listFilesAndDirs(folder, fileFilter, dirFilter);
        files = (foundFiles instanceof List<?>) ? (List<File>) foundFiles : new LinkedList<File>(foundFiles);
    } else {
        if (recursive) {
            try {
                files = new Walker(lastCheckTime).execute(folder);
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        } else {
            Collection<File> foundFiles = FileUtils.listFilesAndDirs(folder,
                    ignoreFilter != null
                            ? new AndFileFilter(new AgeFileFilter(lastCheckTime, false), ignoreFilter)
                            : null,
                    FalseFileFilter.INSTANCE);
            files = (foundFiles instanceof List<?>) ? (List<File>) foundFiles
                    : new LinkedList<File>(foundFiles);
        }
    }

    return files;
}

From source file:org.jahia.tools.files.FileWatcherJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
    FileWatcher fileWatcher = (FileWatcher) jobDataMap.get("fileWatcher");
    if (fileWatcher != null) {
        File folder = fileWatcher.getFolder();
        boolean fileOnly = fileWatcher.getFileOnly();
        boolean recursive = fileWatcher.isRecursive();
        IOFileFilter ignoreFilter = fileWatcher.getIgnoreFilter();
        List<File> changedFiles = checkFiles(folder, fileOnly, recursive, fileWatcher.getCheckDate(),
                fileWatcher.getLastCheckTime(), ignoreFilter);
        fileWatcher.setLastCheckTime(System.currentTimeMillis());
        if (fileWatcher.getRemovedFiles()) {
            Collection<File> currentFiles;
            IOFileFilter filter = ignoreFilter != null ? ignoreFilter : TrueFileFilter.INSTANCE;
            if (fileOnly) {
                currentFiles = FileUtils.listFiles(folder, filter,
                        recursive ? filter : FalseFileFilter.INSTANCE);
            } else {
                currentFiles = FileUtils.listFilesAndDirs(folder, filter,
                        recursive ? filter : FalseFileFilter.INSTANCE);
            }// w ww. ja v a 2  s.  co m
            Set<File> deletedFiles = new TreeSet<File>(new PathFileComparator());
            deletedFiles.addAll(fileWatcher.getPreviousFiles());
            deletedFiles.removeAll(currentFiles);
            changedFiles.addAll(deletedFiles);
            fileWatcher.setPreviousFiles(currentFiles);
        }

        // Notify Observers if number of files > 0
        if (changedFiles.size() > 0) {
            fileWatcher.externalSetChanged(); // Alert the Observable Object That there are change in the folder
            fileWatcher.notifyObservers(changedFiles);
        }
    }
}

From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java

private static void removeResourceFolder(final IResource resource, final boolean removeOriginalRawRes)
        throws CoreException {
    final File[] children = resource.getLocation().toFile().listFiles();
    if (children != null) {
        if (children.length == 0 || removeOriginalRawRes) {
            try {
                resource.delete(true, new NullProgressMonitor());
            } catch (final Exception e) {
                // FIXME: why?! the problem is elsewhere!!
                e.printStackTrace();//from   w w  w  .j  a v  a2 s . com

                // FIXME:

                final IOFileFilter lNoDirFilter = FalseFileFilter.INSTANCE;

                final WildcardFileFilter lFilter = new WildcardFileFilter(new String[] { "*" }); //$NON-NLS-1$
                final Collection<File> files = FileUtils.listFiles(resource.getLocation().toFile(), lFilter,
                        lNoDirFilter);
                for (final File lFile : files)
                    deleteFileOrDirectory(lFile);

                final IOFileFilter lDirFilter = TrueFileFilter.INSTANCE;
                final Collection<File> dirs = FileUtils.listFiles(resource.getLocation().toFile(), lFilter,
                        lDirFilter);
                for (final File lDir : dirs)
                    deleteFileOrDirectory(lDir);
            }
        } else {
            for (int i = 0; i < children.length; i++) {
                if (!children[i].getName().toLowerCase().contains(ORIGINAL_2D_FILE_NAME)) {
                    try {
                        final IResource resourceChild = ResourceUtilities
                                .findFileFromURL(children[i].toURI().toURL());
                        if (resourceChild instanceof IFolder) {
                            removeResourceFolder(resourceChild, removeOriginalRawRes);
                        } else {
                            if (resourceChild != null)
                                resourceChild.delete(true, new NullProgressMonitor());
                            children[i].delete();
                        }
                    } catch (final MalformedURLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } else {
        resource.delete(true, new NullProgressMonitor());
    }
}

From source file:org.silverpeas.core.process.io.file.TestFileHandler.java

@Test
public void testListFilesFromSessionAndRealPathWithFilters() throws Exception {
    buildCommonPathStructure();//from w ww  .java 2  s  . co  m
    Collection<File> files = fileHandler.listFiles(BASE_PATH_TEST, realRootPath, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    assertThat(files.size(), is(13));
    assertThat(listFiles(sessionHandledPath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size(), is(7));
    assertThat(listFiles(realRootPath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size(), is(14));

    // Non recursive
    files = fileHandler.listFiles(BASE_PATH_TEST, realRootPath, TrueFileFilter.INSTANCE,
            FalseFileFilter.INSTANCE);
    assertThat(files.size(), is(3));
    assertThat(listFiles(sessionHandledPath, TrueFileFilter.INSTANCE, FalseFileFilter.INSTANCE).size(), is(2));
    assertThat(listFiles(realRootPath, TrueFileFilter.INSTANCE, FalseFileFilter.INSTANCE).size(), is(2));

    // Extension
    files = fileHandler.listFiles(BASE_PATH_TEST, realRootPath,
            new SuffixFileFilter(new String[] { ".test", ".xml", ".txt" }), TrueFileFilter.INSTANCE);
    assertThat(files.size(), is(3));
    assertThat(listFiles(sessionHandledPath, new SuffixFileFilter(new String[] { "test", ".xml", "txt" }),
            TrueFileFilter.INSTANCE).size(), is(1));
    assertThat(listFiles(realRootPath, new SuffixFileFilter(new String[] { "test", "xml", "txt" }),
            TrueFileFilter.INSTANCE).size(), is(3));
}

From source file:org.silverpeas.core.process.io.file.TestHandledFile.java

@Test
public void testListFilesWithFilters() throws Exception {
    buildCommonPathStructure();/*from   w ww . j  a va  2  s  . co  m*/
    final HandledFile test = getHandledFile(realRootPath);
    Collection<HandledFile> files = test.listFiles(TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    assertThat(files.size(), is(13));
    assertThat(listFiles(sessionHandledPath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size(), is(7));
    assertThat(listFiles(realRootPath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size(), is(14));

    // Non recursive
    files = test.listFiles(TrueFileFilter.INSTANCE, FalseFileFilter.INSTANCE);
    assertThat(files.size(), is(3));
    assertThat(listFiles(sessionHandledPath, TrueFileFilter.INSTANCE, FalseFileFilter.INSTANCE).size(), is(2));
    assertThat(listFiles(realRootPath, TrueFileFilter.INSTANCE, FalseFileFilter.INSTANCE).size(), is(2));

    // Extension
    files = test.listFiles(new SuffixFileFilter(new String[] { ".test", ".xml", ".txt" }),
            TrueFileFilter.INSTANCE);
    assertThat(files.size(), is(3));
    assertThat(listFiles(sessionHandledPath, new SuffixFileFilter(new String[] { "test", ".xml", "txt" }),
            TrueFileFilter.INSTANCE).size(), is(1));
    assertThat(listFiles(realRootPath, new SuffixFileFilter(new String[] { "test", "xml", "txt" }),
            TrueFileFilter.INSTANCE).size(), is(3));
}