|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.PathSearch
public class PathSearch
Search for file names through directories. This class is used to search for file names through a list of different directories. It is also designed to allow one to have path separator characters automatically translated to the platform specific form automatically. In other words, you could always specify a path like "/tmp/etc" and know that it would be translated to the proper form for the environment you are running under.
| Constructor Summary | |
|---|---|
PathSearch()
Default constructor for the PathSearch class. |
|
PathSearch(boolean autoTranslate)
Minimal constructor for the PathSearch class. |
|
| Method Summary | |
|---|---|
int |
addDirectories(String path)
Add one or more directories to the search path. |
boolean |
addDirectory(String path)
Add a additional directory to the search path. |
File |
getDirectory(int i)
Retrieve a directory in the path list. |
int |
getDirectoryCount()
Get the number of directories in the search path. |
static PathSearch |
getSystemPath()
Try to look up the standard PATH for the Operating System. |
static Enumeration |
parsePathString(String path,
boolean autoTranslate)
Method to parse a PATH string into its components. |
File |
searchForFile(String name)
Try to locate a file in the current search path. |
String |
toString()
Return a PATH looking string of the current search areas. |
static String |
translatePath(String origPath)
Adjust directory separation character for platform. |
static String |
translatePathList(String origPath)
Adjust PATH type separation character for platform. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PathSearch()
The following actions are done:
public PathSearch(boolean autoTranslate)
Allows one to specify whether directory separator characters are automatically translated or not. In addition, the current directory will not automatically be added to the start of the search path.
boolean - Flag to enable or disable the automatic translation of the '/'
and '\' characters to the platform specific format
required. (I'd recommend setting it true).| Method Detail |
|---|
public int getDirectoryCount()
addDirectories(java.lang.String)public File getDirectory(int i)
index - Index in the range of [0,getDirectoryCount()-1]
File object for the next element in the directory
search path. Or null, if the index is invalid.getDirectoryCount()public static String translatePath(String origPath)
The following:
java.util.PathSearch.translatePath("../opt\\java/test.java");
Would yield: "../opt/java/test.java" on a Unix platform
Would yield: "..\\opt\\java\\test.java" on a Windows, OS/2 platform
String - String containing the path which you want translated. All of
the '/' and '\' characters contained will be translated to the
appropriate character for the platform.
addDirectories(java.lang.String),
translatePathList(java.lang.String),
File.separatorCharpublic static String translatePathList(String origPath)
The following:
java.util.PathSearch("/opt/java:c:\\tmp;/root");
Would yield: "/opt/java:c:/tmp:/root" on a Unix platform
Would yield: "\\opt\\java;c:\\tmp;\\root" on a Windows, OS/2 platform
String - String containing the list of zero or more paths which you
want translated to the platform form. All of the '/' and '\'
characters contained will be translated to the appropriate
character for the platform. And all of the ';' characters will
be translated to the platform specific character used for
displaying paths (unfortunately this can not be done for the
':' characters cleanly since some platforms use these
characters in their file paths - so, these characters will be
translated UNLESS there is another ':' exactly 2 characters
prior in the string).
addDirectories(java.lang.String),
translatePath(java.lang.String)
public static Enumeration parsePathString(String path,
boolean autoTranslate)
"c:\windows;d:/opt/bin:o:/net/bin"
And parse out the individual directories as strings. For example, the above would come back on a windows system as 3 strings "c:\windows", "d:\opt\bin", and "o:\net\bin".
This is a static method (meaning that you don't need to create an object to use it). It has the following features:
translatePathList(java.lang.String) method will be used.
addDirectory(java.lang.String) method which only adds
directories which actually exist and are valid directories. This
also means that you can use on abitrary strings (sometimes I use
this method to parse a list of files).
String objects - its up
to you to determine whether the object is actually a directory or
not.
Most of the time, you will find using the addDirectories(java.lang.String) method suitable for these objects, however there
are times when access to this method can be very handy.
path - A standard PATH list (its fairly platform independent, use ":"
or ";" to separate each path entry and "/" or "\" to separate
directory names within a path).translate - Set to true if you would like us to automatically translate
":", ";", "/", and "\" characters for you to the platform
specific form via translatePathList(). Most likely you will want this set to
true, but you can set it to false if you want us to just parse
exactly what you send us.
String objects of each
directory parsed from the PATH string.addDirectories(java.lang.String),
translatePathList(java.lang.String)public boolean addDirectory(String path)
String - A string corresponding to a path in the file system. If the
object has automatic translation enabled, then the '/' and '\'
characters will be translated to the appropriate form for the
platform.
addDirectories(java.lang.String),
Example Program,
searchForFile(java.lang.String)public int addDirectories(String path)
String - PATH type string with the java.io.File.pathSeparator
separating directories (or the characters ';' or ':' if
automatic translation is enabled). For example:
"/tmp:/usr/local".
addDirectory(java.lang.String),
Example Program,
searchForFile(java.lang.String),
parsePathString(java.lang.String, boolean)public File searchForFile(String name)
String - Name of the file to search for
addDirectory(java.lang.String),
addDirectories(java.lang.String),
Example Programpublic String toString()
toString in class Objectpublic static PathSearch getSystemPath()
java -Dos.path=$PATH CLASS ARGS
System.getProperty("os.name")
in lower case) or "os.path", we will use that value.
As this is an expensive computation, it is done only one time
and a non-mutable PathSearch object will be
returned (attempts to modify it will be ignored).
PathSearch object that can not be modified (you
can't add additional directories to it). Subsequent calls to
this method will immediately return the results of the first
invocation.ProcessInvoker
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||