|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.util.FileUtil
public class FileUtil
Common utility methods for working with Files.
We needed a place to refactor common File-processing idioms in JMRI code, so this class was created. It's more of a library of procedures than a real class, as (so far) all of the operations have needed no state information.
| Field Summary | |
|---|---|
static String |
FILE
Deprecated. |
static String |
HOME
Portable reference to the user's home directory. |
static String |
PREFERENCES
Portable reference to items in the JMRI user's preferences directory. |
static String |
PROGRAM
Portable reference to items in the JMRI program directory. |
static String |
RESOURCE
Deprecated. |
static char |
SEPARATOR
The portable file path component separator. |
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static void |
createDirectory(String path)
Create a directory if required. |
static URL |
fileToURL(File file)
Return the URL for a given File. |
static URL |
findExternalFilename(String path)
Get the URL of a portable filename if it can be located using findURL(java.lang.String) |
static InputStream |
findInputStream(String path)
Search for a file or JAR resource by name and return the InputStream for that file. |
static InputStream |
findInputStream(String path,
String... searchPaths)
Search for a file or JAR resource by name and return the InputStream for that file. |
static URL |
findURL(String path)
Search for a file or JAR resource by name and return the URL for that file. |
static URL |
findURL(String path,
String... searchPaths)
Search for a file or JAR resource by name and return the URL for that file. |
static String |
getAbsoluteFilename(String path)
Convert a portable filename into an absolute filename |
static String |
getExternalFilename(String pName)
Get the resource file corresponding to a name. |
static String |
getHomePath()
Get the user's home directory. |
static String |
getPortableFilename(File file)
Convert a File object to our preferred storage form. |
static String |
getPortableFilename(String filename)
Convert a filename string to our preferred storage form. |
static String |
getPreferencesPath()
Get the preferences directory. |
static String |
getProgramPath()
Get the JMRI program directory. |
static String |
getScriptsPath()
Get the path to the scripts directory. |
static String |
getUserFilesPath()
Get the user's files directory. |
static String |
getUserResourcePath()
Get the resources directory within the user's files directory. |
static JarFile |
jmriJarFile()
Get the JMRI distribution jar file. |
static void |
logFilePaths()
|
static void |
setProgramPath(File path)
Set the JMRI program directory. |
static void |
setProgramPath(String path)
Set the JMRI program directory. |
static void |
setScriptsPath(String path)
Set the path to python scripts. |
static void |
setUserFilesPath(String path)
Set the user's files directory. |
static URI |
urlToURI(URL url)
Return the URI for a given URL |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String PROGRAM
public static final String PREFERENCES
public static final String HOME
@Deprecated public static final String RESOURCE
PROGRAM.
PROGRAM,
Constant Field Values@Deprecated public static final String FILE
public static final char SEPARATOR
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static String getExternalFilename(String pName)
pName - The name string, possibly starting with program:,
preference:, home:, file: or resource:
public static String getAbsoluteFilename(String path)
path -
public static String getPortableFilename(File file)
getExternalFilename(String pName).
Deprecated forms are not created.
file - File to be representedpublic static String getPortableFilename(String filename)
getExternalFilename(String pName).
Deprecated forms are not created.
filename - Filename to be representedpublic static String getHomePath()
public static String getUserFilesPath()
getPreferencesPath()public static void setUserFilesPath(String path)
path - The path to the user's files directorygetUserFilesPath()public static String getPreferencesPath()
getHomePath() to get the User's home directory.
getHomePath()public static String getProgramPath()
public static void setProgramPath(String path)
setProgramPath(java.io.File) with the passed in path.
path - public static void setProgramPath(File path)
path - public static URL findExternalFilename(String path)
findURL(java.lang.String)
path - public static InputStream findInputStream(String path)
InputStream for that file. Search order is defined by
findURL(java.lang.String, java.lang.String[]).
path - The relative path of the file or resource.
findInputStream(java.lang.String, java.lang.String[]),
findURL(java.lang.String),
findURL(java.lang.String, java.lang.String[])
public static InputStream findInputStream(String path,
@NonNull
String... searchPaths)
InputStream for that file. Search order is defined by
findURL(java.lang.String, java.lang.String[]).
path - The relative path of the file or resource.searchPaths - a list of paths to search for the path in
findInputStream(java.lang.String, java.lang.String[]),
findURL(java.lang.String),
findURL(java.lang.String, java.lang.String[])public static String getUserResourcePath()
public static URL findURL(String path)
URL for that file. Search order is defined by
findURL(java.lang.String, java.lang.String[]).
path - The relative path of the file or resource.
findInputStream(java.lang.String),
findInputStream(java.lang.String, java.lang.String[]),
findURL(java.lang.String, java.lang.String[])
public static URL findURL(String path,
@NonNull
String... searchPaths)
URL for that file. Search order is:
File in the user preferences directory
path - The relative path of the file or resourcesearchPaths - a list of paths to search for the path in
findInputStream(java.lang.String),
findInputStream(java.lang.String, java.lang.String[]),
findURL(java.lang.String)public static URI urlToURI(URL url)
URI for a given URL
url -
URISyntaxExceptionpublic static URL fileToURL(File file)
URL for a given File. This
method catches a MalformedURLException and returns null
in its place, since we really do not expect a File object to ever give a
malformed URL. This method exists solely so implementing classes do not
need to catch that exception.
file - The File to convert.
public static JarFile jmriJarFile()
JarFile pointing to jmri.jar or nullpublic static void logFilePaths()
public static String getScriptsPath()
public static void setScriptsPath(String path)
path - the scriptsPath to setpublic static void createDirectory(String path)
path -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||