org.springframework.core.io

## 类 FileUrlResource

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

- 所有已实现的接口:
    InputStreamSource, Resource, WritableResource

      public class FileUrlResource
      extends UrlResource
      implements WritableResource

  Subclass of `UrlResource` which assumes file resolution, to the degree of implementing the `WritableResource` interface for it. This resource variant also caches resolved `File` handles from `getFile()`.

  This is the class resolved by `DefaultResourceLoader` for a "file:..." URL location, allowing a downcast to `WritableResource` for it.

  Alternatively, for direct construction from a `File` handle, consider using `FileSystemResource`. For an NIO `Path`, consider using `PathResource` instead.

  从以下版本开始:
    5.0.2
  作者:
    Juergen Hoeller

- - ### 构造器概要

    构造器
    构造器和说明
    `FileUrlResource(String location)` Create a new `FileUrlResource` based on the given file location, using the URL protocol "file".
    `FileUrlResource(URL url)` Create a new `FileUrlResource` 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.
    `File` | `getFile()` This implementation returns a File reference for the underlying URL/URI, provided that it refers to a file in the file system.
    `OutputStream` | `getOutputStream()` Return an `OutputStream` for the underlying resource, allowing to (over-)write its content.
    `boolean` | `isWritable()` Indicate whether the contents of this resource can be written via `WritableResource.getOutputStream()`.
    `WritableByteChannel` | `writableChannel()` Return a `WritableByteChannel`.

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

      `equals, getDescription, getFilename, getInputStream, getURI, getURL, hashCode, isFile`

    - ### 从类继承的方法 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`

    - ### 从接口继承的方法 org.springframework.core.io.Resource

      `contentLength, exists, getDescription, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel`

    - ### 从接口继承的方法 org.springframework.core.io.InputStreamSource

      `getInputStream`

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

    - #### FileUrlResource

          public FileUrlResource(URL url)

      Create a new `FileUrlResource` based on the given URL object.

      Note that this does not enforce "file" as URL protocol. If a protocol is known to be resolvable to a file,

      参数:
        `url` - a URL
      另请参阅:
        `ResourceUtils.isFileURL(URL)`, `getFile()`

    - #### FileUrlResource

          public FileUrlResource(String location)
                          throws MalformedURLException

      Create a new `FileUrlResource` based on the given file location, using the URL protocol "file".

      The given parts will automatically get encoded if necessary.

      参数:
        `location` - the location (i.e. the file path within that protocol)
      抛出:
        `MalformedURLException` - if the given URL specification is not valid
      另请参阅:
        `UrlResource.UrlResource(String, String)`, `ResourceUtils.URL_PROTOCOL_FILE`

  - ### 方法详细资料

    - #### getFile

          public File getFile()
                       throws IOException

      从类复制的说明: `UrlResource`
      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` 在类中 `UrlResource`
      抛出:
        `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)`

    - #### isWritable

          public boolean isWritable()

      从接口复制的说明: `WritableResource`
      Indicate whether the contents of this resource can be written via `WritableResource.getOutputStream()`.

      Will be `true` for typical resource descriptors; note that actual content writing may still fail when attempted. However, a value of `false` is a definitive indication that the resource content cannot be modified.

      指定者:
        `isWritable` 在接口中 `WritableResource`
      另请参阅:
        `WritableResource.getOutputStream()`, `Resource.isReadable()`

    - #### getOutputStream

          public OutputStream getOutputStream()
                                       throws IOException

      从接口复制的说明: `WritableResource`
      Return an `OutputStream` for the underlying resource, allowing to (over-)write its content.
      指定者:
        `getOutputStream` 在接口中 `WritableResource`
      抛出:
        `IOException` - if the stream could not be opened
      另请参阅:
        `InputStreamSource.getInputStream()`

    - #### writableChannel

          public WritableByteChannel writableChannel()
                                              throws IOException

      从接口复制的说明: `WritableResource`
      Return a `WritableByteChannel`.

      It is expected that each call creates a fresh channel.

      The default implementation returns `Channels.newChannel(OutputStream)` with the result of `WritableResource.getOutputStream()`.

      指定者:
        `writableChannel` 在接口中 `WritableResource`
      返回:
        the byte channel for the underlying resource (must not be `null`)
      抛出:
        `FileNotFoundException` - if the underlying resource doesn't exist
        `IOException` - if the content channel could not be opened
      另请参阅:
        `WritableResource.getOutputStream()`

    - #### createRelative

          public Resource createRelative(String relativePath)
                                  throws MalformedURLException

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