From 791a2749886f02ec7b8db25bf8862e8269b96da5 Mon Sep 17 00:00:00 2001
From: Harvey Harrison
* asset resource location protocol connection.
*
* See {@link AssetURLContext#resolve(String)} how resources are being resolved.
*
- * The sub protocol URL of the resolved asset
+ * The sub protocol URL of the resolved asset
* Example:
- *
+ *
* Assuming the plain asset entry test/lala.txt
is being resolved by
* a class test.LaLaTest
, ie. using the asset aware ClassLoader,
- * one would use the following asset aware filesystem layout:
- *
+ * one would use the following asset aware filesystem layout:
+ *
*
* test/LaLaTest.class
* assets/test/lala.txt
*
- *
- * The above maybe on a plain filesystem, or within a JAR or an APK file,
+ *
+ * The above maybe on a plain filesystem, or within a JAR or an APK file,
* e.g. jogamp.test.apk
.
- *
+ *
* The above would result in the following possible URLs
- * reflecting the plain and resolved state of the asset URL:
+ * reflecting the plain and resolved state of the asset URL:
*
* 0 Entry test/lala.txt
* 1 Plain asset:test/lala.txt
@@ -38,16 +38,16 @@ import java.net.URL;
*
*
*
* 3 Sub-URL jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt
*
* can be retrieved using {@link #getSubProtocol()}.
*
test/lala.txt
,
* which can be retrieved via {@link #getEntryName()}.
- *
+ *
* *
*
- * The Android ClassLoader {@link jogamp.android.launcher.AssetDexClassLoader} + * The Android ClassLoader {@link jogamp.android.launcher.AssetDexClassLoader} * resolves the resource as an asset URL in it's {@link ClassLoader#findResource(String)} implementation.
*- * Currently we attach our asset {@link java.net.URLStreamHandlerFactory} + * Currently we attach our asset {@link java.net.URLStreamHandlerFactory} * to allow {@link java.net.URL} to handle asset URLs via our asset {@link java.net.URLStreamHandler} implementation. *
*/ public class AssetURLConnection extends PiggybackURLConnectionasset
*/
public static final String asset_protocol = "asset";
-
+
/** The asset URL protocol prefix asset:
*/
public static final String asset_protocol_prefix = "asset:";
-
- /**
+
+ /**
* The optional asset folder name with ending slash assets/
.
* * Note that the asset folder is not used on all platforms using the asset protocol @@ -41,11 +41,11 @@ public abstract class AssetURLContext implements PiggybackURLContext { } }; } - + public static AssetURLStreamHandler createHandler(final ClassLoader cl) { return new AssetURLStreamHandler(create(cl)); } - + /** * Create an asset URL, suitable even w/o the registered asset URLStreamHandler. *
@@ -62,7 +62,7 @@ public abstract class AssetURLContext implements PiggybackURLContext { public static URL createURL(String path, ClassLoader cl) throws MalformedURLException { return new URL(null, path.startsWith(asset_protocol_prefix) ? path : asset_protocol_prefix + path, createHandler(cl)); } - + /** * Create an asset URL, suitable only with the registered asset URLStreamHandler. *
@@ -78,20 +78,20 @@ public abstract class AssetURLContext implements PiggybackURLContext {
public static URL createURL(String path) throws MalformedURLException {
return new URL(path.startsWith(asset_protocol_prefix) ? path : asset_protocol_prefix + path);
}
-
+
/**
- * Returns the asset handler previously set via {@link #registerHandler(ClassLoader)},
+ * Returns the asset handler previously set via {@link #registerHandler(ClassLoader)},
* or null if none was set.
*/
public static URLStreamHandler getRegisteredHandler() {
final GenericURLStreamHandlerFactory f = GenericURLStreamHandlerFactory.register();
return ( null != f ) ? f.getHandler(asset_protocol) : null;
}
-
+
/**
- * Registers the generic URLStreamHandlerFactory via {@link GenericURLStreamHandlerFactory#register()}
+ * Registers the generic URLStreamHandlerFactory via {@link GenericURLStreamHandlerFactory#register()}
* and if successful sets the asset handler
for the given ClassLoader cl
.
- *
+ *
* @return true if successful, otherwise false
*/
public static boolean registerHandler(ClassLoader cl) {
@@ -103,11 +103,11 @@ public abstract class AssetURLContext implements PiggybackURLContext {
return false;
}
}
-
- /**
+
+ /**
* Returns an asset aware ClassLoader.
*
- * The ClassLoader is required to find the asset resource
+ * The ClassLoader is required to find the asset resource
* via it's URL findResource(String)
implementation.
*
@@ -123,33 +123,33 @@ public abstract class AssetURLContext implements PiggybackURLContext { @Override public String getImplementedProtocol() { return asset_protocol; - } - + } + /** * {@inheritDoc} - *
+ *
* This implementation attempts to resolve path
in the following order:
*
new URL(path)
, use sub-protocol if asset URLnew File(path).toURI().toURL()
*
* In case of using the ClassLoader (2) and if running on Android,
* the {@link #assets_folder} is being prepended to path
if missing.
- *
* This is the asset URLStreamHandler variation - * for manual use. + * for manual use. *
** It requires passing a valid {@link AssetURLContext} * for construction, hence it's not suitable for the pkg factory model. *
*/ -public class AssetURLStreamHandler extends URLStreamHandler { +public class AssetURLStreamHandler extends URLStreamHandler { AssetURLContext ctx; - + public AssetURLStreamHandler(AssetURLContext ctx) { this.ctx = ctx; } - + @Override protected URLConnection openConnection(URL u) throws IOException { final AssetURLConnection c = new AssetURLConnection(u, ctx); c.connect(); return c; } - - + + } diff --git a/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java b/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java index 79d7f71..4ec3f19 100644 --- a/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java +++ b/src/java/com/jogamp/common/net/GenericURLStreamHandlerFactory.java @@ -10,30 +10,30 @@ import java.util.Map; public class GenericURLStreamHandlerFactory implements URLStreamHandlerFactory { private static GenericURLStreamHandlerFactory factory = null; - + private final Maphandler
for protocol
.
- *
+ *
* @return the previous set handler
, or null if none was set.
*/
public synchronized final URLStreamHandler setHandler(String protocol, URLStreamHandler handler) {
return protocolHandlers.put(protocol, handler);
}
-
+
/**
- * Returns the protocol
handler previously set via {@link #setHandler(String, URLStreamHandler)},
+ * Returns the protocol
handler previously set via {@link #setHandler(String, URLStreamHandler)},
* or null if none was set.
*/
public synchronized final URLStreamHandler getHandler(String protocol) {
return protocolHandlers.get(protocol);
}
-
+
@Override
public synchronized final URLStreamHandler createURLStreamHandler(String protocol) {
return getHandler(protocol);
diff --git a/src/java/com/jogamp/common/net/PiggybackURLConnection.java b/src/java/com/jogamp/common/net/PiggybackURLConnection.java
index 39f1637..3b774e8 100644
--- a/src/java/com/jogamp/common/net/PiggybackURLConnection.java
+++ b/src/java/com/jogamp/common/net/PiggybackURLConnection.java
@@ -6,10 +6,10 @@ import java.net.URL;
import java.net.URLConnection;
/**
- * Generic resource location protocol connection,
+ * Generic resource location protocol connection,
* using another sub-protocol as the vehicle for a piggyback protocol.
* - * The details of the sub-protocol can be queried using {@link #getSubProtocol()}. + * The details of the sub-protocol can be queried using {@link #getSubProtocol()}. *
** See example in {@link AssetURLConnection}. @@ -19,7 +19,7 @@ public abstract class PiggybackURLConnection exte protected URL subUrl; protected URLConnection subConn; protected I context; - + /** * @param url the specific URL for this instance * @param context the piggyback context, defining state independent code and constants @@ -34,18 +34,18 @@ public abstract class PiggybackURLConnection exte * Resolves the URL via {@link PiggybackURLContext#resolve(String)}, * see {@link AssetURLContext#resolve(String)} for an example. *
- * + * * {@inheritDoc} */ @Override public synchronized void connect() throws IOException { if(!connected) { - subConn = context.resolve(url.getPath()); - subUrl = subConn.getURL(); + subConn = context.resolve(url.getPath()); + subUrl = subConn.getURL(); connected = true; } } - + @Override public InputStream getInputStream() throws IOException { if(!connected) { @@ -53,26 +53,26 @@ public abstract class PiggybackURLConnection exte } return subConn.getInputStream(); } - - /** + + /** * Returns the entry name of the asset. ** Plain asset:test/lala.txt * Resolved asset:jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt * Result test/lala.txt - *+ * * @throws IOException is not connected **/ public abstract String getEntryName() throws IOException; - - /** + + /** * Returns the resolved sub protocol of the asset or null, ie: *
* Plain asset:test/lala.txt * Resolved asset:jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt * Result jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt *- * + * * @throws IOException is not connected */ public URL getSubProtocol() throws IOException { diff --git a/src/java/com/jogamp/common/net/PiggybackURLContext.java b/src/java/com/jogamp/common/net/PiggybackURLContext.java index 2cb48b5..9e3db69 100644 --- a/src/java/com/jogamp/common/net/PiggybackURLContext.java +++ b/src/java/com/jogamp/common/net/PiggybackURLContext.java @@ -8,11 +8,11 @@ import java.net.URLConnection; */ public interface PiggybackURLContext { - /** Returns the specific protocol, constant for this implementation. */ + /** Returns the specific protocol, constant for this implementation. */ public String getImplementedProtocol(); - - /** - * Resolving path to a URL sub protocol and return it's open URLConnection + + /** + * Resolving path to a URL sub protocol and return it's open URLConnection **/ - public URLConnection resolve(String path) throws IOException; + public URLConnection resolve(String path) throws IOException; } diff --git a/src/java/com/jogamp/common/net/asset/Handler.java b/src/java/com/jogamp/common/net/asset/Handler.java index 1063797..d622221 100644 --- a/src/java/com/jogamp/common/net/asset/Handler.java +++ b/src/java/com/jogamp/common/net/asset/Handler.java @@ -8,12 +8,12 @@ import java.net.URLStreamHandler; import com.jogamp.common.net.AssetURLConnection; import com.jogamp.common.net.AssetURLContext; -/** +/** * {@link URLStreamHandler} to handle the asset protocol. - * + * *
* This is the asset URLStreamHandler variation - * using this class ClassLoader for the pkg factory model. + * using this class ClassLoader for the pkg factory model. *
*/ public class Handler extends URLStreamHandler { @@ -23,16 +23,16 @@ public class Handler extends URLStreamHandler { return Handler.class.getClassLoader(); } }; - + public Handler() { super(); } - + @Override protected URLConnection openConnection(URL u) throws IOException { final AssetURLConnection c = new AssetURLConnection(u, localCL); c.connect(); return c; } - + } -- cgit v1.2.3