Package org.assertstruct
Class Res
java.lang.Object
org.assertstruct.Res
Class provide comfortable way to work with text data from classpath or strings.
If content is in JSON5 format it can be parsed and provided as
Template or converted to POJO class.
Res class track location of the resource and provide convenient way to load it and transform into other formats.-
Method Summary
Modifier and TypeMethodDescription<T> TProvides the content of the resource in JSON5 format converted to provided class.char[]asChars()Provides the content of the resource as a char array.asString()Provides the content of the resource as a string.Provides the content of the resource as a template.static ResCreates a new Res object from the given resource path.static ResCreates a new Res object with the given content.static ResCreate resource by autodetect type of resourcestatic Resres(@NonNull String res, StackTraceElement traceElement, AssertStructService env)
-
Method Details
-
res
-
from
Creates a new Res object from the given resource path. The path can be absolute or relative to the class executed from method Resource existence will be checked during creating, however loading will be delayed until accessed.- Parameters:
resPath- the path to the resource.- Returns:
- a new Res object representing the resource.
- Throws:
IllegalArgumentException- if the resource cannot be found
-
of
-
res
public static Res res(@NonNull @NonNull String res, StackTraceElement traceElement, AssertStructService env) -
asString
-
asChars
public char[] asChars()Provides the content of the resource as a char array.- Returns:
- the content
-
asTemplate
Provides the content of the resource as a template. Template is parsed on the first call and then cached.- Returns:
- the template
-
as
Provides the content of the resource in JSON5 format converted to provided class.- Parameters:
type- required class- Returns:
- converted content This method will work only if the resource is in JSON5 format and default JSonConverter support this conversion
-