Class ExternalResource

All Implemented Interfaces:
InputStreamResource, Resource

public class ExternalResource extends AbstractFileResolvingResource
Created by Per Wendel on 2014-05-18.
  • Field Details

    • file

      private final File file
  • Constructor Details

    • ExternalResource

      public ExternalResource(String path)
      Constructor
      Parameters:
      path - the path to the external resource
  • Method Details

    • isDirectory

      public boolean isDirectory()
      Tests whether the file denoted by this abstract pathname is a directory.
      Returns:
      true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
    • 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 AbstractFileResolvingResource
      Returns:
      if exists
    • getDescription

      public String getDescription()
      Returns:
      a description for this resource, to be used for error output when working with the resource.

      Implementations are also encouraged to return this value from their toString method.

      See Also:
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: InputStreamResource
      Return an InputStream.

      It is expected that each call creates a fresh stream.

      This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

      Returns:
      the input stream for the underlying resource (must not be null)
      Throws:
      IOException - if the stream could not be opened
    • getURL

      public URL getURL() throws IOException
      This implementation returns a URL for the underlying class path resource.
      Specified by:
      getURL in interface Resource
      Overrides:
      getURL in class AbstractResource
      Returns:
      a URL handle for this resource.
      Throws:
      IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
      See Also:
    • getPath

      public String getPath()
      Gets the path
      Returns:
      the path
    • getFilename

      public String getFilename()
      This implementation returns the name of the file that this external resource refers to.
      Specified by:
      getFilename in interface Resource
      Overrides:
      getFilename in class AbstractResource
      Returns:
      the file name.
      See Also: