Example usage for org.apache.commons.io FileUtils listFiles

List of usage examples for org.apache.commons.io FileUtils listFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils listFiles.

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:localSPs.BearDataShareAPI.java

public double getStorageSize() throws IOException {
    BigInteger num = new BigInteger("1024");
    String ans = "";
    BigInteger totalMemory = new BigInteger("21474836480");
    BigInteger used;/*w w w  .  ja  v a 2 s.co  m*/
    File dir = new File(ROOT_PATH);
    long totalUsed = 0; // total bytes
    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        totalUsed += file.length();
    }
    used = new BigInteger(String.valueOf(totalUsed));
    ans = totalMemory.subtract(used).divide(num).divide(num).toString();//MB
    return (Double.parseDouble(ans));
}

From source file:it.drwolf.ridire.utility.test.NewsCleaner.java

private void removeDirtyHtml() {
    File dir1 = new File(DIR1);
    File dir2 = new File(DIR2);
    List dir1files = new ArrayList(FileUtils.listFiles(dir1, null, false));
    List dir2files = new ArrayList(FileUtils.listFiles(dir2, null, false));
    Collections.sort(dir1files, new FileNameComparator());
    Collections.sort(dir2files, new FileNameComparator());
    for (int i = 0, j = 0; i < dir1files.size(); i++) {
        File f1 = (File) dir1files.get(i);
        File f2 = (File) dir2files.get(j);
        if (f1.getName().equals(f2.getName())) {
            j++;/*from  ww  w  .j  av  a2s  . co  m*/
            continue;
        } else {
            FileUtils.deleteQuietly(f1);
        }
    }
}

From source file:com.book.identification.task.BookSearch.java

@Override
public void run() {

    List<Volume> volumes = DAOFactory.getInstance().getVolumeDAO().findAll();

    for (Volume volume : volumes) {
        indexedFiles.add(new File(volume.getPath()));
    }/*  w w  w.  j  a  v a  2 s.  c  om*/
    Collection<File> entries = FileUtils.listFiles(root, new SuffixFileFilter(new String[] { ".pdf", ".chm" }),
            TrueFileFilter.INSTANCE);
    for (File fileToProcces : entries) {

        String fileSHA1 = null;
        try {
            fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(fileToProcces));
        } catch (IOException e1) {
            continue;
        }
        logger.info("Accepted file -> " + fileToProcces.getName() + " Hash -> " + fileSHA1);
        FileType fileType = FileType
                .valueOf(StringUtils.upperCase(FilenameUtils.getExtension(fileToProcces.getName())));
        try {
            fileQueue.put(new BookFile(fileToProcces, fileSHA1, fileType));
        } catch (InterruptedException e) {
            logger.info(e);
        }
    }
    nextWorker.notifyEndProducers();
}

From source file:com.mythesis.profileanalysis.Utils.java

/**
 * Method that returns all the files of a certain extension from a directory
 * @param directory_path A String with the directory 
 * @param filetype A string with the filetype (without dot symbol)
 * @return a Collection that contains all the files found
 *//*from   ww  w . j  av a2 s. c  o  m*/
public Collection<File> getinputfiles(String directory_path, String filetype) {
    String[] extensions = { filetype };//set the file extensions you would like to parse, e.g. you could have {txt,jpeg,pdf}
    File directory = new File(directory_path);
    //----FileUtils listfiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)

    //---- file filter is set to the extensions
    //---- the dirFilter is set to true and it performs recursive search to all the subdirectories
    //String collection = FileUtils.listFiles(directory, extensions, true).toString();
    Collection<File> Files = FileUtils.listFiles(directory, extensions, false);
    String[] paths = new String[Files.size()];//----the String array will contain all the paths of the files
    int j = 0;
    for (File file : Files) {
        paths[j] = file.getPath();
        j++;
    }
    return Files;
}

From source file:com.doculibre.constellio.plugins.PluginFactory.java

private static void initPluginManager() {
    if (pm == null) {
        pm = PluginManagerFactory.createPluginManager();
        File classesDir = ClasspathUtils.getClassesDir();

        pm.addPluginsFrom(classesDir.toURI());

        File pluginsDir = getPluginsDir();
        File[] pluginDirs = pluginsDir.listFiles(new FileFilter() {
            @Override//from  ww w  .java 2  s.  c  o  m
            public boolean accept(File pathname) {
                boolean accept;
                if (pathname.isFile()) {
                    accept = false;
                } else if (DefaultConstellioPlugin.NAME.equals(pathname)) {
                    accept = true;
                } else {
                    List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames();
                    accept = availablePluginNames.contains(pathname.getName());
                }
                return accept;
            }
        });
        if (pluginDirs == null) {
            return;
        }
        for (File pluginDir : pluginDirs) {
            // Plugin root dir jars
            Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false);
            // Accept only one root dir jar
            File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next();
            if (pluginJarFile != null) {
                URI pluginJarFileURI = pluginJarFile.toURI();
                pm.addPluginsFrom(pluginJarFileURI);

                PluginManagerImpl pmImpl = (PluginManagerImpl) pm;
                ClassPathManager classPathManager = pmImpl.getClassPathManager();
                ClassLoader classLoader = ClassPathManagerUtils.getClassLoader(classPathManager, pluginJarFile);
                classLoaders.add(classLoader);

                File pluginLibDir = new File(pluginDir, "lib");
                if (pluginLibDir.exists() && pluginLibDir.isDirectory()) {
                    Collection<File> pluginDependencies = FileUtils.listFiles(pluginLibDir,
                            new String[] { "jar" }, false);
                    ClassPathManagerUtils.addJarDependencies(classPathManager, pluginJarFile,
                            pluginDependencies);
                }
            }
        }

        File webInfDir = ClasspathUtils.getWebinfDir();
        File libDir = new File(webInfDir, "lib");
        File[] contellioJarFiles = libDir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                boolean accept;
                if (pathname.isDirectory()) {
                    accept = false;
                } else {
                    List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames();
                    String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName());
                    accept = availablePluginNames.contains(jarNameWoutExtension);
                }
                return accept;
            }
        });
        for (File constellioJarFile : contellioJarFiles) {
            URI constellioJarFileURI = constellioJarFile.toURI();
            pm.addPluginsFrom(constellioJarFileURI);
        }
    }
}

From source file:com.dotcms.publisher.pusher.bundler.LanguageBundler.java

private void copyFileToBundle(File bundleRoot, File messagesDir, Date lastBundleDate)
        throws IOException, DotBundleException, DotDataException, DotSecurityException, DotPublisherException {

    String myFolderUrl = bundleRoot.getPath() + File.separator + "messages";
    File bundleFolderMessages = new File(myFolderUrl);

    for (File lang : FileUtils.listFiles(messagesDir, new String[] { "properties" }, false)) {
        long lastMod = lang.lastModified();
        long startTime = -1;
        if (lastBundleDate != null)
            startTime = lastBundleDate.getTime();
        if (lastMod > startTime) {
            if (!bundleFolderMessages.exists())
                bundleFolderMessages.mkdirs();

            FileUtils.copyFileToDirectory(lang, bundleFolderMessages);
        }//w w w .  jav  a  2s  .  c o  m
    }
}

From source file:localSPs.SpiderOakAPI.java

public double getStorageSize() throws IOException {
    BigInteger num = new BigInteger("1024");
    String ans = "";
    BigInteger totalMemory = new BigInteger("32212254720");
    BigInteger used;//from w  ww.j  a v  a 2s.co  m
    File dir = new File(ROOT_PATH);
    long totalUsed = 0; // total bytes

    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        totalUsed += file.length();
    }
    used = new BigInteger(String.valueOf(totalUsed));
    ans = totalMemory.subtract(used).divide(num).divide(num).toString();//MB
    return (Double.parseDouble(ans));
}

From source file:it.geosolutions.geobatch.opensdi.csvingest.CSVIngestActionTest.java

@Test
public void loadAll() throws Exception {

    createCropDescriptors();/*from  w ww  .j av  a 2  s.  c om*/
    createUnitOfMeasures();

    Queue<EventObject> events = new LinkedList<EventObject>();
    File dir = loadFile("all");
    assertNotNull(dir);
    assertTrue(dir.isDirectory());

    CSVIngestAction action = new CSVIngestAction(new CSVIngestConfiguration(null, null, null));
    //        action.setCropDataDao(cropDataDAO);
    //        action.setCropDescriptorDao(cropDescriptorDAO);
    //        action.setAgrometDao(agrometDAO);
    //        action.setCropStatusDao(cropStatusDAO);
    action.setUnitOfMeasureService(unitOfMeasureService);
    action.afterPropertiesSet();

    for (File file : FileUtils.listFiles(dir, new String[] { "csv" }, true)) {
        LOGGER.info("Loading " + file);
        FileSystemEvent event = new FileSystemEvent(file, FileSystemEventType.FILE_ADDED);
        events.add(event);
        action.addListener(new DummyProgressListener());
        action.execute(events);
    }
    checkSampleData();

}

From source file:fr.fastconnect.factory.tibco.bw.codereview.BWProjectBuilder.java

private void addSources(ProjectDefinition project) {
    final File basedir = project.getBaseDir();

    logger.debug(basedir.getAbsolutePath());

    // TODO: ignore child modules folders more properly
    IOFileFilter custom = new IOFileFilter() {
        @Override/*from w w w.  ja v a2s  .c o  m*/
        public boolean accept(File file) {
            return file.isDirectory() && !(new File(file, "pom.xml").exists())
                    || file.getAbsolutePath().equals(basedir.getAbsolutePath());
        }

        @Override
        public boolean accept(File dir, String name) {
            return false;
        }
    };

    Collection<File> files = FileUtils.listFiles(basedir, new SuffixFileFilter(".process"),
            new AndFileFilter(new NotFileFilter(new PrefixFileFilter("target")), custom));

    project.addSources(files.toArray(new File[0]));
}

From source file:com.denimgroup.threadfix.framework.impl.dotNet.DotNetModelMappings.java

@SuppressWarnings("unchecked")
public DotNetModelMappings(@Nonnull File rootDirectory) {

    modelParsers = list();/*w ww .  ja  v  a  2s  .  c  o  m*/

    if (rootDirectory.exists() && rootDirectory.isDirectory()) {

        Collection<File> modelFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("cs"),
                TrueFileFilter.INSTANCE);

        for (File file : modelFiles) {
            if (file != null && file.exists() && file.isFile()) {
                modelParsers.add(ViewModelParser.parse(file));
            }
        }
    }

    collapse();
}