Package com.jogamp.common.net
Class AssetURLContext
java.lang.Object
com.jogamp.common.net.AssetURLContext
- All Implemented Interfaces:
PiggybackURLContext
See
PiggybackURLConnection for description and examples.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AssetURLContextcreate(ClassLoader cl) static AssetURLStreamHandlerstatic URLCreate an asset URL, suitable only with the registered asset URLStreamHandler.static URLcreateURL(String path, ClassLoader cl) Create an asset URL, suitable even w/o the registered asset URLStreamHandler.abstract ClassLoaderReturns an asset aware ClassLoader.Returns the specific protocol, constant for this implementation.static URLStreamHandlerReturns the asset handler previously set viaregisterHandler(ClassLoader), or null if none was set.static booleanRegisters the generic URLStreamHandlerFactory viaGenericURLStreamHandlerFactory.register()and if successful sets the assethandlerfor the given ClassLoadercl.Resolving path to a URL sub protocol and return it's open URLConnectionstatic URLConnectionresolve(String path, ClassLoader cl)
-
Field Details
-
asset_protocol
The asset URL protocol nameasset- See Also:
-
asset_protocol_prefix
The asset URL protocol prefixasset:- See Also:
-
assets_folder
The optional asset folder name with ending slashassets/.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().- See Also:
-
-
Constructor Details
-
AssetURLContext
public AssetURLContext()
-
-
Method Details
-
create
-
createHandler
-
createURL
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- resource path, with or w/oasset:prefixcl- the ClassLoader used to resolve the location, seegetClassLoader().- Returns:
- Throws:
MalformedURLException
-
createURL
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- resource path, with or w/oasset:prefix- Returns:
- Throws:
MalformedURLException
-
getRegisteredHandler
Returns the asset handler previously set viaregisterHandler(ClassLoader), or null if none was set. -
registerHandler
Registers the generic URLStreamHandlerFactory viaGenericURLStreamHandlerFactory.register()and if successful sets the assethandlerfor the given ClassLoadercl.- Returns:
- true if successful, otherwise false
-
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 URLasset:sub-protocolor just the sub-protocol URL.For example, on Android, we redirect all
pathrequest to assets/path. -
getImplementedProtocol
Description copied from interface:PiggybackURLContextReturns the specific protocol, constant for this implementation.- Specified by:
getImplementedProtocolin interfacePiggybackURLContext
-
resolve
Resolving path to a URL sub protocol and return it's open URLConnectionThis implementation attempts to resolve
pathin the following order:- as a valid URL:
new URL(path), use sub-protocol if asset URL - via ClassLoader:
getClassLoader().getResource(path), use sub-protocol if asset URL - as a File:
new File(path).toURI().toURL()
In case of using the ClassLoader (2) and if running on Android, the
assets_folderis being prepended topathif missing.- Specified by:
resolvein interfacePiggybackURLContext- Throws:
IOException
- as a valid URL:
-
resolve
- Throws:
IOException
-