FilesTraversal.java
1.46 KB
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
49
50
51
52
53
54
55
56
57
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.granite.infocollector.impl;
import com.adobe.granite.infocollector.impl.FilesHandler;
import java.io.File;
import java.io.IOException;
import java.net.URI;
final class FilesTraversal {
private final File home;
public FilesTraversal(String slingHomePath) {
this.home = new File(slingHomePath);
}
public void traverse(FilesHandler handler) throws IOException {
this.traverse(this.home, handler);
}
public void traverse(String fileName, FilesHandler handler) throws IOException {
this.traverse(new File(this.home, fileName), handler);
}
private void traverse(File file, FilesHandler handler) throws IOException {
if (file == null || !file.exists()) {
return;
}
if (file.isDirectory()) {
handler.beginDirectory(file);
for (File child : file.listFiles()) {
this.traverse(child, handler);
}
handler.endDirectory(file);
return;
}
handler.onFile(file);
}
public File getHome() {
return this.home;
}
public File getFile(String name) {
return new File(this.home, name);
}
public String relativize(File file) {
String name = this.home.toURI().relativize(file.toURI()).getPath();
if (file.isDirectory()) {
name = name.endsWith("/") ? name : name + '/';
}
return name;
}
}