Interface ResourceFinder

All Known Implementing Classes:
AbstractResourceFinder, DatabaseResources, MemoryResources, ResourceFinderClasspath, ResourceFinderDirectories, ResourceFinderGroup

public interface ResourceFinder
This interface defines the methods that classes with ResourceFinder functionalities have to implement.

A ResourceFinder provides an abstract way of working with resources. According to a name, a resource can be searched for and its location is returned as an URL object.

It is also possible to obtain a stream to read the resource's content, to retrieve all its contents as a String and to obtain the modification time of the resource.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves the complete content of the resource that corresponds to the provided name.
    getContent(String name, String encoding)
    Retrieves the complete content of the resource that corresponds to the provided name.
    getContent(URL resource)
    Retrieves the complete content of the provided resource.
    getContent(URL resource, String encoding)
    Retrieves the complete content of the provided resource.
    long
    Retrieves the modification time of the resource that corresponds to the provided name.
    long
    Retrieves the modification time of the provided resource.
    Retrieves the resource that corresponds to the provided name.
    <ResultType>
    ResultType
    useStream(String name, InputStreamUser<ResultType,?> user)
    Returns a stream that can be used to read the contents of the resource that corresponds to the provided name.
    <ResultType>
    ResultType
    useStream(URL resource, InputStreamUser<ResultType,?> user)
    Returns a stream that can be used to read the contents of the provided resource.
  • Method Details

    • getResource

      URL getResource(String name)
      Retrieves the resource that corresponds to the provided name.

      This method never throws an exception, but returns null in case of an exception.

      Parameters:
      name - the name of the resource to retrieve
      Returns:
      the URL object that corresponds to the provided name; or

      null if the resource couldn't be found or if an error occurred.

      Since:
      1.0
    • useStream

      <ResultType> ResultType useStream(String name, InputStreamUser<ResultType,?> user) throws ResourceFinderErrorException, InnerClassException
      Returns a stream that can be used to read the contents of the resource that corresponds to the provided name.
      Parameters:
      name - the name of the resource to retrieve
      user - an instance of InputStreamUser that contains the logic that will be executed with this stream
      Returns:
      the return value from the useInputStream method of the provided InputStreamUser instance
      Throws:
      ResourceFinderErrorException - when an error occurred during the creation or opening of the stream.
      InnerClassException - when errors occurs inside the InputStreamUser
      Since:
      1.0
      See Also:
    • useStream

      <ResultType> ResultType useStream(URL resource, InputStreamUser<ResultType,?> user) throws ResourceFinderErrorException, InnerClassException
      Returns a stream that can be used to read the contents of the provided resource.
      Parameters:
      resource - the resource to retrieve
      user - an instance of InputStreamUser that contains the logic that will be executed with this stream
      Returns:
      the return value from the useInputStream method of the provided InputStreamUser instance
      Throws:
      ResourceFinderErrorException - when an error occurred during the creation or opening of the stream.
      InnerClassException - when errors occurs inside the InputStreamUser
      Since:
      1.0
      See Also:
    • getContent

      String getContent(String name) throws ResourceFinderErrorException
      Retrieves the complete content of the resource that corresponds to the provided name. The content will be read into a string by using the platform's default encoding.
      Parameters:
      name - the name of the resource to retrieve
      Returns:
      a String object that contains the complete content of the resource with the provided name; or

      null if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the content.
      Since:
      1.0
      See Also:
    • getContent

      String getContent(String name, String encoding) throws ResourceFinderErrorException
      Retrieves the complete content of the resource that corresponds to the provided name.
      Parameters:
      name - the name of the resource to retrieve the content from
      encoding - the encoding that should be used to read the content
      Returns:
      a String object that contains the complete content of the resource with the provided name; or

      null if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
      Since:
      1.0
      See Also:
    • getContent

      String getContent(URL resource) throws ResourceFinderErrorException
      Retrieves the complete content of the provided resource. The content will be read into a string by using the platform's default encoding.
      Parameters:
      resource - the resource to retrieve the content from
      Returns:
      a String object that contains the complete content of the resource with the provided name; or

      null if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
      Since:
      1.0
      See Also:
    • getContent

      String getContent(URL resource, String encoding) throws ResourceFinderErrorException
      Retrieves the complete content of the provided resource.
      Parameters:
      resource - the resource to retrieve the content from
      encoding - the encoding that should be used to read the content
      Returns:
      a String object that contains the complete content of the resource with the provided name; or

      null if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
      Since:
      1.0
      See Also:
    • getModificationTime

      long getModificationTime(String name) throws ResourceFinderErrorException
      Retrieves the modification time of the resource that corresponds to the provided name.
      Parameters:
      name - the name of the resource to retrieve
      Returns:
      a positive long with the modification time in milliseconds; or

      -1 if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the modification time.
      Since:
      1.0
      See Also:
    • getModificationTime

      long getModificationTime(URL resource) throws ResourceFinderErrorException
      Retrieves the modification time of the provided resource.
      Parameters:
      resource - the resource to retrieve the modification time from
      Returns:
      a positive long with the modification time in milliseconds; or

      -1 if the resource couldn't be found.

      Throws:
      ResourceFinderErrorException - when an error occurred during the retrieval of the modification time.
      Since:
      1.0
      See Also: