Class AbstractResource

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long contentLength()
      This implementation reads the entire InputStream to calculate the content length.
      Resource createRelative​(String relativePath)
      This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
      boolean equals​(Object obj)
      This implementation compares description strings.
      boolean exists()
      This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
      File getFile()
      This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
      protected File getFileForLastModifiedCheck()
      Determine the File to use for timestamp checking.
      String getFilename()
      This implementation always returns null, assuming that this resource type does not have a filename.
      URI getURI()
      This implementation builds a URI based on the URL returned by getURL().
      URL getURL()
      This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
      int hashCode()
      This implementation returns the description's hash code.
      boolean isOpen()
      This implementation always returns false.
      boolean isReadable()
      This implementation always returns true.
      long lastModified()
      This implementation checks the timestamp of the underlying File, if available.
      String toString()
      This implementation returns the description of this resource.
    • Constructor Detail

      • AbstractResource

        public AbstractResource()
    • Method Detail

      • exists

        public boolean exists()
        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
      • isOpen

        public boolean isOpen()
        This implementation always returns false.
        Specified by:
        isOpen in interface Resource
      • getURL

        public URL getURL()
                   throws IOException
        This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
        Specified by:
        getURL in interface Resource
        Throws:
        IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
      • getURI

        public URI getURI()
                   throws IOException
        This implementation builds a URI based on the URL returned by getURL().
        Specified by:
        getURI in interface Resource
        Throws:
        IOException - if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
      • getFile

        public File getFile()
                     throws IOException
        This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
        Specified by:
        getFile in interface 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
      • lastModified

        public long lastModified()
                          throws IOException
        This implementation checks the timestamp of the underlying File, if available.
        Specified by:
        lastModified in interface Resource
        Throws:
        IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
        See Also:
        getFileForLastModifiedCheck()
      • getFileForLastModifiedCheck

        protected File getFileForLastModifiedCheck()
                                            throws IOException
        Determine the File to use for timestamp checking.

        The default implementation delegates to getFile().

        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
      • createRelative

        public Resource createRelative​(String relativePath)
                                throws IOException
        This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
        Specified by:
        createRelative in interface Resource
        Parameters:
        relativePath - the relative path (relative to this resource)
        Returns:
        the resource handle for the relative resource
        Throws:
        IOException - if the relative resource cannot be determined
      • getFilename

        public String getFilename()
        This implementation always returns null, assuming that this resource type does not have a filename.
        Specified by:
        getFilename in interface Resource