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.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java

protected static void reNameResources(final String versionInProjectName, File copyDir,
        String versionInProjectName2, String version_base, String classifier_base, String version_target,
        String classifier_target) {
    System.out.println("PrepareSIDEModulesMigration.reNameResources() " + versionInProjectName + "->"
            + versionInProjectName2);//from   w  ww  .  ja  v a 2  s  . c  o  m
    Collection<?> listFiles = FileUtils.listFiles(copyDir, TrueFileFilter.INSTANCE, new IOFileFilter() {

        public boolean accept(File dir, String name) {
            return !name.equals(".svn");
        }

        public boolean accept(File file) {
            return !file.getName().equals(".svn");
        }
    });
    for (Object object : listFiles) {

        File f = (File) object;

        replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base,
                version_target, classifier_target, f, false);

        renameFile(versionInProjectName, versionInProjectName2, f);
    }

    // renameFile(versionInProjectName, versionInProjectName2, copyDir);

    renameDirectories(copyDir, versionInProjectName, versionInProjectName2);
}

From source file:com.github.drochetti.javassist.maven.ClassTransformer.java

protected Iterator<String> iterateClassnames(final String dir) {
    final String[] extensions = { ".class" };
    final File directory = new File(dir);
    // only files with extension '.class' and NOT with '$' - for ignoring nested classes
    // javassist doesn't support nested classes
    // @see http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/tutorial/tutorial2.html #4.7 Limitations
    ////from   w  ww  . j a va 2  s  .  c o  m
    // Michael Haak: For me, working with nested classes works, so why not using all classes?
    final IOFileFilter fileFilter = new SuffixFileFilter(extensions);
    final IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
    return ClassnameExtractor.iterateClassnames(directory,
            FileUtils.iterateFiles(directory, fileFilter, dirFilter));
}

From source file:modmanager.backend.Modification.java

/**
 * Tries to find read me files and returns the text
 *
 * @return/*from w w w.  j av  a2  s .c  o m*/
 */
public String getReadMe() {
    StringBuilder readme = new StringBuilder();

    for (File file : FileUtils.listFiles(directory, README_FILENAME_FILTER, TrueFileFilter.INSTANCE)) {
        try {
            readme.append(FileUtils.readFileToString(file));
            readme.append("\n---------\n");
        } catch (IOException ex) {

        }
    }

    if (readme.length() == 0) {
        readme.append("No readme found.");
    }

    return readme.toString();
}

From source file:com.infosupport.ellison.core.archive.ApplicationArchive.java

/**
 * Finds all files in a directory matching a specific pattern.
 * <p/>//from   w  w w .  ja  v  a2  s  .  co m
 * For a definition of what kinds of patterns are supported, see {@link WildcardFileFilter}.
 *
 * @param basePath
 *     the name of the base directory to search in. May be null if looking for files from the root directory.
 * @param wildcardPattern
 *     files matching this pattern will be in the returned collection. See {@link WildcardFileFilter} for the
 *     pattern format
 * @param doRecursively
 *     whether to search for files matching {@code wildcardPattern} recursively or not.
 *
 * @return a list of all files matching {@code wildcardPattern} in directory {@code basePath} within this
 *         application archive.
 *
 * @throws FileNotFoundException
 *     if {@code basePath != null} and {@code basePath} does not point to an existing file in the application
 *     archive
 */
public Collection<URI> findFilesByGlobPattern(String basePath, String wildcardPattern, boolean doRecursively)
        throws FileNotFoundException {
    IOFileFilter fileFilter = new WildcardFileFilter(wildcardPattern);
    File baseDir = null;
    IOFileFilter dirFilter = null;

    if (basePath == null) {
        baseDir = unpackedPath;
    } else {
        if (!isPathRelative(basePath)) {
            throw new SecurityException(
                    "It is not permitted to supply base paths containing references to parent directories ('..').");
        }
        baseDir = new File(unpackedPath, basePath);
    }

    if (doRecursively) {
        dirFilter = TrueFileFilter.INSTANCE;
    } else {
        dirFilter = FalseFileFilter.INSTANCE;
    }

    if (!baseDir.exists()) {
        throw new FileNotFoundException(String.format("Basepath '%s' does not exist within archive '%s'",
                basePath, getApplicationFile().getAbsolutePath()));
    }

    if (!baseDir.isDirectory()) {
        throw new IllegalArgumentException(
                String.format("Basepath '%s' is not a directory within the archive", basePath));
    }

    return Collections2.transform(FileUtils.listFiles(baseDir, fileFilter, dirFilter),
            new Function<File, URI>() {
                @Override
                public URI apply(File input) {
                    return relativizePath(input.toURI());
                }
            });
}

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

public void testSigningWithTwoOutboxes() throws SignerException, IOException, ConfigurationException {
    initialize();//from   ww w  .  j  ava 2 s  .  c  o  m
    System.out.println("testSigningWithTwoOutboxes");
    SigningOutbox signOutbox1 = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox1, signatureProperties,
            null);
    SigningOutbox signOutbox2 = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox2, signatureProperties,
            null);

    List<SigningOutbox> outboxes = Arrays.asList(signOutbox1, signOutbox2);

    final File workingDir = createWorkingDir();
    final File corruptedDir = new File(workingDir, ClientCommons.CORRUPTED_DIR);
    Signer signer = new Signer(outboxes, workingDir, corruptedDir);

    List<File> signedFiles = signer.sign();
    signedFiles.forEach((f) -> {
        f.deleteOnExit();
    });
    assertEquals(signOutbox1.getAllPDFsToSign().size() + signOutbox2.getAllPDFsToSign().size(),
            signedFiles.size());

    signer.cleanUp(signedFiles);
    assertEquals(0, signOutbox1.getAllPDFsToSign().size());
    signer.cleanUp(signedFiles);
    assertEquals(0, signOutbox2.getAllPDFsToSign().size());

    // The corrupted directory must be empty
    assert FileUtils.listFiles(corruptedDir, TrueFileFilter.INSTANCE, null).isEmpty();
}

From source file:com.ibm.soatf.component.file.FileComponent.java

/**
 * Returns the first file that matches the *_&lt;fileName&gt; pattern.
 * If no such file exists, it is created by calling the <code>createLocalFile()</code> method
 * @return the existing or newly created file
 * @throws FrameworkExecutionException when <code>IOException</code> occurs
 *///from   w w  w. j  ava  2  s  . c om
private java.io.File getLocalFile() throws FrameworkExecutionException {
    String pattern = "*_" + fileName;
    java.io.File[] files = FileUtils.convertFileCollectionToFileArray(
            FileUtils.listFiles(workingDir, new WildcardFileFilter(pattern), TrueFileFilter.INSTANCE));
    if (files.length == 0) {
        return createLocalFile();
    }
    if (files.length > 1) {
        //TODO
    }
    return files[0];
}

From source file:bioLockJ.module.classifier.r16s.QiimeClassifier.java

/**
 * Subclasses that pick OTUs call this method to initialize the QIIME Mapping file from the output dir
 * of the previous executor.  If the previous executor output a new qiime mapping (via VALIDATED_MAPPING),
 * update the config.metadata file.  If this is a re-run attempt this method overrides the configured
 * metadata file in the prop file, with those found in the INPUT_DIR
 * @param dir/* w  w  w.  ja va  2s .co  m*/
 * @throws Exception
 */
protected void initMappingFile(final File dir) throws Exception {
    if (dir == null) {
        Log.out.info("Restarting failed run with QIIME Pick OTU step so must configure QIIME mapping file: "
                + Config.INPUT_METADATA);
        return;
    }
    final String searchTerm = "*" + VALIDATED_MAPPING;
    Log.out.info("Get mapping file from " + getDirName(dir) + " ending in: " + searchTerm);
    final IOFileFilter ff = new WildcardFileFilter(searchTerm);
    final Collection<File> files = FileUtils.listFiles(dir, ff, TrueFileFilter.INSTANCE);
    final int count = count(files);
    if (count == 0) {
        throw new Exception("Unable to find QIIME mapping file ending in " + VALIDATED_MAPPING
                + " in input directory: " + dir.getAbsolutePath());
    } else if (count > 1) {
        throw new Exception("Too many QIIME mapping files (total=" + count + ") found ending in " + searchTerm
                + " in input directory: " + dir.getAbsolutePath());
    }

    MetadataUtil.setMetadata(files.iterator().next());
}

From source file:com.badlogicgames.packr.Packr.java

private void minimizeJre(Config config, File outDir) throws IOException {
    // remove stuff from the JRE
    System.out.println("minimizing JRE");
    System.out.println("unpacking rt.jar");
    ZipUtil.unpack(new File(outDir, "jre/lib/rt.jar"), new File(outDir, "jre/lib/rt"));

    if (config.platform == Platform.windows) {
        FileUtils.deleteDirectory(new File(outDir, "jre/bin/client"));
        for (File file : new File(outDir, "jre/bin").listFiles()) {
            if (file.getName().endsWith(".exe"))
                file.delete();/*from w  ww .  j  a  v a2  s . co  m*/
        }
    } else {
        FileUtils.deleteDirectory(new File(outDir, "jre/bin"));
    }
    for (String minimizedDir : config.minimizeJre) {
        File file = new File(outDir, minimizedDir);
        if (file.isDirectory())
            FileUtils.deleteDirectory(new File(outDir, minimizedDir));
        else
            file.delete();
    }
    new File(outDir, "jre/lib/rhino.jar").delete();

    System.out.println("packing rt.jar");
    new File(outDir, "jre/lib/rt.jar").delete();
    ZipUtil.pack(new File(outDir, "jre/lib/rt"), new File(outDir, "jre/lib/rt.jar"));
    FileUtils.deleteDirectory(new File(outDir, "jre/lib/rt"));

    // let's remove any shared libs not used on the platform, e.g. libgdx/lwjgl natives
    File jar = new File(outDir, new File(config.jar).getName());
    File jarDir = new File(outDir, jar.getName() + ".tmp");
    ZipUtil.unpack(jar, jarDir);

    Set<String> extensions = new HashSet<String>();
    if (config.platform != Platform.linux32 && config.platform != Platform.linux64) {
        extensions.add(".so");
    }
    if (config.platform != Platform.windows) {
        extensions.add(".dll");
    }
    if (config.platform != Platform.mac) {
        extensions.add(".dylib");
    }

    for (Object obj : FileUtils.listFiles(jarDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        File file = new File(obj.toString());
        for (String extension : extensions) {
            if (file.getName().endsWith(extension))
                file.delete();
        }
    }

    jar.delete();
    ZipUtil.pack(jarDir, jar);
    FileUtils.deleteDirectory(jarDir);
}

From source file:modmanager.backend.Modification.java

/**
 * Tries to find some images (screenshots, ...)
 *
 * @return/*from w ww . ja  v a 2  s  .c o  m*/
 */
public ArrayList<File> getScreenshotImages() {
    ArrayList<File> files = new ArrayList<>();

    files.addAll(FileUtils.listFiles(directory, IMAGE_FILENAME_FILTER, TrueFileFilter.INSTANCE));

    return files;
}

From source file:de.uzk.hki.da.cb.RestructureAction.java

private void listAllFiles() {
    logger.debug("Listing all files on WorkArea:");
    List<File> files = (List<File>) FileUtils.listFiles(new File(wa.objectPath().toString()),
            TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File f : files) {
        logger.debug("" + f);
    }/*from  ww  w . java 2s .  co m*/
}