Java Path File List nio listSteps(Path scenarioDirectory)

Here you can find the source of listSteps(Path scenarioDirectory)

Description

Lists all scenario steps within the given directory path.

License

Open Source License

Parameter

Parameter Description
scenarioDirectory the directory to scan

Return

all steps sorted in lexicographical order

Declaration

public static Iterable<Path> listSteps(Path scenarioDirectory) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileFilter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import static java.util.Arrays.sort;

public class Main {
    private static final FileFilter STEP_FILTER = new FileFilter() {
        @Override/*from  ww  w.ja  va2  s . co  m*/
        public boolean accept(File pathname) {
            return pathname.isFile() && pathname.canRead() && pathname.getName().matches("\\d+_.*");
        }
    };

    /**
     * Lists all scenario steps within the given directory path.
     *
     * @param scenarioDirectory the directory to scan
     * @return all steps sorted in lexicographical order
     */
    public static Iterable<Path> listSteps(Path scenarioDirectory) {
        if (!Files.isDirectory(scenarioDirectory)) {
            throw new IllegalArgumentException(
                    String.format("Path '%s' is not a directory.", scenarioDirectory.toAbsolutePath()));
        }
        File[] list = scenarioDirectory.toFile().listFiles(STEP_FILTER);
        if (list == null || list.length == 0) {
            throw new IllegalStateException(
                    String.format("No test steps found in directory: '%s'", scenarioDirectory.toAbsolutePath()));
        }
        sort(list);
        return toPaths(list);
    }

    /**
     * Converts the given files to a sequence of paths.
     *
     * @param files the files
     * @return the paths
     */
    private static Iterable<Path> toPaths(File... files) {
        List<Path> paths = new ArrayList<>(files.length);
        for (File file : files) {
            paths.add(file.toPath());
        }
        return paths;
    }
}

Related

  1. listFiles(Path path, List preorderList)
  2. listFiles(Path path, String glob)
  3. listFilesRecursively(Path dir, final DirectoryStream.Filter filter, final boolean recursive)
  4. listFoldersInFolder2(String path)
  5. listOfWords(String filePath)
  6. loadDataFilesList(String prefix, Path bwcIndicesPath)
  7. loadTrainingData(Path path, List input, List output, int outputCount)
  8. mergeFiles(List files, Path mergedFile)
  9. mergeInto(List parts, OutputStream out)