java.lang.Object
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
All Implemented Interfaces:
InputStreamSource, Resource
Direct Known Subclasses:
AbstractFileResolvingResource, FileSystemResource, VfsResource

public abstract class AbstractResource extends Object implements Resource
Convenience base class for {link Resource} implementations, pre-implementing typical behavior.

The "exists" method will check whether a File or InputStream can be opened; "isOpen" will always return false; "getURL" and "getFile" throw an exception; and "toString" will return the description.

Since:
28.12.2003
Author:
Juergen Hoeller, Sam Brannen
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    This method reads the entire InputStream to determine the content length.
    createRelative(String relativePath)
    This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
    boolean
    equals(Object other)
    This implementation compares description strings.
    boolean
    This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.
    This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to an absolute file path.
    This implementation always returns null, assuming that this resource type does not have a filename.
    This implementation builds a URI based on the URL returned by {link #getURL()}.
    This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.
    int
    This implementation returns the description's hash code.
    boolean
    This implementation always returns false.
    boolean
    This implementation always returns false.
    This implementation returns the description of this resource.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface nl.basjes.parse.useragent.utils.springframework.core.io.InputStreamSource

    getInputStream

    Methods inherited from interface nl.basjes.parse.useragent.utils.springframework.core.io.Resource

    getDescription
  • Constructor Details

    • AbstractResource

      public AbstractResource()
  • Method Details

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

      public boolean isFile()
      This implementation always returns false.
      Specified by:
      isFile 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 a descriptor
    • getURI

      public URI getURI() throws IOException
      This implementation builds a URI based on the URL returned by {link #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 a 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:
      FileNotFoundException - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
      IOException - in case of general resolution/reading failures see #getInputStream()
    • contentLength

      public long contentLength() throws IOException
      This method reads the entire InputStream to determine the content length.

      For a custom subclass of InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, e.g. checking File length, or possibly simply returning -1 if the stream can only be read once. see #getInputStream()

      Specified by:
      contentLength in interface Resource
      Throws:
      IOException - if the resource cannot be resolved (in the file system or as some other known physical resource type)
    • 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

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

      public boolean equals(@Nullable Object other)
      This implementation compares description strings. see #getDescription()
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      This implementation returns the description's hash code. see #getDescription()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      This implementation returns the description of this resource. see #getDescription()
      Overrides:
      toString in class Object