Package org.djutils.io
Class ResourceResolver.ResourceHandle
java.lang.Object
org.djutils.io.ResourceResolver.ResourceHandle
- Enclosing class:
- ResourceResolver
Inner class with the specifications for a resource.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumEnum for the kind of resource handle: file, JAR entry, HTTP resource, or generic URL. -
Method Summary
Modifier and TypeMethodDescriptionasPath()A Path is available for plain files and for JAR entries (mounted file system).asUri()Return the URI of the resource.asUrl()Return the URL of the resource, if it can be transformed to a URL.(package private) static ResourceResolver.ResourceHandleInstantiate a ResourceHandle from a given Path.(package private) static ResourceResolver.ResourceHandleforGenericUrl(URL url) Instantiate a ResourceHandle from a given generic URL.(package private) static ResourceResolver.ResourceHandleforHttp(URI httpUri, HttpClient http) Instantiate a ResourceHandle for a given URI for a http-connection using the provided http-client.(package private) static ResourceResolver.ResourceHandleInstantiate a ResourceHandle from a jar-entry containing URI such asjar:file:/...booleanReturn whether the resource was loaded from the classpath.booleanisFile()Return whether the resource is of type FILE.booleanReturn whether the resource is of type GENERIC_URL.booleanisHttp()Return whether the resource is of type HTTP.booleanReturn whether the resource is of type JAR_ENTRY.Return a readable stream of the resource for supported schemes.
-
Method Details
-
asUri
Return the URI of the resource.- Returns:
- the URI of the resource
-
asUrl
Return the URL of the resource, if it can be transformed to a URL. If not, an Exception is thrown.- Returns:
- the URI of the resource, if it can be transformed to a URL
- Throws:
IllegalStateException- when the URI cannot be transformed into a URL
-
openStream
Return a readable stream of the resource for supported schemes.- Returns:
- a readable stream of the resource for supported schemes
- Throws:
IOException- when an I/O error occurs during building of the stream
-
asPath
A Path is available for plain files and for JAR entries (mounted file system).- Returns:
- a Path representation of the resource or null when no Path exists.
-
isClassPath
public boolean isClassPath()Return whether the resource was loaded from the classpath.- Returns:
- whether the resource was loaded from the classpath or not
-
isFile
public boolean isFile()Return whether the resource is of type FILE.- Returns:
- whether the resource is of type FILE or not
-
isHttp
public boolean isHttp()Return whether the resource is of type HTTP.- Returns:
- whether the resource is of type HTTP or not
-
isGenericUrl
public boolean isGenericUrl()Return whether the resource is of type GENERIC_URL.- Returns:
- whether the resource is of type GENERIC_URL or not
-
isJarEntry
public boolean isJarEntry()Return whether the resource is of type JAR_ENTRY.- Returns:
- whether the resource is of type JAR_ENTRY or not
-
forFile
Instantiate a ResourceHandle from a given Path.- Parameters:
p- the Path- Returns:
- a ResourceHandle for the Path
-
forJarUri
Instantiate a ResourceHandle from a jar-entry containing URI such asjar:file:/.../lib.jar!/path/inside.- Parameters:
jarUri- the jar-entry containing URI- Returns:
- a ResourceHandle for the jar-entry containing URI
-
forHttp
Instantiate a ResourceHandle for a given URI for a http-connection using the provided http-client.- Parameters:
httpUri- a URI for a http-connectionhttp- the http-client to use- Returns:
- a ResourceHandle for the given URI for a http-connection
-
forGenericUrl
Instantiate a ResourceHandle from a given generic URL. Throw an exception when the resource handle cannot be instantiated from the URL.- Parameters:
url- the generic URL- Returns:
- a ResourceHandle for the given URL
- Throws:
IllegalArgumentException- when the resource handle cannot be instantiated from the URL
-