Package org.springframework.core.io
Class AbstractFileResolvingResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- org.springframework.core.io.AbstractFileResolvingResource
- All Implemented Interfaces:
InputStreamSource,Resource
- Direct Known Subclasses:
ClassPathResource,PortletContextResource,ServletContextResource,UrlResource
public abstract class AbstractFileResolvingResource extends AbstractResource
Abstract base class for resources which resolve URLs into File references, such asUrlResourceorClassPathResource.Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.
- Since:
- 3.0
- Author:
- Juergen Hoeller
Constructor Summary
Constructors Constructor Description AbstractFileResolvingResource()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longcontentLength()This implementation reads the entire InputStream to calculate the content length.protected voidcustomizeConnection(HttpURLConnection con)Customize the givenHttpURLConnection, obtained in the course of anexists(),contentLength()orlastModified()call.protected voidcustomizeConnection(URLConnection con)Customize 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.FilegetFile()This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.protected FilegetFile(URI uri)This implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.protected FilegetFileForLastModifiedCheck()This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).booleanisReadable()This implementation always returnstrue.longlastModified()This implementation checks the timestamp of the underlying File, if available.Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, equals, getFilename, getURI, getURL, hashCode, isOpen, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.io.InputStreamSource
getInputStream
Methods inherited from interface org.springframework.core.io.Resource
getDescription
Constructor Detail
AbstractFileResolvingResource
public AbstractFileResolvingResource()
Method Detail
getFile
public File getFile() throws IOException
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- Throws:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures- See Also:
ResourceUtils.getFile(java.net.URL, String)
getFileForLastModifiedCheck
protected File getFileForLastModifiedCheck() throws IOException
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:
FileNotFoundException- if the resource cannot be resolved as an absolute file path, i.e. is not available in a file systemIOException- in case of general resolution/reading failures
getFile
protected File getFile(URI uri) throws IOException
This implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.- Throws:
IOException- See Also:
ResourceUtils.getFile(java.net.URI, String)
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
isReadable
public boolean isReadable()
Description copied from class:AbstractResourceThis implementation always returnstrue.- Specified by:
isReadablein interfaceResource- Overrides:
isReadablein classAbstractResource- See Also:
InputStreamSource.getInputStream()
contentLength
public long contentLength() throws IOException
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- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
InputStreamSource.getInputStream()
lastModified
public long lastModified() throws IOException
Description copied from class:AbstractResourceThis implementation checks the timestamp of the underlying File, if available.- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classAbstractResource- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- See Also:
AbstractResource.getFileForLastModifiedCheck()
customizeConnection
protected void customizeConnection(URLConnection con) throws IOException
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
protected void customizeConnection(HttpURLConnection con) throws IOException
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