GlueGen
v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java (public API).
AssetURLConnection.java
Go to the documentation of this file.
1
package
com.jogamp.common.net;
2
3
import
java.io.IOException;
4
import
java.net.JarURLConnection;
5
import
java.net.URL;
6
7
/**
8
* See base class {@link PiggybackURLConnection} for motivation.
9
*
10
* <p>
11
* <i>asset</i> resource location protocol connection.
12
* </p>
13
*
14
* <p>
15
* See {@link AssetURLContext#resolve(String)} how resources are being resolved.
16
* </p>
17
*
18
* <h3>Example:</h3>
19
*
20
* Assuming the plain <i>asset entry</i> <b><code>test/lala.txt</code></b> is being resolved by
21
* a class <code>test.LaLaTest</code>, ie. using the <i>asset aware</i> ClassLoader,
22
* one would use the following <i>asset</i> aware filesystem layout:
23
*
24
* <pre>
25
* test/LaLaTest.class
26
* assets/test/lala.txt
27
* </pre>
28
*
29
* The above maybe on a plain filesystem, or within a JAR or an APK file,
30
* e.g. <code>jogamp.test.apk</code>.
31
*
32
* The above would result in the following possible URLs
33
* reflecting the plain and resolved state of the <i>asset URL</i>:
34
* <pre>
35
* 0 Entry test/lala.txt
36
* 1 Plain asset:test/lala.txt
37
* 2 Resolved asset:jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt
38
* </pre>
39
*
40
* <p>
41
* The sub protocol URL of the resolved <i>asset</i>
42
* <pre>
43
* 3 Sub-URL jar:file:/data/app/jogamp.test.apk!/assets/test/lala.txt
44
* </pre>
45
* can be retrieved using {@link #getSubProtocol()}.
46
* </p>
47
*
48
* In all above cases, the <i>asset entry</i> is <b><code>test/lala.txt</code></b>,
49
* which can be retrieved via {@link #getEntryName()}.
50
*
51
* <p>
52
* <h3>General Implementation Notes:</h3>
53
* An <i>asset</i> URL is resolved using {@link AssetURLContext#getClassLoader()}.{@link ClassLoader#getResource(String) getResource(String)},
54
* hence the only requirement for an implementation is to have an <i>asset</i> aware ClassLoader
55
* as described in {@link AssetURLContext#getClassLoader()}.
56
* </p>
57
* <p>
58
* <h3>Warning:</h3>
59
* Since the <i>asset</i> protocol is currently not being implemented
60
* on all platform with an appropriate ClassLoader, a user shall not create the <i>asset</i> URL manually.<br>
61
* </p>
62
*
63
* <h3>Android Implementation Notes:</h3>
64
* <p>
65
* The Android ClassLoader {@link jogamp.android.launcher.AssetDexClassLoader}
66
* resolves the resource as an <i>asset</i> URL in it's {@link ClassLoader#findResource(String)} implementation.</p>
67
* <p>
68
* Currently we attach our <i>asset</i> {@link java.net.URLStreamHandlerFactory}
69
* to allow {@link java.net.URL} to handle <i>asset</i> URLs via our <i>asset</i> {@link java.net.URLStreamHandler} implementation.
70
* </p>
71
*/
72
public
class
AssetURLConnection
extends
PiggybackURLConnection
<AssetURLContext> {
73
74
public
AssetURLConnection
(
final
URL url,
final
AssetURLContext
implHelper) {
75
super(url, implHelper);
76
}
77
78
@Override
79
public
String
getEntryName
() throws IOException {
80
if
(!connected) {
81
throw
new
IOException(
"not connected"
);
82
}
83
84
final
String urlPath ;
85
if
(
subConn
instanceof JarURLConnection) {
86
urlPath = ((JarURLConnection)
subConn
).getEntryName();
87
}
else
{
88
urlPath =
subConn
.getURL().getPath();
89
}
90
91
if
(urlPath.startsWith(
AssetURLContext
.
assets_folder
)) {
92
return
urlPath.substring(
AssetURLContext
.
assets_folder
.length());
93
}
else
{
94
return
urlPath;
95
}
96
}
97
98
}
com.jogamp.common.net.AssetURLConnection
See base class PiggybackURLConnection for motivation.
Definition:
AssetURLConnection.java:72
com.jogamp.common.net.AssetURLConnection.AssetURLConnection
AssetURLConnection(final URL url, final AssetURLContext implHelper)
Definition:
AssetURLConnection.java:74
com.jogamp.common.net.AssetURLConnection.getEntryName
String getEntryName()
Definition:
AssetURLConnection.java:79
com.jogamp.common.net.AssetURLContext
See PiggybackURLConnection for description and examples.
Definition:
AssetURLContext.java:18
com.jogamp.common.net.AssetURLContext.assets_folder
static final String assets_folder
The optional asset folder name with ending slash assets/.
Definition:
AssetURLContext.java:34
com.jogamp.common.net.PiggybackURLConnection
Generic resource location protocol connection, using another sub-protocol as the vehicle for a piggyb...
Definition:
PiggybackURLConnection.java:18
com.jogamp.common.net.PiggybackURLConnection< AssetURLContext >::subConn
URLConnection subConn
Definition:
PiggybackURLConnection.java:20
src
java
com
jogamp
common
net
AssetURLConnection.java
Generated by
1.9.4