public class ResourceLoader
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
java.io.File |
copyToTempDirectory(java.lang.String relativePath,
java.lang.Class outsideClass)
Copies a file into a temporary directory regardless of
if it is in a JAR or not.
|
static java.io.File |
createMainTempDirectory()
Creates the main temporary directory for resource-loader.
|
java.io.File |
extractFromWithinAJarFile(java.net.URL jarPath,
java.io.File mainTempDir,
java.lang.String relativePath) |
static java.net.URL |
getThePathToTheJarWeAreIn(java.lang.Class<?> c)
Gets the base location of the given class.
|
protected boolean |
isPosixCompliant()
Is the system we're running on Posix compliant?
|
void |
requestDeletion(java.io.File file)
Mark the file or directory as "to be deleted".
|
java.io.File |
setPermissions(java.io.File file)
Sets permissions on a file or directory.
|
java.io.File |
setPermissions(java.io.File file,
java.util.Set<java.nio.file.attribute.PosixFilePermission> filePermissions)
Sets a file or directory's permissions.
|
static java.io.File |
urlToFile(java.lang.String url)
Converts the given URL string to its corresponding
File. |
static java.io.File |
urlToFile(java.net.URL url)
Converts the given
URL to its corresponding File. |
public java.io.File copyToTempDirectory(java.lang.String relativePath,
java.lang.Class outsideClass)
throws java.io.IOException,
java.net.URISyntaxException
relativePath - A relative path to a file or directory
relative to the resources folder.java.io.IOException - If at any point processing of the resource file fails.java.net.URISyntaxException - If cannot find the resource file.public java.io.File extractFromWithinAJarFile(java.net.URL jarPath,
java.io.File mainTempDir,
java.lang.String relativePath)
throws java.io.IOException,
java.net.URISyntaxException
java.io.IOExceptionjava.net.URISyntaxExceptionpublic static java.io.File createMainTempDirectory()
throws java.io.IOException
java.io.IOException - Could not create a temporary directorypublic java.io.File setPermissions(java.io.File file)
throws java.io.IOException
file - A file to set global permissions onjava.io.IOException - Could not set permissionssetPermissions(File, Set)public java.io.File setPermissions(java.io.File file,
java.util.Set<java.nio.file.attribute.PosixFilePermission> filePermissions)
throws java.io.IOException
file - The file to set new permissions on.filePermissions - New permissions.java.io.IOExceptionpublic void requestDeletion(java.io.File file)
file - The file or directory to be deleted.protected boolean isPosixCompliant()
public static java.net.URL getThePathToTheJarWeAreIn(java.lang.Class<?> c)
If the class is directly on the file system (e.g., "/path/to/my/package/MyClass.class") then it will return the base directory (e.g., "file:/path/to").
If the class is within a JAR file (e.g., "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the path to the JAR (e.g., "file:/path/to/my-jar.jar").
c - The class whose location is desired.public static java.io.File urlToFile(java.net.URL url)
URL to its corresponding File.
From SciJava class.
This method is similar to calling new File(url.toURI()) except that
it also handles "jar:file:" URLs, returning the path to the JAR file.
url - The URL to convert.FileInputStreamjava.lang.IllegalArgumentException - if the URL does not correspond to a file.public static java.io.File urlToFile(java.lang.String url)
File.
From SciJava class.url - The URL to convert.FileInputStreamjava.lang.IllegalArgumentException - if the URL does not correspond to a file.