Package cern.accsoft.steering.jmad.util
Class ResourceUtil
- java.lang.Object
-
- cern.accsoft.steering.jmad.util.ResourceUtil
-
public final class ResourceUtil extends java.lang.ObjectThis class provides methods to handle resource files
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcanonicalizePath(java.lang.String path)Canonicalize a resource-path name by resolving "./" and "../", and replacing backslashes with slashes.static java.util.Collection<java.lang.String>getResourceNames(java.lang.String packageName)searches all the resources in the classpath to get a list of all the resources in the given package.static java.util.Collection<java.lang.String>getResources(java.util.regex.Pattern pattern)for all elements of java.class.path get a Collection of resources.static java.lang.StringpackageToPath(java.lang.String packageName)Converts the given package name into a path like string (e.g.static java.lang.StringprependPathOffset(java.lang.String filepath, java.lang.String offset)just adds a prefix to the path
-
-
-
Method Detail
-
getResourceNames
public static java.util.Collection<java.lang.String> getResourceNames(java.lang.String packageName)
searches all the resources in the classpath to get a list of all the resources in the given package.- Parameters:
packageName- the package name in which to search for the resources.- Returns:
- the names of the resources (without leading package names)
-
prependPathOffset
public static java.lang.String prependPathOffset(java.lang.String filepath, java.lang.String offset)just adds a prefix to the path- Parameters:
filepath- the path to which to add the prefixoffset- the offset to add as prefix- Returns:
- the whole path
-
canonicalizePath
public static java.lang.String canonicalizePath(java.lang.String path)
Canonicalize a resource-path name by resolving "./" and "../", and replacing backslashes with slashes.- Parameters:
path- the path- Returns:
- a canonical representation of the path
-
packageToPath
public static java.lang.String packageToPath(java.lang.String packageName)
Converts the given package name into a path like string (e.g. "a.java.pkg" is converted to "a/java/pkg"). Hereby always slashes ("/") are used and not the system file separator.- Parameters:
packageName- the package name to convert- Returns:
- the converted package name as path represention
-
getResources
public static java.util.Collection<java.lang.String> getResources(java.util.regex.Pattern pattern)
for all elements of java.class.path get a Collection of resources. All ressources can be found with:Pattern pattern = Pattern.compile(".*");- Parameters:
pattern- the pattern to match- Returns:
- the resources in the order they are found
-
-