Package io.github.cjstehno.testthings
Class Resources
java.lang.Object
io.github.cjstehno.testthings.Resources
Some useful utilities for working with classpath resources.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyResourceTo(String resourcePath, File file) Copies the classpath resource at the specified path to the provided destination file.static voidcopyResourceTo(String resourcePath, Path path) Copies the classpath resource at the specified path to the provided destination path.static <T> TresourceDeserialized(SerdesProvider provider, String path, Class<? extends T> type) Loads the resource at the specified path as bytes and then deserializes it to the specified object type.static <T> TresourceDeserialized(String path, Class<? extends T> type) Loads the resource at the specified path as bytes and then deserializes as JSON it to the specified object type.static FileresourceFile(String path) Retrieves theFilereference to the classpath resource.static PathresourcePath(String path) Retrieves thePathreference to the classpath resource.static ReaderresourceReader(String path) Loads the specified classpath resource as aReader, specifically aBufferedReader.static InputStreamresourceStream(String path) Loads the specified classpath resource as an InputStream.static byte[]resourceToBytes(String path) Loads the specified classpath resource as a byte array.static StringresourceToString(String path) Loads the specified resource path as a UTF-8 string.static StringresourceToString(String path, Charset charset) Loads the specified resource path as a String with the specified charset.static URIresourceUri(String path) Retrieves the URI for the specified resource.static URLresourceUrl(String path) Retrieves the URL for the specified resource.static StringLoads the content at the specified classpath location as a string template.
-
Constructor Details
-
Resources
public Resources()
-
-
Method Details
-
resourceToString
Loads the specified resource path as a String with the specified charset.- Parameters:
path- the classpath resource pathcharset- the charset to be used- Returns:
- the string version of the resource
-
resourceToString
Loads the specified resource path as a UTF-8 string.- Parameters:
path- the classpath resource path- Returns:
- the string version of the resource
-
resourceToBytes
Loads the specified classpath resource as a byte array.- Parameters:
path- the resource path- Returns:
- a byte array containing the resource data
-
resourceStream
Loads the specified classpath resource as an InputStream.- Parameters:
path- the resource path- Returns:
- an InputStream containing the resource data
-
resourceReader
Loads the specified classpath resource as aReader, specifically aBufferedReader.- Parameters:
path- the resource path- Returns:
- a Reader containing the resource data
-
resourceUrl
Retrieves the URL for the specified resource.- Parameters:
path- the resource path- Returns:
- the resource URL
-
resourcePath
Retrieves thePathreference to the classpath resource.- Parameters:
path- the resource path- Returns:
- the Path reference to the classpath resource
-
resourceFile
Retrieves theFilereference to the classpath resource.- Parameters:
path- the resource path- Returns:
- the File reference to the classpath resource
-
resourceDeserialized
public static <T> T resourceDeserialized(SerdesProvider provider, String path, Class<? extends T> type) Loads the resource at the specified path as bytes and then deserializes it to the specified object type.- Type Parameters:
T- the type of the deserialized object- Parameters:
provider- the serdes providerpath- the resource pathtype- the object type- Returns:
- the deserialized object loaded from the resource path
-
resourceDeserialized
Loads the resource at the specified path as bytes and then deserializes as JSON it to the specified object type.- Type Parameters:
T- the type of the deserialized object- Parameters:
path- the resource pathtype- the object type- Returns:
- the deserialized object from the resource path content
-
resourceUri
Retrieves the URI for the specified resource.- Parameters:
path- the resource path- Returns:
- the resource URI
-
copyResourceTo
Copies the classpath resource at the specified path to the provided destination path.- Parameters:
resourcePath- the classpath resource pathpath- the destination path
-
copyResourceTo
Copies the classpath resource at the specified path to the provided destination file.- Parameters:
resourcePath- the classpath resource pathfile- the destination file
-
template
Loads the content at the specified classpath location as a string template. The replacement values are surrounded by curly braces, as{tag}. The provided map defines the replacement values.- Parameters:
path- the resource pathreplacements- the replacement values- Returns:
- the template with all defined values replaced
-