org.springframework.core.io

Class AbstractFileResolvingResource

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      long contentLength()
      This implementation reads the entire InputStream to calculate the content length.
      protected void customizeConnection(java.net.HttpURLConnection con)
      Customize the given HttpURLConnection, obtained in the course of an exists(), contentLength() or lastModified() call.
      protected void customizeConnection(java.net.URLConnection con)
      Customize the given URLConnection, obtained in the course of an exists(), contentLength() or lastModified() call.
      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 given URI-identified 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 isFile()
      This implementation always returns false.
      protected boolean isFile(java.net.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.
      boolean isReadable()
      This implementation always returns true for a resource that exists (revised as of 5.1).
      long lastModified()
      This implementation checks the timestamp of the underlying File, if available.
      java.nio.channels.ReadableByteChannel readableChannel()
      This implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractFileResolvingResource

        public AbstractFileResolvingResource()
    • Method Detail

      • 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
      • 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.FileNotFoundException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
        java.io.IOException - in case of general resolution/reading failures
        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.FileNotFoundException - if the resource cannot be resolved as an absolute file path, i.e. is not available in a file system
        java.io.IOException - in case of general resolution/reading failures
      • isFile

        protected boolean isFile(java.net.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.
        Since:
        5.0
        See Also:
        getFile(URI)
      • getFile

        protected java.io.File getFile(java.net.URI uri)
                                throws java.io.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:
        java.io.IOException
        See Also:
        ResourceUtils.getFile(java.net.URI, String)
      • readableChannel

        public java.nio.channels.ReadableByteChannel readableChannel()
                                                              throws java.io.IOException
        This implementation returns a FileChannel for the given URI-identified resource, provided that it refers to a file in the file system.
        Specified by:
        readableChannel in interface Resource
        Overrides:
        readableChannel in class AbstractResource
        Returns:
        the byte channel for the underlying resource (must not be null)
        Throws:
        java.io.FileNotFoundException - if the underlying resource doesn't exist
        java.io.IOException - if the content channel could not be opened
        Since:
        5.0
        See Also:
        getFile()
      • 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:
        InputStreamSource.getInputStream()
      • customizeConnection

        protected void customizeConnection(java.net.HttpURLConnection con)
                                    throws java.io.IOException
        Customize the given HttpURLConnection, obtained in the course of an exists(), contentLength() or lastModified() call.

        Sets request method "HEAD" by default. Can be overridden in subclasses.

        Parameters:
        con - the HttpURLConnection to customize
        Throws:
        java.io.IOException - if thrown from HttpURLConnection methods