forked from BynBang/OpenPrestige
fixes
This commit is contained in:
1 parent
83aea53e57
commit
aa4f6b6ddc
842 files changed
+47284
-91563
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package dev.zprestige.prestige.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ClasspathResource {
|
||||
private final String path;
|
||||
private static final String NOT_FOUND_MESSAGE = "resource not found: ";
|
||||
|
||||
private ClasspathResource(String resourcePath) {
|
||||
this.path = resourcePath;
|
||||
}
|
||||
|
||||
public static ClasspathResource of(String resourcePath) {
|
||||
return new ClasspathResource(resourcePath.startsWith("/") ? resourcePath.substring(1) : resourcePath);
|
||||
}
|
||||
|
||||
public InputStream openStream() {
|
||||
InputStream stream = ClasspathResource.class.getClassLoader().getResourceAsStream(this.path);
|
||||
if (stream == null) {
|
||||
throw new IllegalArgumentException(NOT_FOUND_MESSAGE + this);
|
||||
} else {
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
} else {
|
||||
return !(other instanceof ClasspathResource resource) ? false : this.path.equals(resource.path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.path);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user