blob: d1de11bf86cd3a8304a176ed32fee224d6380779 (
plain)
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
|
package ru.olamedia.asset;
import java.net.URL;
public class AssetManager {
public static URL getBaseURL() {
return AssetManager.class.getResource(AssetManager.class.getSimpleName() + ".class");
}
public boolean inJar() {
// file:jar:c:/path/to/jar/somejar.jar!
return getBaseURL().toString().startsWith("file:jar:");
// return getBaseURL().toString().indexOf(".jar!") > 0;
}
public static URL getURL(String path) throws AssetNotFoundException {
URL url = AssetManager.class.getClassLoader().getResource(path);
if (null == url) {
throw new AssetNotFoundException(path);
}
return url;
}
public static Asset getAsset(String path) throws AssetNotFoundException {
return new Asset(getURL(path));
}
}
|