1package com.jogamp.common.net;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.net.MalformedURLException;
7import java.net.URISyntaxException;
9import java.net.URLConnection;
10import java.net.URLStreamHandler;
12import com.jogamp.common.os.AndroidVersion;
13import com.jogamp.common.util.IOUtil;
62 public static URL
createURL(
final String path,
final ClassLoader cl)
throws MalformedURLException {
78 public static URL
createURL(
final String path)
throws MalformedURLException {
144 public URLConnection
resolve(
final String path)
throws IOException {
148 public static URLConnection
resolve(String path,
final ClassLoader cl)
throws IOException {
150 URLConnection conn =
null;
154 System.err.println(
"AssetURLContext.resolve: <"+path+
">");
158 }
catch (
final URISyntaxException uriEx) {
159 throw new IOException(uriEx);
166 type =
null != conn ? 1 : -1;
167 }
catch(
final MalformedURLException e1) {
if(DEBUG) { System.err.println(
"FAIL(1): "+e1.getMessage()); } }
169 if(
null == conn &&
null != cl) {
172 while(cpath.startsWith(
"/")) {
173 cpath = cpath.substring(1);
178 url = cl.getResource(cpath);
180 type =
null != conn ? 2 : -1;
186 final File file =
new File(path);
190 type =
null != conn ? 3 : -1;
192 }
catch (
final Throwable e) {
if(DEBUG) { System.err.println(
"FAIL(3): "+e.getMessage()); } }
196 System.err.println(
"AssetURLContext.resolve: type "+type+
": url <"+url+
">, conn <"+conn+
">, connURL <"+(
null!=conn?conn.getURL():
null)+
">");
199 throw new FileNotFoundException(
"Could not look-up: "+path+
" as URL, w/ ClassLoader or as File");
204 private static URLConnection open(
final URL url) {
209 final URLConnection c = url.openConnection();
212 }
catch (
final IOException ioe) {
if(DEBUG) { System.err.println(
"FAIL(2): "+ioe.getMessage()); } }
See PiggybackURLConnection for description and examples.
static URLConnection resolve(String path, final ClassLoader cl)
static final String assets_folder
The optional asset folder name with ending slash assets/.
static AssetURLContext create(final ClassLoader cl)
abstract ClassLoader getClassLoader()
Returns an asset aware ClassLoader.
static boolean registerHandler(final ClassLoader cl)
Registers the generic URLStreamHandlerFactory via GenericURLStreamHandlerFactory#register() and if su...
static URLStreamHandler getRegisteredHandler()
Returns the asset handler previously set via registerHandler(ClassLoader), or null if none was set.
static final String asset_protocol_prefix
The asset URL protocol prefix asset:
static URL createURL(final String path)
Create an asset URL, suitable only with the registered asset URLStreamHandler.
static URL createURL(final String path, final ClassLoader cl)
Create an asset URL, suitable even w/o the registered asset URLStreamHandler.
URLConnection resolve(final String path)
Resolving path to a URL sub protocol and return it's open URLConnection.
static AssetURLStreamHandler createHandler(final ClassLoader cl)
static final String asset_protocol
The asset URL protocol name asset
String getImplementedProtocol()
Returns the specific protocol, constant for this implementation.
URLStreamHandler to handle the asset protocol.
synchronized final URLStreamHandler getHandler(final String protocol)
Returns the protocol handler previously set via setHandler(String, URLStreamHandler),...
static synchronized GenericURLStreamHandlerFactory register()
Returns the singleton instance of the registered GenericURLStreamHandlerFactory or null if registrati...
synchronized final URLStreamHandler setHandler(final String protocol, final URLStreamHandler handler)
Sets the handler for protocol.
This class implements an immutable Uri as defined by RFC 2396.
static Uri valueOf(final File file)
Creates a new Uri instance using the given File instance.
final java.net.URL toURL()
Returns a new URL instance using the encoded input string, new URL(uri.input), i.e.
static final boolean isAvailable
static String cleanPathString(String path)
static final boolean DEBUG
See PiggybackURLConnection for description and examples.