Class ResourceUtils

java.lang.Object
io.extact.rms.platform.util.ResourceUtils

public class ResourceUtils extends Object
Class resource utility.
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • findResoucePathUnder

      public static List<URL> findResoucePathUnder(String targetDir) throws IOException
      Get the class resource under the path specified by the argument by URL. Search also inside the jar file.Also, if a file is specified in the argument path, the URL of the corresponding file is returned. The following usage example
       classpath-resources =>
           jar:file:/C:/foo/bar/baz.jar!/META-INF/MANIFEST.MF
           jar:file:/C:/foo/bar/baz.jar!/mpconfig/a.properties
           jar:file:/C:/foo/bar/baz.jar!/mpconfig/b.properties
           file:/C:/for/bar/target/classes/message.properties
           file:/C:/for/bar/target/classes/mpconfig/c.text
       targetDir => mpconfig
       return url =>
           jar:file:/C:/foo/bar/baz.jar!/mpconfig/a.properties
           jar:file:/C:/foo/bar/baz.jar!/mpconfig/b.properties
           file:/C:/for/bar/target/classes/mpconfig/c.text
       
      Parameters:
      targetDir - Path to search for resources. Do not add `/` at the beginning
      Returns:
      URL of the target resource. Returns an empty list if not applicable.
      Throws:
      IOException - IO error occurs.
    • findResoucePathUnder

      public static List<URL> findResoucePathUnder(String targetDir, Predicate<Object> fileFilter, ClassLoader classLoader) throws IOException
      Get the class resource under the path specified by the argument by URL.
      Throws:
      IOException
      See Also:
    • toJarFileFromResourceUrl

      public static File toJarFileFromResourceUrl(URL resourceUrl)
      Make a jar file on the file system based on the resource URL in the jar.
      Parameters:
      resourceUrl - Resource URL in the jar.
      Returns:
      File object in jar.
    • extractFilePathStringOfUrl

      public static String extractFilePathStringOfUrl(URL resourceUrl)
      Extract the character string of the Jar file path part from the resource URL in the jar.
      Parameters:
      resourceUrl - Resource URL in the jar.
      Returns:
      String of FilePath.