-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathLibDirBasedPathLocator.java
More file actions
49 lines (39 loc) · 1.18 KB
/
Copy pathLibDirBasedPathLocator.java
File metadata and controls
49 lines (39 loc) · 1.18 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
package datadog.nativeloader;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
/** LibDirBasedPathLocator locates libraries inside a list of library directories */
final class LibDirBasedPathLocator implements PathLocator {
private final File[] libDirs;
public LibDirBasedPathLocator(File... libDirs) {
this.libDirs = libDirs;
}
@Override
public URL locate(String component, String path) {
String fullPath = PathUtils.concatPath(component, path);
for (File libDir : this.libDirs) {
File libFile = new File(libDir, fullPath);
if (libFile.exists()) return toUrl(libFile);
}
return null;
}
@SuppressWarnings("deprecation")
private static final URL toUrl(File file) {
try {
return file.toURL();
} catch (MalformedURLException e) {
return null;
}
}
@Override
public int hashCode() {
return Arrays.hashCode(this.libDirs);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof LibDirBasedPathLocator)) return false;
LibDirBasedPathLocator that = (LibDirBasedPathLocator) obj;
return Arrays.equals(this.libDirs, that.libDirs);
}
}