public final class FileLocator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
CTAKES_HOME
$CTAKES_HOME is an environment variable that may be set to indicate
the absolute directory path of the ctakes installation
|
private static Logger |
LOGGER |
Modifier | Constructor and Description |
---|---|
private |
FileLocator() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
createDiscoveredPath(java.lang.String relativePath,
java.io.File file,
java.lang.String locationText)
Logs a debug message before returning the absolute path of a file derived from some relative path
|
static java.io.InputStream |
getAsStream(java.lang.String location) |
static java.lang.String |
getFullPath(java.lang.String relativePath)
Attempts to discover the real location of a file pointed to by relativePath.
|
static java.io.File |
locateFile(java.lang.String location)
Where a Stream is usable, use
getAsStream(String) . |
private static java.io.File |
locateOnClasspath(java.lang.String relativePath)
Check the java classpath for the presence of a file pointed to by relativePath
|
private static final Logger LOGGER
private static final java.lang.String CTAKES_HOME
public static java.io.InputStream getAsStream(java.lang.String location) throws java.io.FileNotFoundException
java.io.FileNotFoundException
public static java.io.File locateFile(java.lang.String location) throws java.io.FileNotFoundException
getAsStream(String)
.
Where a path String is usable, use getFullPath(String)
.java.io.FileNotFoundException
private static java.lang.String createDiscoveredPath(java.lang.String relativePath, java.io.File file, java.lang.String locationText)
relativePath
- relative path of some filefile
- the actual file addressed by relative pathlocationText
- description of where file exists relative to relativePathpublic static java.lang.String getFullPath(java.lang.String relativePath) throws java.io.FileNotFoundException
1. By checking to see if the provided relative path is actually an absolute path 2. By checking within the ClassPath 3. By checking directly under the current working directory 4. By checking under $CTAKES_HOME 5. By traversing above the current working directory. Useful when running under a module directory in an IDE Example: cwd = /usr/bin/ctakes/ctakes-module , relativePath = ctakes-other-module/more/file.ext The directory above cwd /usr/bin/ctakes will be checked for containment of the relative path If /usr/bin/ctakes/ctakes-other-module/more/file.txt exists then that is returned 6. By traversing above the current working directory and under a subdirectory ctakes/ Example: cwd = /usr/bin/my_custom_ctakes/my_ctakes-module , relativePath = ctakes-other-module/more/file.ext The directory above cwd /usr/bin will be checked for containment of ctakes/ plus the relative path If /usr/bin/ctakes/ctakes-other-module/more/file.txt exists then that is returned
relativePath
- some relative path to a filejava.io.FileNotFoundException
- if the file cannot be foundprivate static java.io.File locateOnClasspath(java.lang.String relativePath) throws java.io.FileNotFoundException, java.net.URISyntaxException
relativePath
- some relative path to a filejava.io.FileNotFoundException
- if the file is not found in the classpathjava.net.URISyntaxException
- if the discovered file cannot be converted into a URI