Class ResourceResolver.ResourceHandle

java.lang.Object
org.djutils.io.ResourceResolver.ResourceHandle
Enclosing class:
ResourceResolver

public static final class ResourceResolver.ResourceHandle extends Object
Inner class with the specifications for a resource.
  • Method Details

    • asUri

      public URI asUri()
      Return the URI of the resource.
      Returns:
      the URI of the resource
    • asUrl

      public URL 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

      public InputStream openStream() throws IOException
      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

      public Path 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

      static ResourceResolver.ResourceHandle forJarUri(URI jarUri)
      Instantiate a ResourceHandle from a jar-entry containing URI such as jar:file:/.../lib.jar!/path/inside.
      Parameters:
      jarUri - the jar-entry containing URI
      Returns:
      a ResourceHandle for the jar-entry containing URI
    • forHttp

      static ResourceResolver.ResourceHandle forHttp(URI httpUri, HttpClient http)
      Instantiate a ResourceHandle for a given URI for a http-connection using the provided http-client.
      Parameters:
      httpUri - a URI for a http-connection
      http - the http-client to use
      Returns:
      a ResourceHandle for the given URI for a http-connection
    • forGenericUrl

      static ResourceResolver.ResourceHandle forGenericUrl(URL url)
      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