Top Description Fields Constructors Methods
com.jogamp.common.net

public abstract Class AssetURLContext

extends Object
implements PiggybackURLContext
Class Inheritance
All Implemented Interfaces
com.jogamp.common.net.PiggybackURLContext
Imports
java.io.File, .FileNotFoundException, .IOException, java.net.MalformedURLException, .URISyntaxException, .URL, .URLConnection, .URLStreamHandler, com.jogamp.common.os.AndroidVersion, com.jogamp.common.util.IOUtil

See PiggybackURLConnection for description and examples.

Field Summary

Modifier and TypeField and Description
public static final String
asset_protocol

The asset URL protocol name asset

public static final String
asset_protocol_prefix

The asset URL protocol prefix asset:

public static final String
assets_folder

The optional asset folder name with ending slash assets/.

private static final boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static AssetURLContext
create(final ClassLoader cl)

public static AssetURLStreamHandler
public static URL
createURL(final String
resource path, with or w/o asset: prefix
path
,
final ClassLoader
the ClassLoader used to resolve the location, see getClassLoader().
cl
)

Create an asset URL, suitable even w/o the registered asset URLStreamHandler.

public static URL
createURL(final String
resource path, with or w/o asset: prefix
path
)

Create an asset URL, suitable only with the registered asset URLStreamHandler.

public abstract ClassLoader
getClassLoader()

Returns an asset aware ClassLoader.

public String
getImplementedProtocol()

Implements com.jogamp.common.net.PiggybackURLContext.getImplementedProtocol.

Returns the specific protocol, constant for this implementation.
public static URLStreamHandler
getRegisteredHandler()

Returns the asset handler previously set via registerHandler(ClassLoader), or null if none was set.

private static URLConnection
open(final URL url)

public static boolean

Returns:

true if successful, otherwise false
registerHandler
(final ClassLoader cl)

Registers the generic URLStreamHandlerFactory via GenericURLStreamHandlerFactory#register() and if successful sets the asset handler for the given ClassLoader cl.

public URLConnection
resolve(final String path)

Implements com.jogamp.common.net.PiggybackURLContext.resolve.

Resolving path to a URL sub protocol and return it's open URLConnection

This implementation attempts to resolve path in the following order:

  1. as a valid URL: new URL(path), use sub-protocol if asset URL
  2. via ClassLoader: getClassLoader().getResource(path), use sub-protocol if asset URL
  3. as a File: new File(path).toURI().toURL()
public static URLConnection
resolve(String path, final ClassLoader cl)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

asset_protocolback to summary
public static final String asset_protocol

The asset URL protocol name asset

asset_protocol_prefixback to summary
public static final String asset_protocol_prefix

The asset URL protocol prefix asset:

assets_folderback to summary
public static final String assets_folder

The optional asset folder name with ending slash assets/.

Note that the asset folder is not used on all platforms using the asset protocol and you should not rely on it, use AssetURLConnection#getEntryName().

DEBUGback to summary
private static final boolean DEBUG

Constructor Detail

AssetURLContextback to summary
public AssetURLContext()

Method Detail

createback to summary
public static AssetURLContext create(final ClassLoader cl)
createHandlerback to summary
public static AssetURLStreamHandler createHandler(final ClassLoader cl)
createURLback to summary
public static URL createURL(final String path, final ClassLoader cl) throws MalformedURLException

Create an asset URL, suitable even w/o the registered asset URLStreamHandler.

This is equivalent with:

  return new URL(null, path.startsWith("asset:") ? path : "asset:" + path, new AssetURLStreamHandler(cl));

Parameters
path:String

resource path, with or w/o asset: prefix

cl:ClassLoader

the ClassLoader used to resolve the location, see getClassLoader().

createURLback to summary
public static URL createURL(final String path) throws MalformedURLException

Create an asset URL, suitable only with the registered asset URLStreamHandler.

This is equivalent with:

  return new URL(path.startsWith("asset:") ? path : "asset:" + path);

Parameters
path:String

resource path, with or w/o asset: prefix

getClassLoaderback to summary
public abstract ClassLoader getClassLoader()

Returns an asset aware ClassLoader.

The ClassLoader is required to find the asset resource via it's URL findResource(String) implementation.

It's URL findResource(String) implementation shall return either an asset URL asset:sub-protocol or just the sub-protocol URL.

For example, on Android, we redirect all path request to assets/path.

getImplementedProtocolback to summary
public String getImplementedProtocol()

Implements com.jogamp.common.net.PiggybackURLContext.getImplementedProtocol.

Doc from com.jogamp.common.net.PiggybackURLContext.getImplementedProtocol.

Returns the specific protocol, constant for this implementation.

Annotations
@Override
getRegisteredHandlerback to summary
public static URLStreamHandler getRegisteredHandler()

Returns the asset handler previously set via registerHandler(ClassLoader), or null if none was set.

openback to summary
private static URLConnection open(final URL url)
registerHandlerback to summary
public static boolean registerHandler(final ClassLoader cl)

Registers the generic URLStreamHandlerFactory via GenericURLStreamHandlerFactory#register() and if successful sets the asset handler for the given ClassLoader cl.

Returns:boolean

true if successful, otherwise false

resolveback to summary
public URLConnection resolve(final String path) throws IOException

Implements com.jogamp.common.net.PiggybackURLContext.resolve.

Doc from com.jogamp.common.net.PiggybackURLContext.resolve.

Resolving path to a URL sub protocol and return it's open URLConnection

This implementation attempts to resolve path in the following order:

  1. as a valid URL: new URL(path), use sub-protocol if asset URL
  2. via ClassLoader: getClassLoader().getResource(path), use sub-protocol if asset URL
  3. as a File: new File(path).toURI().toURL()

In case of using the ClassLoader (2) and if running on Android, the assets_folder is being prepended to path if missing.

Annotations
@Override
resolveback to summary
public static URLConnection resolve(String path, final ClassLoader cl) throws IOException