Class Resources


  • public class Resources
    extends Object
    • Constructor Detail

      • Resources

        protected Resources()
    • Method Detail

      • exists

        public static boolean exists​(@NonNull
                                     @NonNull String resourcePath)
        Check if the specified resource exists (can be resolved by any method) hence can be loaded by asFile(String) or asStream(String)
        Parameters:
        resourcePath - Path of the resource to be resolved
        Returns:
        Whether the resource can be resolved or not
      • asFile

        public static File asFile​(@NonNull
                                  @NonNull String resourcePath)
        Get the specified resource as a local file. If it cannot be found (i.e., exists(String) returns false) this method will throw an exception.
        Parameters:
        resourcePath - Path of the resource to get
        Returns:
        Resource file
      • asStream

        public static InputStream asStream​(@NonNull
                                           @NonNull String resourcePath)
        Get the specified resource as an input stream.
        If it cannot be found (i.e., exists(String) returns false) this method will throw an exception.
        Parameters:
        resourcePath - Path of the resource to get
        Returns:
        Resource stream
      • copyDirectory

        public static void copyDirectory​(@NonNull
                                         @NonNull String directoryPath,
                                         @NonNull
                                         @NonNull File destinationDir)
        Copy the contents of the specified directory (path) to the specified destination directory, resolving any resources in the process
        Parameters:
        directoryPath - Directory to copy contents of
        destinationDir - Destination
      • normalizePath

        public static String normalizePath​(String path)
        Normalize the path that may be a resource reference. For example: "someDir/myFile.zip.resource_reference" --> "someDir/myFile.zip" Returns null if the file cannot be resolved. If the file is not a reference, the original path is returned
      • resourceExists

        protected boolean resourceExists​(String resourcePath)
      • getAsFile

        protected File getAsFile​(String resourcePath)
      • copyDir

        public void copyDir​(String directoryPath,
                            File destinationDir)