类 ResourceDecorator

java.lang.Object
cn.taketoday.core.io.ResourceDecorator
所有已实现的接口:
InputStreamSource, Resource, ThrowingConsumer<OutputStream>, Consumer<OutputStream>
直接已知子类:
WritableResourceDecorator

public class ResourceDecorator extends Object implements Resource
This class implements the Wrapper or Decorator pattern.
从以下版本开始:
4.0 2022/3/2 9:06
作者:
Harry Yang
  • 字段详细资料

    • delegate

      protected Resource delegate
  • 构造器详细资料

    • ResourceDecorator

      protected ResourceDecorator()
    • ResourceDecorator

      public ResourceDecorator(Resource delegate)
  • 方法详细资料

    • getInputStream

      public InputStream getInputStream() throws IOException
      从接口复制的说明: InputStreamSource
      Return an InputStream for the content of an underlying resource.

      It is expected that each call creates a fresh stream.

      This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

      指定者:
      getInputStream 在接口中 InputStreamSource
      返回:
      the input stream for the underlying resource (must not be null)
      抛出:
      FileNotFoundException - if the underlying resource does not exist
      IOException - if the content stream could not be opened
      另请参阅:
    • getReader

      public Reader getReader() throws IOException
      从接口复制的说明: InputStreamSource
      Get Reader
      指定者:
      getReader 在接口中 InputStreamSource
      抛出:
      IOException - If an input exception occurs
    • getReader

      public Reader getReader(String encoding) throws IOException
      从接口复制的说明: InputStreamSource
      Get Reader
      指定者:
      getReader 在接口中 InputStreamSource
      参数:
      encoding - Charset string
      抛出:
      IOException - If an input exception occurs
    • readableChannel

      public ReadableByteChannel readableChannel() throws IOException
      从接口复制的说明: InputStreamSource
      Return a ReadableByteChannel.

      It is expected that each call creates a fresh channel.

      The default implementation returns Channels.newChannel(InputStream) with the result of InputStreamSource.getInputStream().

      指定者:
      readableChannel 在接口中 InputStreamSource
      返回:
      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
      另请参阅:
    • getName

      public String getName()
      从接口复制的说明: Resource
      Determine a name for this resource, i.e. typically the last part of the path: for example, "myfile.txt".

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

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

      public long contentLength() throws IOException
      从接口复制的说明: Resource
      Determine the content length for this resource.
      指定者:
      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
      从接口复制的说明: Resource
      Determine the last-modified timestamp for this resource.
      指定者:
      lastModified 在接口中 Resource
      抛出:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • 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
      另请参阅:
    • exists

      public boolean exists()
      从接口复制的说明: Resource
      Determine whether this resource actually exists in physical form.

      This method performs a definitive existence check, whereas the existence of a Resource handle only guarantees a valid descriptor handle.

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

      public boolean isReadable()
      从接口复制的说明: Resource
      Indicate whether non-empty contents of this resource can be read via InputStreamSource.getInputStream().

      Will be true for typical resource descriptors that exist since it strictly implies Resource.exists() semantics. Note that actual content reading may still fail when attempted. However, a value of false is a definitive indication that the resource content cannot be read.

      指定者:
      isReadable 在接口中 Resource
      另请参阅:
    • isOpen

      public boolean isOpen()
      从接口复制的说明: Resource
      Indicate whether this resource represents a handle with an open stream. If true, the InputStream cannot be read multiple times, and must be read and closed to avoid resource leaks.

      Will be false for typical resource descriptors.

      指定者:
      isOpen 在接口中 Resource
    • isFile

      public boolean isFile()
      从接口复制的说明: Resource
      Determine whether this resource represents a file in a file system.

      A value of true strongly suggests (but does not guarantee) that a Resource.getFile() call will succeed.

      This is conservatively false by default.

      指定者:
      isFile 在接口中 Resource
      另请参阅:
    • 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(@Nullable ResourceFilter filter) throws IOException
      从接口复制的说明: Resource
      list Resource under the directory
      指定者:
      list 在接口中 Resource
      参数:
      filter - filter Resource
      返回:
      Resource names
      抛出:
      IOException - if the resource is not available
    • 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
    • getDelegate

      public Resource getDelegate()
    • setDelegate

      public void setDelegate(Resource delegate)
    • equals

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

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • 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
      另请参阅: