Class RunnableFileSystemResource

All Implemented Interfaces:
Resource, InputStreamSource, Resource, WritableResource

public class RunnableFileSystemResource extends FileSystemResource implements Resource, Resource
A file backed resource which calls out to a provided Runnable as appropriate such that the resource becomes reloadable.
  • Field Details

    • theRunnable

      @Nonnull private final Runnable theRunnable
      What to run at the appropriate time.
    • log

      @Nonnull private final org.slf4j.Logger log
      The log.
    • thePrefix

      @Nonnull @NotEmpty private final String thePrefix
      Log prefix.
  • Constructor Details

  • Method Details

    • createRelativeResource

      @Nonnull public RunnableFileSystemResource createRelativeResource(@Nonnull String relativePath) throws IOException
      Create a resource relative to this resource.
      Specified by:
      createRelativeResource in interface Resource
      Parameters:
      relativePath - the relative path (relative to this resource)
      Returns:
      the resource handle for the relative resource
      Throws:
      IOException - if the relative resource cannot be determined
    • exists

      public 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.

      Specified by:
      exists in interface Resource
      Specified by:
      exists in interface Resource
      Overrides:
      exists in class FileSystemResource
      Returns:
      whether this resource actually exists in physical form.
    • getInputStream

      @Nonnull public InputStream getInputStream() throws IOException
      Return an InputStream.

      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.

      Specified by:
      getInputStream in interface InputStreamSource
      Specified by:
      getInputStream in interface Resource
      Overrides:
      getInputStream in class FileSystemResource
      Returns:
      the input stream for the underlying resource (must not be null)
      Throws:
      IOException - if the stream could not be opened
    • lastModified

      public long lastModified() throws IOException
      Determine the last-modified timestamp for this resource.
      Specified by:
      lastModified in interface Resource
      Specified by:
      lastModified in interface Resource
      Overrides:
      lastModified in class FileSystemResource
      Returns:
      the last-modified timestamp for this resource.
      Throws:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • callRunnable

      protected void callRunnable() throws IOException
      Call the runnable and catch every event thrown.
      Throws:
      IOException - if anything bad happens