Package net.shibboleth.shared.spring.resource

# Class RunnableFileSystemResource

java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.FileSystemResource
net.shibboleth.shared.spring.resource.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 Summary

Fields
Modifier and Type
Field
Description
`private final org.slf4j.Logger`
`log`
The log.
`private final String`
`thePrefix`
Log prefix.
`private final Runnable`
`theRunnable`
What to run at the appropriate time.

## Constructor Summary

Constructors
Constructor
Description
`RunnableFileSystemResource(File file, Runnable runnable)`
Constructor.
`RunnableFileSystemResource(String path, Runnable runnable)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`callRunnable()`
Call the runnable and catch every event thrown.
`RunnableFileSystemResource`
`createRelativeResource(String relativePath)`
Create a resource relative to this resource.
`boolean`
`exists()`
Return whether this resource actually exists in physical form.
`InputStream`
`getInputStream()`
Return an `InputStream`.
`long`
`lastModified()`
Determine the last-modified timestamp for this resource.

### Methods inherited from class org.springframework.core.io.FileSystemResource

`contentLength, createRelative, equals, getContentAsByteArray, getContentAsString, getDescription, getFile, getFilename, getFilePath, getOutputStream, getPath, getURI, getURL, hashCode, isFile, isReadable, isWritable, readableChannel, writableChannel`

### Methods inherited from class org.springframework.core.io.AbstractResource

`getFileForLastModifiedCheck, isOpen, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.resource.Resource

`contentLength, getDescription, getFile, getFilename, getURI, getURL, isFile, isOpen, isReadable`

### Methods inherited from interface org.springframework.core.io.Resource

`contentLength, createRelative, getContentAsByteArray, getContentAsString, getDescription, getFile, getFilename, getFilePath, getURI, getURL, isFile, isOpen, isReadable, readableChannel`

## 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

### RunnableFileSystemResource

public RunnableFileSystemResource(@Nonnull @ParameterName(name="file") File file, @Nonnull @ParameterName(name="runnable") Runnable runnable)
Constructor.

Parameters:
  `file` - The file to back.
  `runnable` - a `Runnable` to call at appropriate times

### RunnableFileSystemResource

public RunnableFileSystemResource(@Nonnull @NotEmpty @ParameterName(name="path") String path, @Nonnull @ParameterName(name="runnable") Runnable runnable)
Constructor.

Parameters:
  `path` - the path to the file to look at.
  `runnable` - a `Runnable` to call at appropriate times

## 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