Example usage for org.apache.commons.io.comparator NameFileComparator NameFileComparator

List of usage examples for org.apache.commons.io.comparator NameFileComparator NameFileComparator

Introduction

In this page you can find the example usage for org.apache.commons.io.comparator NameFileComparator NameFileComparator.

Prototype

public NameFileComparator(IOCase caseSensitivity) 

Source Link

Document

Construct a file name comparator instance with the specified case-sensitivity.

Usage

From source file:com.stratelia.webactiv.util.fileFolder.FileFolderManager.java

/**
 * Returns all the files (and only the files, no directory) inside the given directory.
 * @param chemin/*w ww  .  j a  v a2  s.  com*/
 * @return
 * @throws UtilException
 */
public static Collection<File> getAllFile(String chemin) throws UtilException {
    List<File> resultat = new ArrayList<File>();
    File directory = new File(chemin);
    if (directory.isDirectory()) {
        resultat = new ArrayList<File>(FileUtils.listFiles(directory, null, false));
        Collections.sort(resultat, new NameFileComparator(IOCase.INSENSITIVE));
    } else {
        SilverTrace.error("util", "FileFolderManager.getAllFile", "util.EX_NO_CHEMIN_REPOS", chemin);
        throw new UtilException("FileFolderManager.getAllFile", "util.EX_NO_CHEMIN_REPOS", chemin);
    }
    return resultat;
}

From source file:org.silverpeas.core.util.file.FileFolderManager.java

/**
 * Returns all the files (and only the files, not the directories) that are directly inside the
 * given directory. Throws an {@link UtilException} if the
 * specified path doesn't denote a directory or if the listing of all of its files fails.
 * @param path the path of the directory
 * @return a collection of files// www. j a  v  a 2 s. co  m
 */
public static Collection<File> getAllFile(final String path) {
    final List<File> result;
    final Path directory = Paths.get(path);
    if (directory.toFile().isDirectory()) {
        try (final Stream<Path> folders = Files.list(directory)) {
            result = folders.filter(p -> p.toFile().isFile()).map(Path::toFile)
                    .sorted(new NameFileComparator(IOCase.INSENSITIVE)).collect(Collectors.toList());
        } catch (IOException e) {
            throw new UtilException(e);
        }
    } else {
        throw new UtilException(path + NOT_A_DIRECTORY_MSG);
    }
    return result;
}