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
A file backed resource which calls out to a provided
Runnable as appropriate such that the resource becomes
reloadable.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRunnableFileSystemResource(File file, Runnable runnable) Constructor.RunnableFileSystemResource(String path, Runnable runnable) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCall the runnable and catch every event thrown.createRelativeResource(String relativePath) Create a resource relative to this resource.booleanexists()Return whether this resource actually exists in physical form.Return anInputStream.longDetermine the last-modified timestamp for this resource.Methods inherited from class org.springframework.core.io.FileSystemResource
contentLength, createRelative, equals, getContentAsByteArray, getContentAsString, getDescription, getFile, getFilename, getOutputStream, getPath, getURI, getURL, hashCode, isFile, isReadable, isWritable, readableChannel, writableChannelMethods inherited from class org.springframework.core.io.AbstractResource
getFileForLastModifiedCheck, isOpen, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.shibboleth.shared.resource.Resource
contentLength, getDescription, getFile, getFilename, getURI, getURL, isFile, isOpen, isReadableMethods inherited from interface org.springframework.core.io.Resource
contentLength, createRelative, getContentAsByteArray, getContentAsString, getDescription, getFile, getFilename, getURI, getURL, isFile, isOpen, isReadable, readableChannel
-
Field Details
-
theRunnable
What to run at the appropriate time. -
log
@Nonnull private final org.slf4j.Logger logThe log. -
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- aRunnableto 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- aRunnableto 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:
createRelativeResourcein interfaceResource- 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
Resourcehandle only guarantees a valid descriptor handle. -
getInputStream
Return anInputStream.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:
getInputStreamin interfaceInputStreamSource- Specified by:
getInputStreamin interfaceResource- Overrides:
getInputStreamin classFileSystemResource- Returns:
- the input stream for the underlying resource (must not be
null) - Throws:
IOException- if the stream could not be opened
-
lastModified
Determine the last-modified timestamp for this resource.- Specified by:
lastModifiedin interfaceResource- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classFileSystemResource- 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
Call the runnable and catch every event thrown.- Throws:
IOException- if anything bad happens
-