Class AbstractFileResolvingResource

  • All Implemented Interfaces:
    Resource
    Direct Known Subclasses:
    ClassPathResource, UrlResource

    public abstract class AbstractFileResolvingResource
    extends java.lang.Object
    implements Resource
    Abstract base class for resources which resolve URLs into File references, such as org.springframework.core.io.UrlResource or org.springframework.core.io.ClassPathResource.

    Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.

    Since:
    3.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long contentLength()
      Determine the content length for this resource.
      boolean exists()
      Return whether this resource actually exists in physical form.
      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()
      Return whether the contents of this resource can be read, e.g.
      long lastModified()
      Determine the last-modified timestamp for this resource.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
        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
      • 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).
        Throws:
        java.io.IOException
      • 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
      • exists

        public boolean exists()
        Description copied from interface: Resource
        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
      • isReadable

        public boolean isReadable()
        Description copied from interface: Resource
        Return whether the contents of this resource can be read, e.g. via Resource.getInputStream() or Resource.getFile().

        Will be true for typical resource descriptors; note that actual content reading may still fail when attempted. However, a value of false is a definitive indication that the resource content cannot be read.

        Specified by:
        isReadable in interface Resource
        See Also:
        Resource.getInputStream()
      • contentLength

        public long contentLength()
                           throws java.io.IOException
        Description copied from interface: Resource
        Determine the content length for this resource.
        Specified by:
        contentLength in interface Resource
        Throws:
        java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
      • lastModified

        public long lastModified()
                          throws java.io.IOException
        Description copied from interface: Resource
        Determine the last-modified timestamp for this resource.
        Specified by:
        lastModified in interface Resource
        Throws:
        java.io.IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)