Package net.solarnetwork.service.support
Class TextResourceCache
java.lang.Object
net.solarnetwork.service.support.TextResourceCache
A simple text resource cache.
All loaded resources are cached in memory.
- Since:
- 1.67
- Version:
- 1.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TextResourceCacheA global, thread-safe, shared instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetResourceAsString(String resourceName, Class<?> clazz) Get a text resource as a string.getResourceAsString(String resourceName, Class<?> clazz, Map<String, ?> templateVariables) Get a text resource as a string.getResourceAsString(String resourceName, Class<?> clazz, Pattern skip) Get a text resource as a string.getResourceAsString(String resourceName, Class<?> clazz, Pattern skip, Map<String, ?> templateVariables) Get a text resource as a string.
-
Field Details
-
INSTANCE
A global, thread-safe, shared instance.
-
-
Constructor Details
-
TextResourceCache
public TextResourceCache()Constructor.This uses a
HashMapfor the cache, which is not thread safe. -
TextResourceCache
Constructor.- Parameters:
cache- the cache to use; for thread safety use something like aConcurrentMap
-
-
Method Details
-
getResourceAsString
Get a text resource as a string.- Parameters:
resourceName- the resource to loadclazz- the Class to load the resource from- Returns:
- the text
- Throws:
RuntimeException- if the resource cannot be loaded
-
getResourceAsString
public String getResourceAsString(String resourceName, Class<?> clazz, Map<String, ?> templateVariables) Get a text resource as a string.- Parameters:
resourceName- the resource to loadclazz- the Class to load the resource fromtemplateVariables- optional template variables to substitute in the loaded resource- Returns:
- the text
- Throws:
RuntimeException- if the resource cannot be loaded
-
getResourceAsString
Get a text resource as a string.- Parameters:
resourceName- the resource to loadclazz- the Class to load the resource fromskip- an optional pattern that will be used to match against lines; matches will be left out of the string used to match- Returns:
- the text
- Throws:
RuntimeException- if the resource cannot be loaded
-
getResourceAsString
public String getResourceAsString(String resourceName, Class<?> clazz, Pattern skip, Map<String, ?> templateVariables) Get a text resource as a string.Note that the final, template resolved text is cached in memory.
- Parameters:
resourceName- the resource to loadclazz- the Class to load the resource fromskip- an optional pattern that will be used to match against lines; matches will be left out of the string used to matchtemplateVariables- optional template variables to substitute in the loaded resource- Returns:
- the text
- Throws:
RuntimeException- if the resource cannot be loaded- See Also:
-