View Javadoc
1   /**************************************************************************
2    *
3    * Copyright (c) 2016-2020 Yawg project contributors.
4    *
5    **************************************************************************/
6   
7   package com.varmateo.yawg.core;
8   
9   import java.io.IOException;
10  import java.nio.file.Files;
11  import java.nio.file.Path;
12  import java.util.function.Predicate;
13  import java.util.stream.Stream;
14  
15  import io.vavr.collection.List;
16  import io.vavr.collection.Seq;
17  
18  
19  /**
20   * Used for obtaining the list of entries in a given directory that
21   * should be baked.
22   */
23  /* default */ final class DirEntryScanner {
24  
25  
26      private final Predicate<Path> _entryFilter;
27  
28  
29      /**
30       *
31       */
32      /* default */ DirEntryScanner(final DirBakeOptions options) {
33  
34          _entryFilter = new DirEntryChecker(options).asPathPredicate();
35      }
36  
37  
38      /**
39       *
40       */
41      public Seq<Path> getDirEntries(final Path dirPath)
42              throws IOException {
43  
44          try ( Stream<Path> entries = Files.list(dirPath) ) {
45              final Stream<Path> stream =
46                      entries
47                      .filter(_entryFilter)
48                      .sorted();
49              return List.ofAll(() -> stream.iterator());
50          }
51      }
52  
53  
54  }