Class InjectResources
- java.lang.Object
-
- com.adelean.inject.resources.core.InjectResources
-
public final class InjectResources extends java.lang.ObjectInjectResourcesis a small fluid Java DSL that simplifies loading and parsing of resource files.This library takes care of opening/closing of streams and handles exceptions.
Example:
String text = resource() .withPath("/com/adelean/junit/jupiter", "resource.txt") .asText() .text();Or with resources content parsing:
// Assuming there is object 'reader' able to parse properties content in variable of type DbConnection DbConnection dbConnection = resource() .withPath("/com/adelean/junit/jupiter", "db.properties") .asInputStream() .parseChecked(reader::readValue);
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource.ResourceOnClassloaderonClassLoader(java.lang.ClassLoader classLoader)Returns builder for resource that is present on a classpath ofclassLoaderargument.Resource.ResourceOnClassloaderonClassLoaderOf(java.lang.Class<?> clazz)Returns builder for resource that is present on a classpath ofClassLoaderofclazzargument.static InjectResourcesresource()Entry point ofInjectResourcess fluid Java DSL.ResourcewithPath(java.lang.String firstPathToken, java.lang.String... otherTokens)Returns builder for resource with definedpathon a classpath of the threads contextClassLoader.
-
-
-
Method Detail
-
resource
public static InjectResources resource()
Entry point ofInjectResourcess fluid Java DSL.- Returns:
InjectResourcesresource factory
-
onClassLoaderOf
public Resource.ResourceOnClassloader onClassLoaderOf(java.lang.Class<?> clazz)
Returns builder for resource that is present on a classpath ofClassLoaderofclazzargument.- Parameters:
clazz- class on a classpath where requested resource is present- Returns:
Resource.ResourceOnClassloaderresource factory
-
onClassLoader
public Resource.ResourceOnClassloader onClassLoader(java.lang.ClassLoader classLoader)
Returns builder for resource that is present on a classpath ofclassLoaderargument.- Parameters:
classLoader- classloader from a classpath where requested resource is present- Returns:
Resource.ResourceOnClassloaderresource factory
-
withPath
public Resource withPath(java.lang.String firstPathToken, java.lang.String... otherTokens)
Returns builder for resource with definedpathon a classpath of the threads contextClassLoader.Those two operations are equivalent:
withPath("/com/adelean/junit/jupiter/resource.txt") // equivalent to withPath("/com/adelean/junit/jupiter", "resource.txt")- Parameters:
firstPathToken- path of resource, it least one tokenotherTokens- path of resource, allows multiple tokens- Returns:
Resourceresource builder
-
-