View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.datamodel.niofs.utils;
20  
21  import java.io.IOException;
22  import java.nio.file.FileVisitResult;
23  import java.nio.file.FileVisitor;
24  import java.nio.file.attribute.BasicFileAttributes;
25  import java.util.ArrayList;
26  
27  public class MCRFileCollectingFileVisitor<T> implements FileVisitor<T> {
28  
29      private final ArrayList<T> paths;
30  
31      public MCRFileCollectingFileVisitor() {
32          paths = new ArrayList<>();
33      }
34  
35      public ArrayList<T> getPaths() {
36          return paths;
37      }
38  
39      @Override
40      public FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs) throws IOException {
41          return FileVisitResult.CONTINUE;
42      }
43  
44      @Override
45      public FileVisitResult visitFile(T file, BasicFileAttributes attrs) throws IOException {
46          paths.add(file);
47          return FileVisitResult.CONTINUE;
48      }
49  
50      @Override
51      public FileVisitResult visitFileFailed(T file, IOException exc) throws IOException {
52          return FileVisitResult.TERMINATE;
53      }
54  
55      @Override
56      public FileVisitResult postVisitDirectory(T dir, IOException exc) throws IOException {
57          return FileVisitResult.CONTINUE;
58      }
59  }