类 AbstractResource

java.lang.Object
cn.taketoday.core.io.AbstractResource
所有已实现的接口:
InputStreamSource, Resource
直接已知子类:
AbstractFileResolvingResource, ByteArrayResource, DescriptiveResource, FileSystemResource, InputStreamResource, PathResource

public abstract class AbstractResource extends Object implements Resource
Convenience base class for Resource implementations, pre-implementing typical behavior.

The "exists" method will check whether a File or InputStream can be opened; "isOpen" will always return false; "getURL" and "getFile" throw an exception; and "toString" will return the description.

从以下版本开始:
2.1.6 2019-05-14
作者:
Juergen Hoeller, Sam Brannen, Harry Yang
  • 构造器详细资料

    • AbstractResource

      public AbstractResource()
  • 方法详细资料

    • getName

      @Nullable public String getName()
      Determine the filename for this resource — typically the last part of the path — for example, "myfile.txt".

      Returns null if this type of resource does not have a filename.

      Implementations are encouraged to return the filename unencoded.

      指定者:
      getName 在接口中 Resource
    • exists

      public boolean exists()
      This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.

      This will cover both directories and content resources.

      指定者:
      exists 在接口中 Resource
    • isReadable

      public boolean isReadable()
      This implementation always returns true for a resource that exists (revised as of 5.1).
      指定者:
      isReadable 在接口中 Resource
      另请参阅:
    • customizeConnection

      protected void customizeConnection(URLConnection con) throws IOException
      Customize the given URLConnection, obtained in the course of an exists(), contentLength() or lastModified() call.

      Calls ResourceUtils.useCachesIfNecessary(URLConnection) and delegates to customizeConnection(HttpURLConnection) if possible. Can be overridden in subclasses.

      参数:
      con - the URLConnection to customize
      抛出:
      IOException - if thrown from URLConnection methods
    • customizeConnection

      protected void customizeConnection(HttpURLConnection con) throws IOException
      Customize the given HttpURLConnection, obtained in the course of an exists(), contentLength() or lastModified() call.

      Sets request method "HEAD" by default. Can be overridden in subclasses.

      参数:
      con - the HttpURLConnection to customize
      抛出:
      IOException - if thrown from HttpURLConnection methods
    • isOpen

      public boolean isOpen()
      This implementation always returns false.
      指定者:
      isOpen 在接口中 Resource
    • isFile

      public boolean isFile()
      This implementation always returns false.
      指定者:
      isFile 在接口中 Resource
      另请参阅:
    • getURL

      public URL getURL() throws IOException
      从接口复制的说明: Resource
      Return a URL handle for this resource.
      指定者:
      getURL 在接口中 Resource
      抛出:
      IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
    • getURI

      public URI getURI() throws IOException
      从接口复制的说明: Resource
      Return a URI handle for this resource.
      指定者:
      getURI 在接口中 Resource
      抛出:
      IOException - if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
    • getFile

      public File getFile() throws IOException
      从接口复制的说明: Resource
      Return a File handle for this resource.
      指定者:
      getFile 在接口中 Resource
      抛出:
      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
      另请参阅:
    • isDirectory

      public boolean isDirectory() throws IOException
      从接口复制的说明: Resource
      Tests whether the resource denoted by this abstract pathname is a directory.

      Where it is required to distinguish an I/O exception from the case that the file is not a directory, or where several attributes of the same file are required at the same time, then the Files.readAttributes method may be used.

      指定者:
      isDirectory 在接口中 Resource
      返回:
      true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
      抛出:
      IOException - cannot determine resource
    • list

      public String[] list() throws IOException
      从接口复制的说明: Resource
      list Resource under the directory
      指定者:
      list 在接口中 Resource
      返回:
      Resource names
      抛出:
      IOException - if the resource is not available
    • list

      public Resource[] list(ResourceFilter filter) throws IOException
      从接口复制的说明: Resource
      list Resource under the directory
      指定者:
      list 在接口中 Resource
      参数:
      filter - filter Resource
      返回:
      Resource names
      抛出:
      IOException - if the resource is not available
    • contentLength

      public long contentLength() throws IOException
      This method reads the entire InputStream to determine the content length.

      For a custom subclass of InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, e.g. checking File length, or possibly simply returning -1 if the stream can only be read once.

      指定者:
      contentLength 在接口中 Resource
      抛出:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
      另请参阅:
    • lastModified

      public long lastModified() throws IOException
      This implementation checks the timestamp of the underlying File, if available.
      指定者:
      lastModified 在接口中 Resource
      抛出:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
      另请参阅:
    • getFileForLastModifiedCheck

      protected File getFileForLastModifiedCheck() throws IOException
      Determine the File to use for timestamp checking.

      The default implementation delegates to getFile().

      返回:
      the File to use for timestamp checking (never null)
      抛出:
      FileNotFoundException - if the resource cannot be resolved as an absolute file path, i.e. is not available in a file system
      IOException - in case of general resolution/reading failures
    • createRelative

      public Resource createRelative(String relativePath) throws IOException
      从接口复制的说明: Resource
      Create a resource relative to this resource.
      指定者:
      createRelative 在接口中 Resource
      参数:
      relativePath - the relative path (relative to this resource)
      返回:
      the resource handle for the relative resource
      抛出:
      IOException - if the relative resource cannot be determined
    • toString

      public String toString()
      从接口复制的说明: Resource
      Return a description for this resource, to be used for error output when working with the resource.

      Implementations are also encouraged to return this value from their toString method.

      指定者:
      toString 在接口中 Resource
      覆盖:
      toString 在类中 Object
      另请参阅:
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object