aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/asset/AssetManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ru/olamedia/asset/AssetManager.java')
-rw-r--r--src/ru/olamedia/asset/AssetManager.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/ru/olamedia/asset/AssetManager.java b/src/ru/olamedia/asset/AssetManager.java
new file mode 100644
index 0000000..d1de11b
--- /dev/null
+++ b/src/ru/olamedia/asset/AssetManager.java
@@ -0,0 +1,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));
+ }
+}