org.springframework.core.io

## 类 UrlResource

- java.lang.Object
- - org.springframework.core.io.AbstractResource
  - - org.springframework.core.io.AbstractFileResolvingResource
    - - org.springframework.core.io.UrlResource

- 所有已实现的接口:
    InputStreamSource, Resource
  直接已知子类:
    FileUrlResource

      public class UrlResource
      extends AbstractFileResolvingResource

  `Resource` implementation for `java.net.URL` locators. Supports resolution as a `URL` and also as a `File` in case of the `"file:"` protocol.
  从以下版本开始:
    28.12.2003
  作者:
    Juergen Hoeller
  另请参阅:
    `URL`

- - ### 构造器概要

    构造器
    构造器和说明
    `UrlResource(String path)` Create a new `UrlResource` based on a URL path.
    `UrlResource(String protocol, String location)` Create a new `UrlResource` based on a URI specification.
    `UrlResource(String protocol, String location, String fragment)` Create a new `UrlResource` based on a URI specification.
    `UrlResource(URI uri)` Create a new `UrlResource` based on the given URI object.
    `UrlResource(URL url)` Create a new `UrlResource` based on the given URL object.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `Resource` | `createRelative(String relativePath)` This implementation creates a `UrlResource`, applying the given path relative to the path of the underlying URL of this resource descriptor.
    `boolean` | `equals(Object other)` This implementation compares the underlying URL references.
    `String` | `getDescription()` This implementation returns a description that includes the URL.
    `File` | `getFile()` This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.
    `String` | `getFilename()` This implementation returns the name of the file that this URL refers to.
    `InputStream` | `getInputStream()` This implementation opens an InputStream for the given URL.
    `URI` | `getURI()` This implementation returns the underlying URI directly, if possible.
    `URL` | `getURL()` This implementation returns the underlying URL reference.
    `int` | `hashCode()` This implementation returns the hash code of the underlying URL reference.
    `boolean` | `isFile()` This implementation always returns `false`.

    - ### 从类继承的方法 org.springframework.core.io.AbstractFileResolvingResource

      `contentLength, customizeConnection, customizeConnection, exists, getFile, getFileForLastModifiedCheck, isFile, isReadable, lastModified, readableChannel`

    - ### 从类继承的方法 org.springframework.core.io.AbstractResource

      `isOpen, toString`

    - ### 从类继承的方法 java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### 构造器详细资料

    - #### UrlResource

          public UrlResource(URI uri)
                      throws MalformedURLException

      Create a new `UrlResource` based on the given URI object.
      参数:
        `uri` - a URI
      抛出:
        `MalformedURLException` - if the given URL path is not valid
      从以下版本开始:
        2.5

    - #### UrlResource

          public UrlResource(URL url)

      Create a new `UrlResource` based on the given URL object.
      参数:
        `url` - a URL

    - #### UrlResource

          public UrlResource(String path)
                      throws MalformedURLException

      Create a new `UrlResource` based on a URL path.

      Note: The given path needs to be pre-encoded if necessary.

      参数:
        `path` - a URL path
      抛出:
        `MalformedURLException` - if the given URL path is not valid
      另请参阅:
        `URL.URL(String)`

    - #### UrlResource

          public UrlResource(String protocol,
                             String location)
                      throws MalformedURLException

      Create a new `UrlResource` based on a URI specification.

      The given parts will automatically get encoded if necessary.

      参数:
        `protocol` - the URL protocol to use (e.g. "jar" or "file" - without colon); also known as "scheme"
        `location` - the location (e.g. the file path within that protocol); also known as "scheme-specific part"
      抛出:
        `MalformedURLException` - if the given URL specification is not valid
      另请参阅:
        `URI.URI(String, String, String)`

    - #### UrlResource

          public UrlResource(String protocol,
                             String location,
                             @Nullable
                             String fragment)
                      throws MalformedURLException

      Create a new `UrlResource` based on a URI specification.

      The given parts will automatically get encoded if necessary.

      参数:
        `protocol` - the URL protocol to use (e.g. "jar" or "file" - without colon); also known as "scheme"
        `location` - the location (e.g. the file path within that protocol); also known as "scheme-specific part"
        `fragment` - the fragment within that location (e.g. anchor on an HTML page, as following after a "#" separator)
      抛出:
        `MalformedURLException` - if the given URL specification is not valid
      另请参阅:
        `URI.URI(String, String, String)`

  - ### 方法详细资料

    - #### getInputStream

          public InputStream getInputStream()
                                     throws IOException

      This implementation opens an InputStream for the given URL.

      It sets the `useCaches` flag to `false`, mainly to avoid jar file locking on Windows.

      返回:
        the input stream for the underlying resource (must not be `null`)
      抛出:
        `FileNotFoundException` - if the underlying resource doesn't exist
        `IOException` - if the content stream could not be opened
      另请参阅:
        `URL.openConnection()`, `URLConnection.setUseCaches(boolean)`, `URLConnection.getInputStream()`

    - #### getURL

          public URL getURL()

      This implementation returns the underlying URL reference.
      指定者:
        `getURL` 在接口中 `Resource`
      覆盖:
        `getURL` 在类中 `AbstractResource`

    - #### getURI

          public URI getURI()
                     throws IOException

      This implementation returns the underlying URI directly, if possible.
      指定者:
        `getURI` 在接口中 `Resource`
      覆盖:
        `getURI` 在类中 `AbstractResource`
      抛出:
        `IOException` - if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor

    - #### isFile

          public boolean isFile()

      从类复制的说明: `AbstractResource`
      This implementation always returns `false`.
      指定者:
        `isFile` 在接口中 `Resource`
      覆盖:
        `isFile` 在类中 `AbstractFileResolvingResource`
      另请参阅:
        `Resource.getFile()`

    - #### getFile

          public File getFile()
                       throws IOException

      This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.
      指定者:
        `getFile` 在接口中 `Resource`
      覆盖:
        `getFile` 在类中 `AbstractFileResolvingResource`
      抛出:
        `FileNotFoundException` - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
        `IOException` - in case of general resolution/reading failures
      另请参阅:
        `ResourceUtils.getFile(java.net.URL, String)`

    - #### createRelative

          public Resource createRelative(String relativePath)
                                  throws MalformedURLException

      This implementation creates a `UrlResource`, applying the given path relative to the path of the underlying URL of this resource descriptor.
      指定者:
        `createRelative` 在接口中 `Resource`
      覆盖:
        `createRelative` 在类中 `AbstractResource`
      参数:
        `relativePath` - the relative path (relative to this resource)
      返回:
        the resource handle for the relative resource
      抛出:
        `MalformedURLException`
      另请参阅:
        `URL.URL(java.net.URL, String)`

    - #### getFilename

          public String getFilename()

      This implementation returns the name of the file that this URL refers to.
      指定者:
        `getFilename` 在接口中 `Resource`
      覆盖:
        `getFilename` 在类中 `AbstractResource`
      另请参阅:
        `URL.getPath()`

    - #### getDescription

          public String getDescription()

      This implementation returns a description that includes the URL.
      另请参阅:
        `Object.toString()`

    - #### equals

          public boolean equals(Object other)

      This implementation compares the underlying URL references.
      覆盖:
        `equals` 在类中 `AbstractResource`
      另请参阅:
        `Resource.getDescription()`

    - #### hashCode

          public int hashCode()

      This implementation returns the hash code of the underlying URL reference.
      覆盖:
        `hashCode` 在类中 `AbstractResource`
      另请参阅:
        `Resource.getDescription()`