Package rife.resources
Class AbstractResourceFinder
java.lang.Object
rife.resources.AbstractResourceFinder
- All Implemented Interfaces:
ResourceFinder
- Direct Known Subclasses:
MemoryResources
,ResourceFinderClasspath
,ResourceFinderDirectories
,ResourceFinderGroup
This abstract class offers common implementations of several
ResourceFinder
methods. This makes it easier to implement
specific ResourceFinder
classes.
All method implementations here accept resource specification as names and correctly defer the actual logic to the methods that accept resource specification as URLs.
- Since:
- 1.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetContent
(String name) 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.long
getModificationTime
(String name) Retrieves the modification time of the resource that corresponds to the provided name.<ResultType>
ResultTypeuseStream
(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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface rife.resources.ResourceFinder
getContent, getModificationTime, getResource, useStream
-
Constructor Details
-
AbstractResourceFinder
public AbstractResourceFinder()
-
-
Method Details
-
useStream
public <ResultType> ResultType useStream(String name, InputStreamUser<ResultType, ?> user) throws ResourceFinderErrorException, InnerClassExceptionDescription copied from interface:ResourceFinder
Returns a stream that can be used to read the contents of the resource that corresponds to the provided name.- Specified by:
useStream
in interfaceResourceFinder
- Parameters:
name
- the name of the resource to retrieveuser
- an instance ofInputStreamUser
that contains the logic that will be executed with this stream- Returns:
- the return value from the
useInputStream
method of the providedInputStreamUser
instance - Throws:
ResourceFinderErrorException
- when an error occurred during the creation or opening of the stream.InnerClassException
- when errors occurs inside theInputStreamUser
- See Also:
-
getContent
Description copied from interface:ResourceFinder
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.- Specified by:
getContent
in interfaceResourceFinder
- 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; ornull
if the resource couldn't be found. - Throws:
ResourceFinderErrorException
- when an error occurred during the retrieval of the content.- See Also:
-
getContent
Description copied from interface:ResourceFinder
Retrieves the complete content of the resource that corresponds to the provided name.- Specified by:
getContent
in interfaceResourceFinder
- Parameters:
name
- the name of the resource to retrieve the content fromencoding
- 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; ornull
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.- See Also:
-
getContent
Description copied from interface:ResourceFinder
Retrieves the complete content of the provided resource. The content will be read into a string by using the platform's default encoding.- Specified by:
getContent
in interfaceResourceFinder
- 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; ornull
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.- See Also:
-
getModificationTime
Description copied from interface:ResourceFinder
Retrieves the modification time of the resource that corresponds to the provided name.- Specified by:
getModificationTime
in interfaceResourceFinder
- 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.- See Also:
-