Interface Resource

All Known Implementing Classes:
AbstractResource, ClasspathResource, FileResource, UrlResource

public interface Resource
Inspired by org.springframework.core.io.Resource.
Author:
Cyrille Le Clerc
  • Method Summary

    Modifier and Type Method Description
    boolean exists()
    Return whether this resource actually exists in physical form.
    String getDescription()
    Return a description for this resource, to be used for error output when working with the resource.
    File getFile()
    Return a File handle for this resource.
    InputStream getInputStream()
    Return an InputStream.
    URI getURI()
    Return a URI handle for this resource.
    URL getURL()
    Return a URL handle for this resource.
    long lastModified()
    Determine the last-modified timestamp for this resource.
  • Method Details

    • getInputStream

      @Nonnull InputStream getInputStream()
      Return an InputStream.

      It is expected that each call creates a fresh stream.

      Returns:
      the input stream for the underlying resource (must not be null)
      Throws:
      IoRuntimeException - if the stream could not be opened
    • exists

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

    • getURL

      @Nonnull URL getURL()
      Return a URL handle for this resource.
      Throws:
      IoRuntimeException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
    • getURI

      @Nonnull URI getURI()
      Return a URI handle for this resource.
      Throws:
      IoRuntimeException - if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
    • getFile

      @Nonnull File getFile()
      Return a File handle for this resource.
      Throws:
      IoRuntimeException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
    • lastModified

      long lastModified()
      Determine the last-modified timestamp for this resource.
      Throws:
      IoRuntimeException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • getDescription

      String getDescription()
      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.

      See Also:
      Object.toString()