jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
org.jau.net.AssetURLContext Class Referenceabstract

See PiggybackURLConnection for description and examples. More...

Inheritance diagram for org.jau.net.AssetURLContext:
Collaboration diagram for org.jau.net.AssetURLContext:

Public Member Functions

abstract ClassLoader getClassLoader ()
 Returns an asset aware ClassLoader. More...
 
String getImplementedProtocol ()
 Returns the specific protocol, constant for this implementation. More...
 
URLConnection resolve (final String path) throws IOException
 Resolving path to a URL sub protocol and return it's open URLConnection. More...
 
String getImplementedProtocol ()
 Returns the specific protocol, constant for this implementation. More...
 
URLConnection resolve (String path) throws IOException
 Resolving path to a URL sub protocol and return it's open URLConnection. More...
 

Static Public Member Functions

static AssetURLContext create (final ClassLoader cl)
 
static AssetURLStreamHandler createHandler (final ClassLoader cl)
 
static URL createURL (final String path, final ClassLoader cl) throws MalformedURLException
 Create an asset URL, suitable even w/o the registered asset URLStreamHandler. More...
 
static URL createURL (final String path) throws MalformedURLException
 Create an asset URL, suitable only with the registered asset URLStreamHandler. More...
 
static URLStreamHandler getRegisteredHandler ()
 Returns the asset handler previously set via registerHandler(ClassLoader), or null if none was set. More...
 
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. More...
 
static URLConnection resolve (String path, final ClassLoader cl) throws IOException
 
static URLConnection getResource (final String resourcePath, final ClassLoader cl)
 Locating a resource using the ClassLoader's facilities. More...
 

Static Public Attributes

static final String asset_protocol = "asset"
 The asset URL protocol name asset More...
 
static final String asset_protocol_prefix = "asset:"
 The asset URL protocol prefix asset: More...
 
static final String assets_folder = "assets/"
 The optional asset folder name with ending slash assets/. More...
 

Detailed Description

See PiggybackURLConnection for description and examples.

Definition at line 44 of file AssetURLContext.java.

Member Function Documentation

◆ create()

static AssetURLContext org.jau.net.AssetURLContext.create ( final ClassLoader  cl)
static

Definition at line 62 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createHandler()

static AssetURLStreamHandler org.jau.net.AssetURLContext.createHandler ( final ClassLoader  cl)
static

Definition at line 71 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createURL() [1/2]

static URL org.jau.net.AssetURLContext.createURL ( final String  path) throws MalformedURLException
static

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
pathresource path, with or w/o asset: prefix
Returns
Exceptions
MalformedURLException

Definition at line 104 of file AssetURLContext.java.

◆ createURL() [2/2]

static URL org.jau.net.AssetURLContext.createURL ( final String  path,
final ClassLoader  cl 
) throws MalformedURLException
static

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
pathresource path, with or w/o asset: prefix
clthe ClassLoader used to resolve the location, see getClassLoader().
Returns
Exceptions
MalformedURLException

Definition at line 88 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getClassLoader()

abstract ClassLoader org.jau.net.AssetURLContext.getClassLoader ( )
abstract

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.

Here is the caller graph for this function:

◆ getImplementedProtocol()

String org.jau.net.AssetURLContext.getImplementedProtocol ( )

Returns the specific protocol, constant for this implementation.

Implements org.jau.net.PiggybackURLContext.

Definition at line 150 of file AssetURLContext.java.

◆ getRegisteredHandler()

static URLStreamHandler org.jau.net.AssetURLContext.getRegisteredHandler ( )
static

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

Definition at line 112 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getResource()

static URLConnection org.jau.net.AssetURLContext.getResource ( final String  resourcePath,
final ClassLoader  cl 
)
static

Locating a resource using the ClassLoader's facilities.

Returns the resolved and connected URLConnection or null if not found.

See also
ClassLoader::getResource(String)
ClassLoader::getSystemResource(String)
URL::URL(String)
File::File(String)

Definition at line 253 of file AssetURLContext.java.

Here is the call graph for this function:

◆ registerHandler()

static boolean org.jau.net.AssetURLContext.registerHandler ( final ClassLoader  cl)
static

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

Returns
true if successful, otherwise false

Definition at line 123 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolve() [1/2]

URLConnection org.jau.net.AssetURLContext.resolve ( final String  path) throws IOException

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.

Implements org.jau.net.PiggybackURLContext.

Definition at line 170 of file AssetURLContext.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolve() [2/2]

static URLConnection org.jau.net.AssetURLContext.resolve ( String  path,
final ClassLoader  cl 
) throws IOException
static

Definition at line 174 of file AssetURLContext.java.

Here is the call graph for this function:

Member Data Documentation

◆ asset_protocol

final String org.jau.net.AssetURLContext.asset_protocol = "asset"
static

The asset URL protocol name asset

Definition at line 48 of file AssetURLContext.java.

◆ asset_protocol_prefix

final String org.jau.net.AssetURLContext.asset_protocol_prefix = "asset:"
static

The asset URL protocol prefix asset:

Definition at line 51 of file AssetURLContext.java.

◆ assets_folder

final String org.jau.net.AssetURLContext.assets_folder = "assets/"
static

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().

Definition at line 60 of file AssetURLContext.java.


The documentation for this class was generated from the following file: