Package rife.resources
Class MemoryResources
java.lang.Object
rife.resources.AbstractResourceFinder
rife.resources.MemoryResources
- All Implemented Interfaces:
ResourceFinder,ResourceWriter
This class offers
ResourceFinder and ResourceWriter
capabilities for resources that are stored in a memory.- Since:
- 1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResource(String name, String content) Adds a resource with the provided name and content.getContent(URL resource, String encoding) Retrieves the complete content of the provided resource.longgetModificationTime(URL resource) Retrieves the modification time of the provided resource.getResource(String name) Retrieves the resource that corresponds to the provided name.booleanremoveResource(String name) Removes the resource with the provided name.booleanupdateResource(String name, String content) Updates the content of the resource with the provided name.<ResultType>
ResultTypeuseStream(URL resource, InputStreamUser<ResultType, ?> user) Returns a stream that can be used to read the contents of the provided resource.Methods inherited from class rife.resources.AbstractResourceFinder
getContent, getContent, getContent, getModificationTime, useStream
-
Constructor Details
-
MemoryResources
public MemoryResources()Creates a new instance.- Since:
- 1.0
-
-
Method Details
-
addResource
Description copied from interface:ResourceWriterAdds a resource with the provided name and content.- Specified by:
addResourcein interfaceResourceWriter- Parameters:
name- the name of the resourcecontent- the content of the resource
-
updateResource
Description copied from interface:ResourceWriterUpdates the content of the resource with the provided name.- Specified by:
updateResourcein interfaceResourceWriter- Parameters:
name- the name of the resourcecontent- the content of the resource- Returns:
truewhen the resource was updated;falseotherwise
-
removeResource
Description copied from interface:ResourceWriterRemoves the resource with the provided name.- Specified by:
removeResourcein interfaceResourceWriter- Parameters:
name- the name of the resource- Returns:
truewhen the resource was removed;falseotherwise
-
getResource
Description copied from interface:ResourceFinderRetrieves the resource that corresponds to the provided name.This method never throws an exception, but returns
nullin case of an exception.- Specified by:
getResourcein interfaceResourceFinder- Parameters:
name- the name of the resource to retrieve- Returns:
- the
URLobject that corresponds to the provided name; ornullif the resource couldn't be found or if an error occurred.
-
useStream
public <ResultType> ResultType useStream(URL resource, InputStreamUser<ResultType, ?> user) throws ResourceFinderErrorException, InnerClassExceptionDescription copied from interface:ResourceFinderReturns a stream that can be used to read the contents of the provided resource.- Specified by:
useStreamin interfaceResourceFinder- Parameters:
resource- the resource to retrieveuser- an instance ofInputStreamUserthat contains the logic that will be executed with this stream- Returns:
- the return value from the
useInputStreammethod of the providedInputStreamUserinstance - 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:ResourceFinderRetrieves the complete content of the provided resource.- Specified by:
getContentin interfaceResourceFinder- Parameters:
resource- the resource to retrieve the content fromencoding- the encoding that should be used to read the content- Returns:
- a
Stringobject that contains the complete content of the resource with the provided name; ornullif the resource couldn't be found. - See Also:
-
getModificationTime
Description copied from interface:ResourceFinderRetrieves the modification time of the provided resource.- Specified by:
getModificationTimein interfaceResourceFinder- Parameters:
resource- the resource to retrieve the modification time from- Returns:
- a positive
longwith the modification time in milliseconds; or-1if the resource couldn't be found. - See Also:
-