Example usage for org.apache.commons.io.filefilter FileFileFilter FILE

List of usage examples for org.apache.commons.io.filefilter FileFileFilter FILE

Introduction

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

Prototype

IOFileFilter FILE

To view the source code for org.apache.commons.io.filefilter FileFileFilter FILE.

Click Source Link

Document

Singleton instance of file filter

Usage

From source file:jenkins.plugins.shiningpanda.utils.FilePathUtil.java

/**
 * Synchronize a file or all files in a directory.
 * //w w  w . ja v  a2s  . co  m
 * @param src
 *            The source file or directory
 * @param dest
 *            The destination file or directory
 * @return The destination file or directory
 * @throws IOException
 * @throws InterruptedException
 */
public static FilePath synchronize(FilePath src, FilePath dest) throws IOException, InterruptedException {
    // Handle files
    if (isFile(src)) {
        // Check if differ
        if (differ(src, dest))
            // If differ, copy
            src.copyTo(dest);
    }
    // Handle directory
    else if (isDirectory(src)) {
        // Get the list of the files to synchronize
        List<FilePath> srcFiles = src.list(FileFileFilter.FILE);
        // Get the list of the related file names
        List<String> srcNames = new ArrayList<String>();
        // Go threw the files
        for (FilePath srcFile : srcFiles)
            // Add to the source list
            srcNames.add(srcFile.getName());
        // Delete files in destination folder that don't exist anymore in
        // source folder
        if (dest.exists())
            // List the files
            for (FilePath destFile : dest.list(FileFileFilter.FILE))
                // Check if contained in the source files
                if (!srcNames.contains(destFile.getName()))
                    // If not delete it
                    destFile.delete();
        // Synchronize all files
        for (FilePath srcFile : srcFiles)
            // Synchronize folders
            synchronize(srcFile, new FilePath(dest, srcFile.getName()));
    }
    // Return the destination file of directory
    return dest;
}

From source file:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java

/**
 * @param latestDeployDirectory// w  w  w . j a va  2  s .c  o m
 * @return
 */
private IOFileFilter getFilefilter(File latestDeployDirectory) {
    IOFileFilter fileFilter = new SuffixFileFilter(fileTypes);
    fileFilter = FileFilterUtils.andFileFilter(FileFileFilter.FILE, fileFilter);
    fileFilter = FileFilterUtils.andFileFilter(new AgeFileFilter(latestDeployDirectory, false), fileFilter);
    return fileFilter;
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java

/**
 * This will save the HTML markup + css file to a specified folder
 *
 * @param tempFilepath the temp folder where
 * @return//from  w w w .j a v  a  2s .  c o m
 */
private Path exportMarkup(Path tempFilepath) {
    Path resultPath;
    if (outputPath != null) {
        resultPath = outputPath;
    } else {
        resultPath = workingDirectory;
    }

    Path markupDir = resultPath.resolve(title + "-markup");
    try {
        try {
            Files.createDirectory(markupDir);
        } catch (FileAlreadyExistsException e) {
            // do nothing
        }

        Path tempDirPath = tempFilepath.getParent();
        File tempDir = tempDirPath.toFile();

        // Copy all files from temp folder to the markup output folder
        String[] files = tempDir.list(FileFileFilter.FILE);
        for (int i = 0; i < files.length; i++) {
            Files.copy(tempDirPath.resolve(files[i]), markupDir.resolve(files[i]),
                    StandardCopyOption.REPLACE_EXISTING);
        }

        logger.info("Exported markup to folder: " + markupDir.toAbsolutePath().toString());
    } catch (IOException e) {
        logger.error("Error saving markup files: " + e.getMessage(), e);
        return null;
    }
    return markupDir;
}

From source file:annis.administration.DefaultAdministrationDao.java

void importBinaryData(String path) {
    log.info("importing all binary data from ExtData");
    File extData = new File(path + "/ExtData");
    if (extData.canRead() && extData.isDirectory()) {
        // import toplevel corpus media files
        File[] topFiles = extData.listFiles((FileFilter) FileFileFilter.FILE);
        for (File data : topFiles) {
            String extension = FilenameUtils.getExtension(data.getName());
            try {
                if (mimeTypeMapping.containsKey(extension)) {
                    log.info("import " + data.getCanonicalPath() + " to staging area");

                    // search for corpus_ref
                    String sqlScript = "SELECT id FROM _corpus WHERE top_level IS TRUE LIMIT 1";
                    long corpusID = jdbcTemplate.queryForLong(sqlScript);

                    importSingleFile(data.getCanonicalPath(), corpusID);
                } else {
                    log.warn("not importing " + data.getCanonicalPath() + " since file type is unknown");
                }//from www.j a v  a  2  s .  c  o m
            } catch (IOException ex) {
                log.error("no canonical path given", ex);
            }
        }

        // get each subdirectory (which corresponds to an document name)
        File[] documents = extData.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
        for (File doc : documents) {
            if (doc.isDirectory() && doc.canRead()) {
                File[] dataFiles = doc.listFiles((FileFilter) FileFileFilter.FILE);
                for (File data : dataFiles) {
                    String extension = FilenameUtils.getExtension(data.getName());
                    try {
                        if (mimeTypeMapping.containsKey(extension)) {
                            log.info("import " + data.getCanonicalPath() + " to staging area");

                            // search for corpus_ref
                            String sqlScript = "SELECT id FROM _corpus WHERE \"name\" = ? LIMIT 1";
                            long corpusID = jdbcTemplate.queryForLong(sqlScript, doc.getName());

                            importSingleFile(data.getCanonicalPath(), corpusID);
                        } else {
                            log.warn(
                                    "not importing " + data.getCanonicalPath() + " since file type is unknown");
                        }
                    } catch (IOException ex) {
                        log.error("no canonical path given", ex);
                    }
                }
            }
        }
    }
}

From source file:io.manasobi.utils.FileUtils.java

/**
 *   ?  ?? . /*from www . ja v  a  2  s .  c  o m*/
 * 
 * @param dir 
 * @param includeRootDir  ?? ? ? . (true ? ?? ?)
 * @return  ?  ??  
 */
public static List<String> listFileAndDirNames(String dir, boolean includeRootDir) {

    List<File> dirs = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(new File(dir),
            FileFileFilter.FILE, DirectoryFileFilter.DIRECTORY);

    List<String> dirNameList = new ArrayList<String>();

    int index = 0;

    for (File dirUnit : dirs) {

        if (index++ == 0 && !includeRootDir) {
            continue;
        }

        dirNameList.add(dirUnit.getAbsolutePath());
        index++;
    }

    return dirNameList;
}

From source file:io.manasobi.utils.FileUtils.java

/**
 *   ?  ?? File ?  . /*w  ww .  j a v  a2  s  .c o m*/
 * 
 * @param dir 
 * @param includeRootDir  ?? ? ? . (true ? ?? ?)
 * @return  ?  ??  File ? 
 */
public static File[] listFilesAndDirs(String dir, boolean includeRootDir) {

    List<File> filesAndDirs = (List<File>) org.apache.commons.io.FileUtils.listFilesAndDirs(new File(dir),
            FileFileFilter.FILE, DirectoryFileFilter.DIRECTORY);

    List<File> filesAndDirsList = new ArrayList<File>();

    int index = 0;

    for (File fileOrDir : filesAndDirs) {

        if (index++ == 0 && !includeRootDir) {
            continue;
        }

        filesAndDirsList.add(fileOrDir);
        index++;
    }

    return filesAndDirsList.toArray(new File[filesAndDirsList.size()]);

}

From source file:annis.administration.AdministrationDao.java

void importBinaryData(String path, String toplevelCorpusName) {
    log.info("importing all binary data from ExtData");
    File extData = new File(path + "/ExtData");
    if (extData.canRead() && extData.isDirectory()) {
        // import toplevel corpus media files
        File[] topFiles = extData.listFiles((FileFilter) FileFileFilter.FILE);
        for (File data : topFiles) {
            String extension = FilenameUtils.getExtension(data.getName());
            try {
                if (mimeTypeMapping.containsKey(extension)) {
                    log.info("import " + data.getCanonicalPath() + " to staging area");

                    // search for corpus_ref
                    String sqlScript = "SELECT id FROM _corpus WHERE top_level IS TRUE LIMIT 1";
                    long corpusID = getJdbcTemplate().queryForLong(sqlScript);

                    importSingleFile(data.getCanonicalPath(), toplevelCorpusName, corpusID);
                } else {
                    log.warn("not importing " + data.getCanonicalPath() + " since file type is unknown");
                }/* w w w  . java 2 s  . c  om*/
            } catch (IOException ex) {
                log.error("no canonical path given", ex);
            }
        }

        // get each subdirectory (which corresponds to an document name)
        File[] documents = extData.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
        for (File doc : documents) {
            if (doc.isDirectory() && doc.canRead()) {
                File[] dataFiles = doc.listFiles((FileFilter) FileFileFilter.FILE);
                for (File data : dataFiles) {
                    String extension = FilenameUtils.getExtension(data.getName());
                    try {
                        if (mimeTypeMapping.containsKey(extension)) {
                            log.info("import " + data.getCanonicalPath() + " to staging area");

                            // search for corpus_ref
                            String sqlScript = "SELECT id FROM _corpus WHERE \"name\" = ? LIMIT 1";
                            long corpusID = getJdbcTemplate().queryForLong(sqlScript, doc.getName());

                            importSingleFile(data.getCanonicalPath(), toplevelCorpusName, corpusID);
                        } else {
                            log.warn(
                                    "not importing " + data.getCanonicalPath() + " since file type is unknown");
                        }
                    } catch (IOException ex) {
                        log.error("no canonical path given", ex);
                    }
                }
            }
        }
    }
}

From source file:com.jayway.maven.plugins.android.phase09package.ApkMojo.java

private void copyLocalNativeLibraries(final File localNativeLibrariesDirectory, final File destinationDirectory)
        throws MojoExecutionException {
    getLog().debug("Copying existing native libraries from " + localNativeLibrariesDirectory);
    try {/*from  w w w . ja v  a  2  s  . com*/

        IOFileFilter libSuffixFilter = FileFilterUtils.suffixFileFilter(".so");

        IOFileFilter gdbserverNameFilter = FileFilterUtils.nameFileFilter("gdbserver");
        IOFileFilter orFilter = FileFilterUtils.or(libSuffixFilter, gdbserverNameFilter);

        IOFileFilter libFiles = FileFilterUtils.and(FileFileFilter.FILE, orFilter);
        FileFilter filter = FileFilterUtils.or(DirectoryFileFilter.DIRECTORY, libFiles);
        org.apache.commons.io.FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory,
                filter);

    } catch (IOException e) {
        getLog().error("Could not copy native libraries: " + e.getMessage(), e);
        throw new MojoExecutionException("Could not copy native dependency.", e);
    }
}

From source file:net.sourceforge.subsonic.domain.MusicFile.java

/**
 * Returns all music files that are children of this music file.
 *
 * @param includeFiles       Whether files should be included in the result.
 * @param includeDirectories Whether directories should be included in the result.
 * @param sort               Whether to sort files in the same directory.   @return All children music files.
 * @throws IOException If an I/O error occurs.
 *//*from w  w  w.j a v  a2  s  .  c om*/
public List<MusicFile> getChildren(boolean includeFiles, boolean includeDirectories, boolean sort)
        throws IOException {

    FileFilter filter;
    if (includeFiles && includeDirectories) {
        filter = TrueFileFilter.INSTANCE;
    } else if (includeFiles) {
        filter = FileFileFilter.FILE;
    } else if (includeDirectories) {
        filter = DirectoryFileFilter.DIRECTORY;
    } else {
        filter = FalseFileFilter.INSTANCE;
    }

    File[] children = FileUtil.listFiles(file, filter);
    List<MusicFile> result = new ArrayList<MusicFile>(children.length);

    for (File child : children) {
        try {
            if (acceptMedia(child)) {
                result.add(createMusicFile(child));
            }
        } catch (SecurityException x) {
            LOG.warn("Failed to create MusicFile for " + child, x);
        }
    }

    if (sort) {
        Collections.sort(result, new MusicFileSorter());
    }

    return result;
}

From source file:net.sourceforge.subsonic.service.MusicFileService.java

/**
 * Returns a cover art image for the given directory.
 *//*from ww w .ja v a2s .  c  o m*/
public File getCoverArt(MusicFile dir) throws IOException {

    // Look in cache.
    CacheElement element = coverArtCache.get(dir.getPath());
    if (element != null) {

        // Check if cache is up-to-date.
        if (element.getCreated() > dir.getFile().lastModified()) {
            return (File) element.getValue();
        }
    }

    File coverArt = getBestCoverArt(FileUtil.listFiles(dir.getFile(), FileFileFilter.FILE));
    if (coverArt != null) {
        coverArtCache.put(dir.getPath(), coverArt);
    }
    return coverArt;
}