UrlResource (Grails 6.0.0)

Package: org.grails.io.support

## [Java] Class UrlResource

- org.grails.io.support.UrlResource

-     public class UrlResource
      extends AbstractFileResolvingResource

  Resource implementation for `java.net.URL` locators. Obviously supports resolution as URL, and also as File in case of the "file:" protocol.

  Authors:
    Juergen Hoeller
  Since:
    28.12.2003
  See Also:
    java.net.URL

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `private java.net.URL` | `cleanedUrl` | Cleaned URL (with normalized path), used for comparisons.
    `private java.net.URI` | `uri` | Original URI, if available; used for URI and File access.
    `private java.net.URL` | `url` | Original URL, used for actual access.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `UrlResource (java.net.URL url)` Create a new UrlResource.
    `UrlResource (java.net.URI uri)` Create a new UrlResource.
    `UrlResource (java.lang.String path)` Create a new UrlResource.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Resource` | `createRelative(java.lang.String relativePath)` This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.
    `` | `public boolean` | `equals(java.lang.Object obj)` This implementation compares the underlying URL references.
    `` | `private java.net.URL` | `getCleanedUrl(java.net.URL originalUrl, java.lang.String originalPath)` Determine a cleaned URL for the given original URL.
    `` | `public java.lang.String` | `getDescription()` This implementation returns a description that includes the URL.
    `` | `public java.io.File` | `getFile()` This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.
    `` | `public java.lang.String` | `getFilename()` This implementation returns the name of the file that this URL refers to.
    `` | `public java.io.InputStream` | `getInputStream()` This implementation opens an InputStream for the given URL.
    `` | `public java.net.URI` | `getURI()` This implementation returns the underlying URI directly, if possible.
    `` | `public java.net.URL` | `getURL()` This implementation returns the underlying URL reference.
    `` | `public int` | `hashCode()` This implementation returns the hash code of the underlying URL reference.
    `` | `public java.lang.String` | `toString()`
    `` | `private static void` | `useCachesIfNecessary(java.net.URLConnection con)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class AbstractFileResolvingResource` | `contentLength, exists, getFile, getFile, getFileForLastModifiedCheck, isReadable, lastModified, useCachesIfNecessary`

- - ### Field Detail

    - #### private final java.net.URL cleanedUrl

      Cleaned URL (with normalized path), used for comparisons.

    - #### private final java.net.URI uri

      Original URI, if available; used for URI and File access.

    - #### private final java.net.URL url

      Original URL, used for actual access.

  - ### Constructor Detail

    - #### public UrlResource(java.net.URL url)

      Create a new UrlResource.

      Parameters:
        `url` - a URL

    - #### public UrlResource(java.net.URI uri)

      Create a new UrlResource.

      throws:
        java.net.MalformedURLException if the given URL path is not valid
      Parameters:
        `uri` - a URI

    - #### public UrlResource(java.lang.String path)

      Create a new UrlResource.

      throws:
        MalformedURLException if the given URL path is not valid
      Parameters:
        `path` - a URL path

  - ### Method Detail

    - #### public Resource createRelative(java.lang.String relativePath)

      This implementation creates a UrlResource, applying the given path relative to the path of the underlying URL of this resource descriptor.

      See Also:
        java.net.URL#URL(java.net.URL, String)

    - #### @java.lang.Override public boolean equals(java.lang.Object obj)

      This implementation compares the underlying URL references.

    - #### private java.net.URL getCleanedUrl(java.net.URL originalUrl, java.lang.String originalPath)

      Determine a cleaned URL for the given original URL.

      Parameters:
        `originalUrl` - the original URL
        `originalPath` - the original URL path
      Returns:
        the cleaned URL

    - #### public java.lang.String getDescription()

      This implementation returns a description that includes the URL.

    - #### @java.lang.Override public java.io.File getFile()

      This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.

    - #### public java.lang.String getFilename()

      This implementation returns the name of the file that this URL refers to.

      See Also:
        java.net.URL#getFile()
        java.io.File#getName()

    - #### public java.io.InputStream getInputStream()

      This implementation opens an InputStream for the given URL. It sets the "UseCaches" flag to `false`, mainly to avoid jar file locking on Windows.

      See Also:
        java.net.URL#openConnection()
        java.net.URLConnection#setUseCaches(boolean)
        java.net.URLConnection#getInputStream()

    - #### public java.net.URI getURI()

      This implementation returns the underlying URI directly, if possible.

    - #### public java.net.URL getURL()

      This implementation returns the underlying URL reference.

    - #### @java.lang.Override public int hashCode()

      This implementation returns the hash code of the underlying URL reference.

    - #### @java.lang.Override public java.lang.String toString()

    - #### private static void useCachesIfNecessary(java.net.URLConnection con)