Class ClassPathUtils
The methods of this class do not allow null inputs.
- Since:
- 3.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringgetPackageName(Class<?> context) Gets the package name of the context class.static StringpackageToPath(String path) Converts a package name to a Java path ('/').static StringpathToPackage(String path) Converts a Java path ('/') to a package name.private static StringQualifies a resource name with a prefix and separator.static StringtoFullyQualifiedName(Class<?> context, String resourceName) Returns the fully qualified name for the resource with nameresourceNamerelative to the given context.static StringtoFullyQualifiedName(Package context, String resourceName) Returns the fully qualified name for the resource with nameresourceNamerelative to the given context.static StringtoFullyQualifiedPath(Class<?> context, String resourceName) Returns the fully qualified path for the resource with nameresourceNamerelative to the given context.static StringtoFullyQualifiedPath(Package context, String resourceName) Returns the fully qualified path for the resource with nameresourceNamerelative to the given context.
-
Constructor Details
-
ClassPathUtils
Deprecated.TODO Make private in 4.0.ClassPathUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asClassPathUtils.toFullyQualifiedName(MyClass.class, "MyClass.properties");.This constructor is public to permit tools that require a JavaBean instance to operate.
-
-
Method Details
-
getPackageName
Gets the package name of the context class.Returns an empty string for an unnamed package, including when
Class.getPackage()returnsnullon Java 8.- Parameters:
context- The context class, must not benull.- Returns:
- The package name, or an empty string for an unnamed package.
- Throws:
NullPointerException- Thrown ifcontextis null, represents an array, a primitive type orvoid, or represents a named class whose package is unavailable.
-
packageToPath
Converts a package name to a Java path ('/').- Parameters:
path- The source path.- Returns:
- A package name.
- Throws:
NullPointerException- Thrown ifpathis null.- Since:
- 3.13.0
-
pathToPackage
Converts a Java path ('/') to a package name.- Parameters:
path- The source path.- Returns:
- A package name.
- Throws:
NullPointerException- Thrown ifpathis null.- Since:
- 3.13.0
-
qualify
Qualifies a resource name with a prefix and separator.Returns
resourceNameunchanged when the prefix is empty.- Parameters:
prefix- The package name or path, must not benull.resourceName- The resource name, validated as non-null by the caller.separator- The separator between the prefix and resource name.- Returns:
- The qualified resource name, or the unchanged resource name when the prefix is empty.
- Throws:
NullPointerException- Thrown ifprefixis null.
-
toFullyQualifiedName
Returns the fully qualified name for the resource with nameresourceNamerelative to the given context.Note that this method does not check whether the resource actually exists. It only constructs the name. Null inputs are not allowed.
If the context class is in an unnamed package, returns
resourceNameunchanged.ClassPathUtils.toFullyQualifiedName(StringUtils.class, "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
- Parameters:
context- The context for constructing the name.resourceName- The resource name to construct the fully qualified name for.- Returns:
- The fully qualified name of the resource with name
resourceName. - Throws:
NullPointerException- Thrown if eithercontextorresourceNameis null, ifcontextrepresents an array, a primitive type orvoid, or if it represents a named class whose package is unavailable.
-
toFullyQualifiedName
Returns the fully qualified name for the resource with nameresourceNamerelative to the given context.Note that this method does not check whether the resource actually exists. It only constructs the name. Null inputs are not allowed.
If the context is an unnamed package, returns
resourceNameunchanged.ClassPathUtils.toFullyQualifiedName(StringUtils.class.getPackage(), "StringUtils.properties") = "org.apache.commons.lang3.StringUtils.properties"
- Parameters:
context- The context for constructing the name.resourceName- The resource name to construct the fully qualified name for.- Returns:
- The fully qualified name of the resource with name
resourceName. - Throws:
NullPointerException- Thrown if eithercontextorresourceNameis null.
-
toFullyQualifiedPath
Returns the fully qualified path for the resource with nameresourceNamerelative to the given context.Note that this method does not check whether the resource actually exists. It only constructs the path. Null inputs are not allowed.
If the context class is in an unnamed package, returns
resourceNameunchanged.ClassPathUtils.toFullyQualifiedPath(StringUtils.class, "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
- Parameters:
context- The context for constructing the path.resourceName- The resource name to construct the fully qualified path for.- Returns:
- The fully qualified path of the resource with name
resourceName. - Throws:
NullPointerException- Thrown if eithercontextorresourceNameis null, ifcontextrepresents an array, a primitive type orvoid, or if it represents a named class whose package is unavailable.
-
toFullyQualifiedPath
Returns the fully qualified path for the resource with nameresourceNamerelative to the given context.Note that this method does not check whether the resource actually exists. It only constructs the path. Null inputs are not allowed.
If the context is an unnamed package, returns
resourceNameunchanged.ClassPathUtils.toFullyQualifiedPath(StringUtils.class.getPackage(), "StringUtils.properties") = "org/apache/commons/lang3/StringUtils.properties"
- Parameters:
context- The context for constructing the path.resourceName- The resource name to construct the fully qualified path for.- Returns:
- The fully qualified path of the resource with name
resourceName. - Throws:
NullPointerException- Thrown if eithercontextorresourceNameis null.
-