接口 Resource

所有超级接口:
Consumer<OutputStream>, InputStreamSource, ThrowingConsumer<OutputStream>
所有已知子接口:
ContextResource, WritableResource
所有已知实现类:
AbstractFileResolvingResource, AbstractResource, ByteArrayResource, ClassPathResource, ClassRelativeResourceLoader.ClassRelativeContextResource, DefaultResourceLoader.ClassPathContextResource, DescriptiveResource, FileSystemResource, FileSystemResourceLoader.FileSystemContextResource, FileUrlResource, InputStreamResource, ModuleResource, PathResource, ResourceDecorator, UrlResource, WritableResourceDecorator

public interface Resource extends InputStreamSource
Interface for a resource descriptor that abstracts from the actual type of underlying resource, such as a file or class path resource.

An InputStream can be opened for every resource if it exists in physical form, but a URL or File handle can just be returned for certain resources. The actual behavior is implementation-specific.

从以下版本开始:
2.1.6 2019-05-14 19:55
作者:
Juergen Hoeller, Arjen Poutsma, Harry Yang
另请参阅:
  • 字段详细资料

    • EMPTY_ARRAY

      static final Resource[] EMPTY_ARRAY
  • 方法详细资料

    • getName

      @Nullable String getName()
      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.

    • contentLength

      long contentLength() throws IOException
      Determine the content length for this resource.
      抛出:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • lastModified

      long lastModified() throws IOException
      Determine the last-modified timestamp for this resource.
      抛出:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • getURL

      URL getURL() throws IOException
      Return a URL handle for this resource.
      抛出:
      IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
    • getURI

      URI getURI() throws IOException
      Return a URI handle for this resource.
      抛出:
      IOException - if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
      从以下版本开始:
      2.1.7
    • getFile

      File getFile() throws IOException
      Return a File handle for this 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
      另请参阅:
    • getContentAsByteArray

      default byte[] getContentAsByteArray() throws IOException
      Return the contents of this resource as a byte array.
      返回:
      the contents of this resource as byte array
      抛出:
      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
      从以下版本开始:
      4.0
    • getContentAsString

      default String getContentAsString(Charset charset) throws IOException
      Returns the contents of this resource as a string, using the specified charset.
      参数:
      charset - the charset to use for decoding
      返回:
      the contents of this resource as a String
      抛出:
      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
      从以下版本开始:
      4.0
    • exists

      boolean exists()
      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.

    • isReadable

      default boolean isReadable()
      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 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.

      另请参阅:
    • isOpen

      default boolean isOpen()
      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.

    • isFile

      default boolean isFile()
      Determine whether this resource represents a file in a file system.

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

      This is conservatively false by default.

      从以下版本开始:
      4.0
      另请参阅:
    • isDirectory

      boolean isDirectory() throws IOException
      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.

      返回:
      true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
      抛出:
      IOException - cannot determine resource
    • list

      list Resource under the directory
      返回:
      Resource names
      抛出:
      IOException - if the resource is not available
    • list

      list Resource under the directory
      参数:
      filter - filter Resource
      返回:
      Resource names
      抛出:
      IOException - if the resource is not available
    • createRelative

      Resource createRelative(String relativePath) throws IOException
      Create a resource relative to this 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

      String toString()
      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 在类中 Object
      另请参阅: