Package spark.resource
Class AbstractFileResolvingResource
java.lang.Object
spark.resource.AbstractResource
spark.resource.AbstractFileResolvingResource
- All Implemented Interfaces:
InputStreamResource,Resource
- Direct Known Subclasses:
ClassPathResource,ExternalResource
Abstract base class for resources which resolve URLs into File references,
such as UrlResource or
ClassPathResource.
Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongThis implementation reads the entire InputStream to calculate the content length.protected voidCustomize the givenHttpURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.protected voidCustomize the givenURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.booleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.getFile()This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.protected FileThis implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).booleanThis implementation always returnstrue.longThis implementation checks the timestamp of the underlying File, if available.Methods inherited from class spark.resource.AbstractResource
createRelative, equals, getFilename, getURI, getURL, hashCode, isOpen, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface spark.resource.InputStreamResource
getInputStreamMethods inherited from interface spark.resource.Resource
getDescription
-
Constructor Details
-
AbstractFileResolvingResource
public AbstractFileResolvingResource()
-
-
Method Details
-
getFile
This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.- Specified by:
getFilein interfaceResource- Overrides:
getFilein classAbstractResource- Returns:
- a File handle for this resource.
- Throws:
IOException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
-
getFileForLastModifiedCheck
This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).- Overrides:
getFileForLastModifiedCheckin classAbstractResource- Returns:
- the File to use for timestamp checking (never
null) - Throws:
IOException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
-
exists
public boolean exists()Description copied from class:AbstractResourceThis implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractResource- Returns:
- if exists
-
isReadable
public boolean isReadable()Description copied from class:AbstractResourceThis implementation always returnstrue.- Specified by:
isReadablein interfaceResource- Overrides:
isReadablein classAbstractResource- Returns:
- if readable
- See Also:
-
contentLength
Description copied from class:AbstractResourceThis implementation reads the entire InputStream to calculate the content length. Subclasses will almost always be able to provide a more optimal version of this, e.g. checking a File length.- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classAbstractResource- Returns:
- the content length for this resource.
- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
-
lastModified
Description copied from class:AbstractResourceThis implementation checks the timestamp of the underlying File, if available.- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classAbstractResource- 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)- See Also:
-
customizeConnection
Customize the givenURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.Calls
ResourceUtils.useCachesIfNecessary(URLConnection)and delegates tocustomizeConnection(HttpURLConnection)if possible. Can be overridden in subclasses.- Parameters:
con- the URLConnection to customize- Throws:
IOException- if thrown from URLConnection methods
-
customizeConnection
Customize the givenHttpURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.Sets request method "HEAD" by default. Can be overridden in subclasses.
- Parameters:
con- the HttpURLConnection to customize- Throws:
IOException- if thrown from HttpURLConnection methods
-