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.mda.bcb.tcgagsdata.TcgaGSData.java

protected static File[] findFiles(String theCombinedDir, String theDiseaseSampleFile) {
    // theDiseaseSampleFile - disease in first column, rest of row is SAMPLE barcode
    Collection<File> files = FileUtils.listFiles(new File(theCombinedDir),
            new WildcardFileFilter(theDiseaseSampleFile), TrueFileFilter.INSTANCE);
    return files.toArray(new File[0]);

}

From source file:org.mobicents.servlet.restcomm.rvd.storage.FsProjectStorage.java

/**
 * Returns a WavItem list for all .wav files insude the /audio RVD directory. No project is involved here.
 * @param rvdContext//from w  w  w .  j  a v a2  s.  co  m
 * @return
 */
public static List<WavItem> listBundledWavs(RvdContext rvdContext) {
    List<WavItem> items = new ArrayList<WavItem>();

    String contextRealPath = rvdContext.getServletContext().getRealPath("/");
    String audioRealPath = contextRealPath + "audio";
    String contextPath = rvdContext.getServletContext().getContextPath();

    File dir = new File(audioRealPath);
    Collection<File> audioFiles = FileUtils.listFiles(dir, new SuffixFileFilter(".wav"),
            TrueFileFilter.INSTANCE);
    for (File anyFile : audioFiles) {
        WavItem item = new WavItem();
        String itemRelativePath = anyFile.getPath().substring(contextRealPath.length());
        String presentationName = anyFile.getPath().substring(contextRealPath.length() + "audio".length());
        item.setUrl(contextPath + "/" + itemRelativePath);
        item.setFilename(presentationName);
        items.add(item);
    }
    return items;
}

From source file:org.muehleisen.hannes.taxiapp.TaxiRoute.java

@Override
public void run() {
    log.info(this.getClass().getSimpleName() + " starting...");

    BlockingQueue<Runnable> taskQueue = new LinkedBlockingDeque<Runnable>(100);
    ExecutorService ex = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
            Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE, TimeUnit.DAYS, taskQueue,
            new ThreadPoolExecutor.DiscardPolicy());
    // create rainbow table for driver lookup
    log.info("Creating driver license rainbow table.");
    RouteLogEntry.initLrt();//from  ww w  .ja v a  2s  .  c  o m

    // bring up routing service
    log.info("Bringing up OTP Graph Service from '" + graph + "'.");
    GraphServiceImpl graphService = new GraphServiceImpl();
    graphService.setPath(graph);
    graphService.startup();
    ps = new RetryingPathServiceImpl(graphService, new EarliestArrivalSPTService());

    // read taxi files
    log.info("Reading taxi files from '" + taxilog + "'.");
    Collection<File> files = FileUtils.listFiles(new File(taxilog), new SuffixFileFilter(".csv.zip"),
            TrueFileFilter.INSTANCE);
    for (File f : files) {
        log.info("Reading '" + f + "'.");
        try {
            ZipInputStream z = new ZipInputStream(new FileInputStream(f));
            z.getNextEntry(); // ZIP files have many entries. In this case,
                              // only one
            BufferedReader r = new BufferedReader(new InputStreamReader(z));
            r.readLine(); // header
            String line = null;
            while ((line = r.readLine()) != null) {
                RouteLogEntry rle = new RouteLogEntry(line);
                if (!rle.hasGeo()) {
                    continue;
                }
                while (taskQueue.remainingCapacity() < 1) {
                    Thread.sleep(100);
                }
                ex.submit(new RouteTask(rle));
            }
            r.close();
            z.close();
        } catch (Exception e) {
            log.error("Failed to read taxi file from '" + taxilog + "'.", e);
        }
    }
    ex.shutdown();
    try {
        ex.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS);
    } catch (InterruptedException e) {
        // ...
    }
    log.info(deliveries);
}

From source file:org.mule.transport.file.FileMoveToFunctionalTestCase.java

private void waitForFiles(final File folder, final int expectedAmount) throws InterruptedException {
    PollingProber prober = new PollingProber(PROBER_TIMEOUT, PROBER_POLLING_INTERVAL);

    prober.check(new Probe() {
        int lastAmount = 0;

        @Override//w ww .j  a  v a 2 s .com
        public boolean isSatisfied() {
            lastAmount = FileUtils.listFiles(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size();
            return lastAmount >= expectedAmount;
        }

        @Override
        public String describeFailure() {
            return String.valueOf(expectedAmount) + " files were expected, but only "
                    + String.valueOf(lastAmount) + " were present.";
        }
    });
}

From source file:org.mycontroller.standalone.api.BackupApi.java

/**
 * Call this method to get list of available backup files.
 * <p><b>Filter(s):</b>
 * <p>name - {@link List} of backup file names
 * <p><b>Page filter(s):</b>
 * <p>pageLimit - Set number of items per page
 * <p>page - Request page number/*  w w w .ja  v  a  2s.c  o  m*/
 * <p>order - Set order. <b>Option:</b> asc, desc
 * <p>orderBy - column name for order. <b>Option:</b> name
 * @param filters Supports various filter options.
 * @return QueryResponse Contains input filter and response
 * @throws IOException throws when problem with backup location
 */
public QueryResponse getBackupFiles(HashMap<String, Object> filters) throws IOException {
    Query query = Query.get(filters);

    String locationCanonicalPath = McUtils.getDirectoryLocation(FileUtils
            .getFile(AppProperties.getInstance().getBackupSettings().getBackupLocation()).getCanonicalPath());

    if (FileUtils.getFile(locationCanonicalPath).exists()) {
        List<BackupFile> files = new ArrayList<BackupFile>();

        //Filters
        //Extension filter
        SuffixFileFilter extensionFilter = new SuffixFileFilter(BACKUP_FILE_SUFFIX_FILTER, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        @SuppressWarnings("unchecked")
        List<String> fileNames = (List<String>) query.getFilters().get(KEY_NAME);
        if (fileNames == null) {
            fileNames = new ArrayList<String>();
        }
        fileNames.add(BRCommons.FILE_NAME_IDENTITY);

        if (fileNames != null && !fileNames.isEmpty()) {
            for (String fileName : fileNames) {
                if (nameFileFilter == null) {
                    nameFileFilter = FileFilterUtils
                            .and(new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                } else {
                    nameFileFilter = FileFilterUtils.and(nameFileFilter,
                            new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                }
            }
        }
        //Combine all filters
        IOFileFilter finalFileFilter = null;
        if (nameFileFilter != null) {
            finalFileFilter = FileFilterUtils.and(extensionFilter, nameFileFilter);
        } else {
            finalFileFilter = extensionFilter;
        }
        List<File> backupFiles = new ArrayList<File>(FileUtils
                .listFiles(FileUtils.getFile(locationCanonicalPath), finalFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) backupFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils
                .listFiles(FileUtils.getFile(locationCanonicalPath), extensionFilter, TrueFileFilter.INSTANCE)
                .size());
        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = backupFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (File backupFile : backupFiles) {
            String name = backupFile.getCanonicalPath().replace(locationCanonicalPath, "");
            files.add(BackupFile.builder().name(name).size(backupFile.length())
                    .timestamp(backupFile.lastModified()).canonicalPath(backupFile.getCanonicalPath()).build());
        }

        if (!files.isEmpty()) {
            //Do order reverse
            Collections.sort(files, Collections.reverseOrder());
            if (fileFrom < files.size()) {
                files = files.subList(Math.max(0, fileFrom), Math.min(fileTo, files.size()));
            }
        }
        return QueryResponse.builder().data(files).query(query).build();

    } else {
        throw new FileNotFoundException("File location not found: " + locationCanonicalPath);
    }
}

From source file:org.mycontroller.standalone.utils.McScriptFileUtils.java

@SuppressWarnings("unchecked")
public static QueryResponse getScriptFiles(Query query) throws IOException {
    //Check less info available and true, if true set less info return
    Boolean lessInfo = (Boolean) query.getFilters().get(ScriptsHandler.KEY_LESS_INFO);
    if (lessInfo) {
        query.setPageLimit(-1);// www. j  a  va 2s  . co m
    }

    String scriptsFileLocation = AppProperties.getInstance().getScriptsLocation();

    String filesLocation = null;
    if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == null) {
        filesLocation = scriptsFileLocation;
    } else if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == SCRIPT_TYPE.CONDITION) {
        filesLocation = AppProperties.getInstance().getScriptsConditionsLocation();
    } else if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == SCRIPT_TYPE.OPERATION) {
        filesLocation = AppProperties.getInstance().getScriptsOperationsLocation();
    }

    String locationCanonicalPath = McUtils
            .getDirectoryLocation(FileUtils.getFile(scriptsFileLocation).getCanonicalPath());

    if (FileUtils.getFile(filesLocation).exists()) {
        List<McScript> files = new ArrayList<McScript>();
        List<String> filesString = new ArrayList<String>();

        //Filters
        //Extension filter
        String[] scriptSuffixFilter = null;
        if (query.getFilters().get(ScriptsHandler.KEY_EXTENSION) != null) {
            if (Arrays.asList(MC_SCRIPT_SUFFIX_FILTER)
                    .contains(query.getFilters().get(ScriptsHandler.KEY_EXTENSION))) {
                scriptSuffixFilter = new String[] {
                        (String) query.getFilters().get(ScriptsHandler.KEY_EXTENSION) };
            }
        }

        if (scriptSuffixFilter == null) {
            scriptSuffixFilter = MC_SCRIPT_SUFFIX_FILTER;
        }
        SuffixFileFilter languageFilter = new SuffixFileFilter(scriptSuffixFilter, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        List<String> fileNames = (List<String>) query.getFilters().get(ScriptsHandler.KEY_NAME);
        if (fileNames != null && !fileNames.isEmpty()) {
            for (String fileName : fileNames) {
                if (nameFileFilter == null) {
                    nameFileFilter = FileFilterUtils
                            .and(new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                } else {
                    nameFileFilter = FileFilterUtils.and(nameFileFilter,
                            new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                }
            }
        }

        //Combine all filters
        IOFileFilter scriptsFileFilter = null;
        if (nameFileFilter != null) {
            scriptsFileFilter = FileFilterUtils.and(languageFilter, nameFileFilter);
        } else {
            scriptsFileFilter = languageFilter;
        }
        List<File> scriptFiles = new ArrayList<File>(FileUtils.listFiles(FileUtils.getFile(filesLocation),
                scriptsFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) scriptFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils.listFiles(FileUtils.getFile(scriptsFileLocation),
                new SuffixFileFilter(MC_SCRIPT_SUFFIX_FILTER, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)
                .size());

        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = scriptFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (; fileFrom < fileTo; fileFrom++) {
            if (scriptFiles.size() > fileFrom) {
                File scriptFile = scriptFiles.get(fileFrom);
                String name = scriptFile.getCanonicalPath().replace(locationCanonicalPath, "");
                if (lessInfo) {
                    filesString.add(name);
                } else {
                    files.add(McScript.builder().name(name)
                            .extension(FilenameUtils.getExtension(scriptFile.getCanonicalPath()))
                            .size(scriptFile.length()).lastModified(scriptFile.lastModified()).build());
                }
            } else {
                break;
            }
        }
        if (lessInfo) {
            return QueryResponse.builder().data(filesString).query(query).build();
        } else {
            return QueryResponse.builder().data(files).query(query).build();
        }

    } else {
        throw new FileNotFoundException("File location not found: " + locationCanonicalPath);
    }
}

From source file:org.mycontroller.standalone.utils.McServerFileUtils.java

public static List<String> getImageFilesList() throws IOException {
    String filesLocation = AppProperties.getInstance().getControllerSettings().getWidgetImageFilesLocation();
    String locationCanonicalPath = FileUtils.getFile(filesLocation).getCanonicalPath();
    if (!locationCanonicalPath.endsWith(File.separator)) {
        locationCanonicalPath += File.separator;
    }//from w  w  w.j  av a  2  s.c  o  m
    if (FileUtils.getFile(filesLocation).exists()) {
        List<String> files = new ArrayList<String>();
        IOFileFilter ioFileFilter = FileFilterUtils.and(
                new SuffixFileFilter(IMAGE_DISPLAY_SUFFIX_FILTER, IOCase.INSENSITIVE),
                new SizeFileFilter(IMAGE_DISPLAY_WIDGET_FILE_SIZE_LIMIT, false));
        Collection<File> imageFiles = FileUtils.listFiles(FileUtils.getFile(filesLocation), ioFileFilter,
                TrueFileFilter.INSTANCE);
        for (File imageFile : imageFiles) {
            files.add(imageFile.getCanonicalPath().replace(locationCanonicalPath, ""));
            if (files.size() >= MAX_FILES_LIMIT) {
                break;
            }
        }
        return files;
    } else {
        throw new FileNotFoundException("File location not found: " + locationCanonicalPath);
    }
}

From source file:org.mycontroller.standalone.utils.McTemplateUtils.java

@SuppressWarnings("unchecked")
public static QueryResponse get(Query query) throws IOException {
    //Check less info available and true, if true set less info return
    Boolean lessInfo = (Boolean) query.getFilters().get(TemplatesHandler.KEY_LESS_INFO);
    if (lessInfo) {
        query.setPageLimit(-1);/*ww  w  .j  a  va  2 s .com*/
    }

    String locationCanonicalPath = McUtils.getDirectoryLocation(
            FileUtils.getFile(AppProperties.getInstance().getTemplatesLocation()).getCanonicalPath());

    if (FileUtils.getFile(locationCanonicalPath).exists()) {
        List<McTemplate> files = new ArrayList<McTemplate>();
        List<String> filesString = new ArrayList<String>();

        //Filters
        //Extension filter
        String[] extensionSuffixFilter = null;
        if (query.getFilters().get(TemplatesHandler.KEY_EXTENSION) != null) {
            if (Arrays.asList(MC_SCRIPT_SUFFIX_FILTER)
                    .contains(query.getFilters().get(TemplatesHandler.KEY_EXTENSION))) {
                extensionSuffixFilter = new String[] {
                        (String) query.getFilters().get(TemplatesHandler.KEY_EXTENSION) };
            }
        }

        if (extensionSuffixFilter == null) {
            extensionSuffixFilter = MC_SCRIPT_SUFFIX_FILTER;
        }

        SuffixFileFilter extensionFilter = new SuffixFileFilter(extensionSuffixFilter, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        List<String> fileNames = (List<String>) query.getFilters().get(TemplatesHandler.KEY_NAME);
        if (fileNames != null && !fileNames.isEmpty()) {
            for (String fileName : fileNames) {
                if (nameFileFilter == null) {
                    nameFileFilter = FileFilterUtils
                            .and(new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                } else {
                    nameFileFilter = FileFilterUtils.and(nameFileFilter,
                            new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                }
            }
        }

        //Combine all filters
        IOFileFilter templatesFileFilter = null;
        if (nameFileFilter != null) {
            templatesFileFilter = FileFilterUtils.and(extensionFilter, nameFileFilter);
        } else {
            templatesFileFilter = extensionFilter;
        }
        List<File> templateFiles = new ArrayList<File>(FileUtils.listFiles(
                FileUtils.getFile(locationCanonicalPath), templatesFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) templateFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils.listFiles(FileUtils.getFile(locationCanonicalPath),
                new SuffixFileFilter(MC_SCRIPT_SUFFIX_FILTER, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)
                .size());

        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = templateFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (; fileFrom < fileTo; fileFrom++) {
            if (templateFiles.size() > fileFrom) {
                File templateFile = templateFiles.get(fileFrom);
                String name = templateFile.getCanonicalPath().replace(locationCanonicalPath, "");
                if (lessInfo) {
                    filesString.add(name);
                } else {
                    files.add(McTemplate.builder().name(name)
                            .extension(FilenameUtils.getExtension(templateFile.getCanonicalPath()))
                            .size(templateFile.length()).lastModified(templateFile.lastModified()).build());
                }
            } else {
                break;
            }
        }
        if (lessInfo) {
            return QueryResponse.builder().data(filesString).query(query).build();
        } else {
            return QueryResponse.builder().data(files).query(query).build();
        }

    } else {
        throw new FileNotFoundException("File location not found: " + locationCanonicalPath);
    }
}

From source file:org.objectpocket.storage.blob.FileBlobStore.java

@Override
public void cleanup(Set<Blob> referencedBlobs) throws IOException {
    if (referencedBlobs == null) {
        return;/*from  www.  j  a v  a2  s  .co  m*/
    }
    File dir = new File(directory + "/" + BLOB_STORE_DIRNAME);
    Set<String> paths = new HashSet<>(referencedBlobs.size());
    for (Blob blob : referencedBlobs) {
        String path = blob.getPath();
        if (path == null || path.isEmpty()) {
            path = blob.getId();
        }
        paths.add(path.replaceAll("\\\\", "/"));
    }
    initBlobStore(false);
    Collection<File> files = FileUtils.listFiles(dir, FileFilterUtils.fileFileFilter(),
            TrueFileFilter.INSTANCE);
    for (File file : files) {
        String path = file.getPath().replace(dir.getPath(), "");
        path = path.replaceAll("\\\\", "/");
        while (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (!paths.contains(path)) {
            File f = new File(directory + "/" + BLOB_STORE_DIRNAME + "/" + path);
            f.delete();
        }
    }
    // clear empty dirs
    Collection<File> dirs = FileUtils.listFilesAndDirs(dir, DirectoryFileFilter.DIRECTORY,
            DirectoryFileFilter.DIRECTORY);
    for (File d : dirs) {
        if (d.list().length == 0) {
            d.delete();
        }
    }
}

From source file:org.objectpocket.storage.blob.FileBlobStore.java

public long numEntries() throws IOException {
    File dir = new File(directory + "/" + BLOB_STORE_DIRNAME);
    Collection<File> files = FileUtils.listFiles(dir, FileFilterUtils.fileFileFilter(),
            TrueFileFilter.INSTANCE);
    return files.size();
}