Spring Framework

org.springframework.core.io
Class AbstractFileResolvingResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by 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 as UrlResource or ClassPathResource.

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
AbstractFileResolvingResource()
           
 
Method Summary
 long contentLength()
          This implementation reads the entire InputStream to calculate the content length.
 boolean exists()
          This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
 java.io.File 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  java.io.File getFile(java.net.URI uri)
          This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.
protected  java.io.File getFileForLastModifiedCheck()
          This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).
 boolean isReadable()
          This implementation always returns true.
 long lastModified()
          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.Resource
getDescription, getInputStream
 

Constructor Detail

AbstractFileResolvingResource

public AbstractFileResolvingResource()
Method Detail

getFile

public java.io.File getFile()
                     throws java.io.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:
getFile in interface Resource
Overrides:
getFile in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
See Also:
ResourceUtils.getFile(java.net.URL, String)

getFileForLastModifiedCheck

protected java.io.File getFileForLastModifiedCheck()
                                            throws java.io.IOException
This implementation determines the underlying File (or jar file, in case of a resource in a jar/zip).

Overrides:
getFileForLastModifiedCheck in class AbstractResource
Returns:
the File to use for timestamp checking (never null)
Throws:
java.io.IOException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system

getFile

protected java.io.File getFile(java.net.URI uri)
                        throws java.io.IOException
This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.

Throws:
java.io.IOException
See Also:
ResourceUtils.getFile(java.net.URI, String)

exists

public boolean exists()
Description copied from class: AbstractResource
This 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:
exists in interface Resource
Overrides:
exists in class AbstractResource

isReadable

public boolean isReadable()
Description copied from class: AbstractResource
This implementation always returns true.

Specified by:
isReadable in interface Resource
Overrides:
isReadable in class AbstractResource
See Also:
Resource.getInputStream()

contentLength

public long contentLength()
                   throws java.io.IOException
Description copied from class: AbstractResource
This 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:
contentLength in interface Resource
Overrides:
contentLength in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
See Also:
Resource.getInputStream()

lastModified

public long lastModified()
                  throws java.io.IOException
Description copied from class: AbstractResource
This implementation checks the timestamp of the underlying File, if available.

Specified by:
lastModified in interface Resource
Overrides:
lastModified in class AbstractResource
Throws:
java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
See Also:
AbstractResource.getFileForLastModifiedCheck()

Spring Framework