tcl.lang
Class FileUtil

java.lang.Object
  extended by tcl.lang.FileUtil

public class FileUtil
extends Object


Field Summary
static int PATH_ABSOLUTE
           
static int PATH_RELATIVE
           
static int PATH_VOLUME_RELATIVE
           
 
Constructor Summary
FileUtil()
           
 
Method Summary
static String doTildeSubst(Interp interp, String user)
          Given a string following a tilde, this routine returns the corresponding home directory.
static File getLinkTarget(File link)
          Get the target file of a link, or null if the specified file is not a link.
static File getNewFileObj(Interp interp, String fileName)
           
static TclObject getNormalizedPath(Interp interp, TclObject pathObj)
          This important function attempts to extract from the given TclObject a unique normalized path representation, whose string value can be used as a unique identifier for the file.
static int getPathType(String path)
           
static String getSeparators(String arg)
           
static boolean isExecutable(File fileObj)
          Tests if the given file is executable by the current user.
static String joinPath(Interp interp, TclObject[] argv, int startIndex, int endIndex)
          Combine a list of pathes into one path.
static TclObject splitAndTranslate(Interp interp, String path)
          Split the path.
static TclObject splitPath(Interp interp, String path)
          Turn one path into a list of components.
static String translateFileName(Interp interp, String path)
          If the path starts with a tilde, do tilde substitution on the first component and join it with the remainder of the path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_RELATIVE

public static final int PATH_RELATIVE
See Also:
Constant Field Values

PATH_VOLUME_RELATIVE

public static final int PATH_VOLUME_RELATIVE
See Also:
Constant Field Values

PATH_ABSOLUTE

public static final int PATH_ABSOLUTE
See Also:
Constant Field Values
Constructor Detail

FileUtil

public FileUtil()
Method Detail

getPathType

public static int getPathType(String path)
Parameters:
path - String path to test
Returns:
PATH_RELATIVE if path is relative, PATH_ABSOLUTE if path is an absolute path, PATH_VOLUME_RELATIVE if path is relative to a volume

getNewFileObj

public static File getNewFileObj(Interp interp,
                                 String fileName)
                          throws TclException
Parameters:
interp - current interpreter
fileName - filename following Tcl rules
Returns:
Java File object for given file, as an absolute file
Throws:
TclException

joinPath

public static String joinPath(Interp interp,
                              TclObject[] argv,
                              int startIndex,
                              int endIndex)
                       throws TclException
Combine a list of pathes into one path. It is necessary to perform system specific operations.

Parameters:
interp - Current interpreter
argv - List of pathes to be joined.
startIndex - 1st item in argv to join.
endIndex - 1st item to ignore.
Returns:
a path String.
Throws:
TclException

splitPath

public static TclObject splitPath(Interp interp,
                                  String path)
                           throws TclException
Turn one path into a list of components.

Parameters:
interp - current interpreter
path - Path to split
Returns:
Tcl List Object containing the components of path
Throws:
TclException

doTildeSubst

public static String doTildeSubst(Interp interp,
                                  String user)
                           throws TclException
Given a string following a tilde, this routine returns the corresponding home directory.

Parameters:
interp - interpreter
user - username following the tilde
Returns:
A string containing the home directory in native format.
Throws:
TclException - if env(HOME) is not set or if an unknown user is requested

translateFileName

public static String translateFileName(Interp interp,
                                       String path)
                                throws TclException
If the path starts with a tilde, do tilde substitution on the first component and join it with the remainder of the path. Otherwise, do nothing.

Parameters:
interp - current interpreter
path - path to be translationed
Returns:
the tilde-substituted path
Throws:
TclException

splitAndTranslate

public static TclObject splitAndTranslate(Interp interp,
                                          String path)
                                   throws TclException
Split the path. If there is only one component, and it starts with a tilde, do tilde substitution and split its result.

Parameters:
interp - current interpreter
path - to be split
Returns:
a TclList object containing the components of path
Throws:
TclException

getSeparators

public static final String getSeparators(String arg)
Returns:
the platform separator. Note that the separator is platform-dependent. On MACs separator depends on the given path ('/' or ':')

getNormalizedPath

public static final TclObject getNormalizedPath(Interp interp,
                                                TclObject pathObj)
This important function attempts to extract from the given TclObject a unique normalized path representation, whose string value can be used as a unique identifier for the file.

Returns:
NULL or a valid path object reference. Side effects: none -

getLinkTarget

public static File getLinkTarget(File link)
Get the target file of a link, or null if the specified file is not a link. Note that this returns a full absolute path to the link target; even if the link target is relative. FIXME: Java 1.7 will provide a better link test

Parameters:
link - File to test
Returns:
target of the 'link' File, if it is a link, or null if not.

isExecutable

public static boolean isExecutable(File fileObj)
Tests if the given file is executable by the current user. If Java 1.6+ File.canExecute() is not available, will make its best guess

Parameters:
fileObj - File to test for executability
Returns:
true if file is executable, false otherwise


Copyright © 2015. All rights reserved.