File: TrackFileFinder.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (48 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package tim.prune.function.filesleuth;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;

import tim.prune.function.filesleuth.data.FileTypeBlacklist;
import tim.prune.function.filesleuth.data.TrackFileList;

/**
 * Responsible for searching the file tree and building up a TrackFileList
 */
public class TrackFileFinder
{
	private final TrackFileList _tracks;
	private final File _startDir;
	private final boolean _subdirectories;


	public TrackFileFinder(TrackFileList inList, File inStartDir, boolean inSubdirectories)
	{
		_tracks = inList;
		_startDir = inStartDir;
		_subdirectories = inSubdirectories;
	}

	public void begin() {
		new Thread(this::run).start();
	}

	/** Perform recursive file search in separate thread */
	private void run()
	{
		final int depth = _subdirectories ? Integer.MAX_VALUE : 1;
		try {
			Files.walk(Path.of(_startDir.getAbsolutePath()), depth, FileVisitOption.FOLLOW_LINKS)
					.filter(Files::isRegularFile)
					.filter(FileTypeBlacklist::isAllowed)
					.forEach(_tracks::foundFile);
		}
		catch (IOException | java.io.UncheckedIOException ioe) {
			System.err.println("Error: " + ioe.getMessage());
		}
		_tracks.setListComplete();
	}
}