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:com.quavo.util.FileUtilities.java

/**
 * Gets the class files inside a directory.
 *
 * @param directory The directory.//from  ww w  .  j  a  v  a2 s .c  o  m
 * @return An array of classes.
 * @throws IOException If an I/O exception is thrown.
 * @throws ClassNotFoundException If the class is not found.
 */
public static Class<?>[] getAllClasses(String directory) throws IOException, ClassNotFoundException {
    String path = Constants.OUTPUT_DIRECTORY + "/" + directory.replace('.', '/') + "/";
    File dir = new File(path);
    List<Class<?>> classes = new ArrayList<>();
    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.getName().endsWith(".class")) {
            classes.add(Class
                    .forName(file.getParent().replace("\\", ".").replace(Constants.OUTPUT_DIRECTORY + ".", "")
                            + '.' + file.getName().substring(0, file.getName().length() - 6)));
        }
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:com.ebay.logstorm.server.utils.LogStormServerDebug.java

private static File findAssemblyJarFile() {
    String projectRootDir = System.getProperty("user.dir");
    String assemblyModuleTargeDirPath = projectRootDir + "/assembly/target/";
    File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath);
    if (!assemblyTargeDirFile.exists()) {
        throw new IllegalStateException(
                assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under "
                        + projectRootDir + " to build the project firstly and retry");
    }//from  w  w w  .  j av a  2  s  .  co m
    String jarFileNameWildCard = "logstorm-assembly-*.jar";
    Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile,
            new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE);
    if (jarFiles.size() == 0) {
        throw new IllegalStateException(
                "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry");
    }
    File jarFile = jarFiles.iterator().next();
    LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath());
    return jarFile;
}

From source file:com.ebay.logstorm.core.utils.PipelineEnvironmentLoaderForTest.java

private static File findAssemblyJarFile(String relativeToHomePath) {
    String projectRootDir = System.getProperty("user.dir");
    String assemblyModuleTargeDirPath = relativeToHomePath == null ? projectRootDir + "/assembly/target/"
            : projectRootDir + relativeToHomePath + "/assembly/target/";
    File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath);
    if (!assemblyTargeDirFile.exists()) {
        throw new IllegalStateException(
                assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under "
                        + projectRootDir + " to build the project firstly and retry");
    }/*from w ww.ja  v a  2 s  .c o m*/
    String jarFileNameWildCard = "logstorm-assembly-*.jar";
    Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile,
            new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE);
    if (jarFiles.size() == 0) {
        throw new IllegalStateException(
                "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry");
    }
    File jarFile = jarFiles.iterator().next();
    LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath());
    return jarFile;
}

From source file:com.denimgroup.threadfix.framework.impl.dotNetWebForm.MasterPageParser.java

public static Map<String, AspxParser> getMasterFileMap(File rootDirectory, Map<String, AscxFile> ascxFileMap) {
    if (rootDirectory == null) {
        throw new IllegalArgumentException("Can't pass null argument to getMasterFileMap()");
    } else if (!rootDirectory.isDirectory()) {
        throw new IllegalArgumentException("Can't pass a non-directory file argument to getMasterFileMap()");
    }//from   w ww  .  j  a v a 2s.c om

    Map<String, AspxParser> parserMap = map();

    Collection masterFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("Master"),
            TrueFileFilter.INSTANCE);

    for (Object aspxFile : masterFiles) {
        if (aspxFile instanceof File) {
            File file = (File) aspxFile;

            AspxParser aspxParser = AspxParser.parse(file);
            AspxUniqueIdParser uniqueIdParser = AspxUniqueIdParser.parse(file, ascxFileMap);

            aspxParser.parameters.addAll(uniqueIdParser.parameters);
            parserMap.put(file.getName(), aspxParser);
        }
    }

    return parserMap;
}

From source file:com.magnet.tools.tests.FileSystemStepDefs.java

@Then("^the directory structure for \"([^\"]*)\" should be:$")
public static void the_directory_should_be(String directory, List<String> entries) throws Throwable {
    the_directory_should_exist(directory);
    List<AssertionError> errors = new ArrayList<AssertionError>();
    for (String entry : entries) {
        try {/*from w  w w  .j a  v a 2  s.c  o  m*/
            if (entry.endsWith("/") || entry.endsWith("\\")) {
                ScenarioUtils.the_directory_under_directory_should_exist(directory, entry);
            } else {
                ScenarioUtils.the_file_under_directory_should_exist(directory, entry);
            }
        } catch (AssertionError e) {
            errors.add(e);
        }
    }
    if (!errors.isEmpty()) {
        String dir = ScenarioUtils.expandVariables(directory);
        StringBuilder tree = new StringBuilder();
        for (AssertionError e : errors) {
            tree.append("Entry not found: ").append(e.getMessage()).append("\n");
        }
        tree.append("\n").append("The directory structure for ").append(dir).append(" was:").append("\n");
        for (File f : FileUtils.listFilesAndDirs(new File(dir), TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE)) {
            tree.append(f).append("\n");
        }
        throw new AssertionError(tree.toString(), errors.get(0));
    }
}

From source file:net.shopxx.util.CompressUtils.java

public static void archive(File[] srcFiles, File destFile, String archiverName) {
    Assert.notNull(destFile);//ww w .j  a va  2s  .  c  o  m
    Assert.state(!destFile.exists() || destFile.isFile());
    Assert.hasText(archiverName);

    File parentFile = destFile.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    ArchiveOutputStream archiveOutputStream = null;
    try {
        archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiverName,
                new BufferedOutputStream(new FileOutputStream(destFile)));
        if (ArrayUtils.isNotEmpty(srcFiles)) {
            for (File srcFile : srcFiles) {
                if (srcFile == null || !srcFile.exists()) {
                    continue;
                }
                Set<File> files = new HashSet<File>();
                if (srcFile.isFile()) {
                    files.add(srcFile);
                }
                if (srcFile.isDirectory()) {
                    files.addAll(FileUtils.listFilesAndDirs(srcFile, TrueFileFilter.INSTANCE,
                            TrueFileFilter.INSTANCE));
                }
                String basePath = FilenameUtils.getFullPath(srcFile.getCanonicalPath());
                for (File file : files) {
                    try {
                        String entryName = FilenameUtils.separatorsToUnix(
                                StringUtils.substring(file.getCanonicalPath(), basePath.length()));
                        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, entryName);
                        archiveOutputStream.putArchiveEntry(archiveEntry);
                        if (file.isFile()) {
                            InputStream inputStream = null;
                            try {
                                inputStream = new BufferedInputStream(new FileInputStream(file));
                                IOUtils.copy(inputStream, archiveOutputStream);
                            } catch (FileNotFoundException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } catch (IOException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } finally {
                                IOUtils.closeQuietly(inputStream);
                            }
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    } finally {
                        archiveOutputStream.closeArchiveEntry();
                    }
                }
            }
        }
    } catch (ArchiveException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }
}

From source file:com.ricston.connectors.lightweightclustering.LightweightClusteringConnectorTest.java

@Test
public void testPollingAndQueue() throws Exception {

    //poller is creating a message every second
    //5sec of waiting time should create around 5 messages 
    Thread.sleep(5000);/*from   w w  w.  j a  v a2s. c  o  m*/

    Collection<?> itemFiles = FileUtils.listFiles(items, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    Assert.assertTrue(itemFiles.size() >= 5);
}

From source file:biz.gabrys.maven.plugin.util.io.RegexFileScanner.java

/**
 * {@inheritDoc} You must use '/' as path separator in include/exclude patterns.
 */// w w w  .j av a 2  s.  c o  m
public Collection<File> getFiles(final File directory, final String[] includes, final String[] excludes) {
    final IOFileFilter filter = createFileFilter(directory, includes, excludes);
    return FileUtils.listFiles(directory, filter, TrueFileFilter.INSTANCE);
}

From source file:neembuu.uploader.zip.generator.utils.NUFileUtils.java

/**
 * Get all the files with the given extension.
 * @param file The directory where there are all the files.
 * @param extension The extension of the files to search for.
 * @return The list of the files./*  w w w . ja v a2s .com*/
 */
public static Collection<File> listAllFilesWithExt(File file, final String extension) {
    return FileUtils.listFiles(file, new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            // to prevent old libs compiled by netbeans from getting into.
            // i know since we are using git this should not happen, but when the code
            // was been tweaked for testing, this statement was reqired.
            if (file.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(file.getName(), extension);
        }

        @Override
        public boolean accept(File dir, String name) {
            if (dir.getAbsolutePath().replace('/', '\\').contains("\\dist\\"))
                return false;
            return FilenameUtils.isExtension(name, extension);
        }
    }, TrueFileFilter.INSTANCE);
}

From source file:com.edsoft.teknosaproject.bean.TreeNodeBean.java

@PostConstruct
public void initialize() {
    root = null;//from   w ww. ja v a2  s . c o  m
    fileList = null;
    //fileList = (LinkedList<File>) FileUtils.listFilesAndDirs(Paths.get("E:", "T_K_B AnaDepo").toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    fileList = (LinkedList<File>) FileUtils.listFilesAndDirs(Paths.get(DIR, "AnaDepo").toFile(),
            TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    root = new DefaultTreeNode(fileList.getFirst().getName(), null);
    rec(root.getChildren(), fileList, 1, fileList.getFirst(), root);
}