com.dalsemi.fs
Class DSFile

java.lang.Object
  |
  +--java.io.File
        |
        +--com.dalsemi.fs.DSFile

public class DSFile
extends File

An extension to the standard java.io.File class. Methods are provided for accessing the permissions and the owner ID. Instances of this class can also be used to execute the file it represents, although the preferred way to execute a file is through the methods provided in java.lang.Runtime.

See Also:
Serialized Form

Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
DSFile(File dir, String name)
          Creates a new DSFile instance from a parent abstract pathname and a child pathname string.
DSFile(String path)
          Creates a new DSFile instance by converting the given pathname string into an abstract pathname.
DSFile(String path, String name)
          Creates a new DSFile instance from a parent pathname string and a child pathname string.
 
Method Summary
static byte[] buildAbsolutePath(String parent, String name)
          Builds the fully qualified path name from the directory name and the file name.
 boolean canExec()
          Determines if this file can be executed.
 int executeFile()
          Executes this file as a new foreground process.
 int executeFile(InputStream stdin, OutputStream stdout, OutputStream stderr, String[] args, boolean foreground, String processName)
          Executes this file as a new process with the default environment.
 int executeFile(InputStream stdin, OutputStream stdout, OutputStream stderr, String[] args, String[] env, boolean foreground, String processName)
          Executes this file.
 int executeFile(InputStream stdin, OutputStream stdout, OutputStream stderr, String[] args, String[] env, boolean foreground, String processName, Process procObj)
          Executes this file.
 int getOtherPermissions()
          Retrieves the other (non-owner) permissions for this file.
 int getUser()
          Gets the ID of the user (owner) of this file.
 int getUserPermissions()
          Retrieves the user (owner) permissions for this file.
 boolean listLong(OutputStream out, boolean unixStyle)
          Prints a verbose file listing to the given stream.
 void setOtherPermissions(int perms)
          Sets the other (non-owner) permissions for this file.
 void setUser(byte uid)
          Sets the user (owner) of this file.
 void setUserPermissions(int perms)
          Sets the user (owner) permissions for this file.
 void touch()
          Sets the modified time of this file to the current time.
 
Methods inherited from class java.io.File
canRead, canWrite, delete, equals, exists, getAbsolutePath, getCanonicalPath, getName, getParent, getPath, hashCode, isAbsolute, isDirectory, isFile, lastModified, length, list, list, mkdir, mkdirs, renameTo, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DSFile

public DSFile(String path)
Creates a new DSFile instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.
Parameters:
path - the file pathname
Throws:
NullPointerException - if the file path is equal to null

DSFile

public DSFile(String path,
              String name)
Creates a new DSFile instance from a parent pathname string and a child pathname string.

If path is null then the new DSFile instance is created as if by invoking the single-argument DSFile constructor on the given name pathname string.

Otherwise the path pathname string is taken to denote a directory, and the name pathname string is taken to denote either a directory or a file. If the name pathname string is absolute then it is converted into a relative pathname in a system-dependent way. If path is the empty string then the new DSFile instance is created by converting name into an abstract pathname and resolving the result against the current working directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.

Parameters:
path - the directory pathname
name - the file pathname
Throws:
NullPointerException - if the name is equal to null

DSFile

public DSFile(File dir,
              String name)
Creates a new DSFile instance from a parent abstract pathname and a child pathname string.

If dir is null then the new DSFile instance is created as if by invoking the single-argument DSFile constructor on the given name pathname string.

Otherwise the dir abstract pathname is taken to denote a directory, and the name pathname string is taken to denote either a directory or a file. If the name pathname string is absolute then it is converted into a relative pathname in a system-dependent way. If dir is the empty abstract pathname then the new DSFile instance is created by converting name into an abstract pathname and resolving the result against the current working directory. Otherwise each pathname string is converted into an abstract pathname and the child abstract pathname is resolved against the parent.

Parameters:
dir - the directory
name - the file pathname
Throws:
NullPointerException - if the name is equal to null
Method Detail

setUserPermissions

public void setUserPermissions(int perms)
                        throws IOException
Sets the user (owner) permissions for this file. The three lowest order bits are used for the permissions, all others are ignored.

Bit 0 = Execute

Bit 1 = Write

Bit 2 = Read

Set the bit to grant that permission, clear it to deny.

Parameters:
perms - the new user/owner permissions
Throws:
IOException - if the file does not exist or the caller does not own the file and is not an administrator
See Also:
getUserPermissions()

getUserPermissions

public int getUserPermissions()
                       throws FileNotFoundException
Retrieves the user (owner) permissions for this file. The three lowest order bits of the return are used, all others should be ignored.

Bit 0 = Execute

Bit 1 = Write

Bit 2 = Read

If the bit is set, that permission is granted, otherwise it is denied.

Returns:
the permissions
Throws:
FileNotFoundException - if the file does not exist
See Also:
setUserPermissions(int)

setOtherPermissions

public void setOtherPermissions(int perms)
                         throws IOException
Sets the other (non-owner) permissions for this file. The three lowest order bits are used for the permissions, all others are ignored.

Bit 0 = Execute

Bit 1 = Write

Bit 2 = Read

Set the bit to grant that permission, clear it to deny.

Parameters:
perms - the new other permissions
Throws:
IOException - if the file does not exist or the caller does not own the file and is not an administrator
See Also:
getOtherPermissions()

getOtherPermissions

public int getOtherPermissions()
                        throws FileNotFoundException
Retrieves the other (non-owner) permissions for this file. The three lowest order bits of the return are used, all others should be ignored.

Bit 0 = Execute

Bit 1 = Write

Bit 2 = Read

If the bit is set, that permission is granted, otherwise it is denied.

Returns:
the permissions
Throws:
FileNotFoundException - if the file does not exist
See Also:
setOtherPermissions(int)

setUser

public void setUser(byte uid)
             throws IOException
Sets the user (owner) of this file. Only owners of a file are allowed to make changes to its permissions.
Parameters:
uid - the ID of the new user
Throws:
IOException - if the file does not exist or the caller does not own the file and is not an administrator
See Also:
getUser(), TINIOS.getCurrentUID(), TINIOS.getUserNameByUID(byte), TINIOS.getUIDByUserName(String)

getUser

public int getUser()
            throws FileNotFoundException
Gets the ID of the user (owner) of this file.
Returns:
uid the ID of the user
Throws:
FileNotFoundException - if the file does not exist
See Also:
setUser(byte), TINIOS.getCurrentUID(), TINIOS.getUserNameByUID(byte), TINIOS.getUIDByUserName(String)

canExec

public boolean canExec()
Determines if this file can be executed. Will return false if the file does not exist or if the caller does not have execute permission for the file.
Returns:
true if the application can execute this file, false otherwise
See Also:
executeFile(InputStream,OutputStream,OutputStream,String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String,Process), executeFile()

executeFile

public int executeFile()
                throws IOException
Executes this file as a new foreground process. Applications should not invoke executeFile directly, but should instead use the methods of the java.lang.Runtime class to start new processes. System.in, System.out, and System.err of the calling process are used for the new process's streams. This call will block until the new process finishes.
Returns:
the new process's ID (pid)
Throws:
IOException - if the canExec() method returns false
See Also:
canExec(), executeFile(InputStream,OutputStream,OutputStream,String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String,Process)

touch

public void touch()
           throws IOException
Sets the modified time of this file to the current time. If the file does not exist, a file of length 0 will be created.
Throws:
if - the caller cannot write the file

listLong

public boolean listLong(OutputStream out,
                        boolean unixStyle)
                 throws IOException
Prints a verbose file listing to the given stream. The listing will include the files name, size, owner and user permissions, owner name, and last modified time. This method can also print the listing to match the format of the Un*x 'ls -l' command.
Parameters:
out - the output stream the listing will be sent to
unixStyle - whether the Un*x format should be used
Returns:
false if the user does not have permissions to read the directory or if this file does not exist, true otherwise

buildAbsolutePath

public static byte[] buildAbsolutePath(String parent,
                                       String name)
Builds the fully qualified path name from the directory name and the file name. The current working directory is also used as needed. The final result will have the leading and trailing separator characters (/) removed. The name parameter cannot be null. Both parameters can, however, be the empty string. The resulting byte array will have the following format.

Byte 0-3 = The offset into the array where the name begins (LSB, xx, xx, MSB).

Byte 4-7 = The length of the name stored in the array (LSB, xx, xx, MSB).

Byte 8-x = The data holding the ASCII name of the file. There may be extra bytes preceding or following the actual data. Use the first eight bytes of the array to determine which bytes to use.

Parameters:
parent - the directory or path of the file
name - the file name
Returns:
byte array containing the fully qualified path name

executeFile

public int executeFile(InputStream stdin,
                       OutputStream stdout,
                       OutputStream stderr,
                       String[] args,
                       boolean foreground,
                       String processName)
                throws IOException
Executes this file as a new process with the default environment. Applications should not invoke executeFile directly, but should instead use the methods of the java.lang.Runtime class to start new processes.
Parameters:
stdin - the stream that will become the new process's System.in
stdout - the stream that will become the new process's System.out
stderr - the stream that will become the new process's System.err
args - the arguments that will be passed to the applications main(String[]) method
foreground - whether this method should block until the new process finishes
processName - the name of the new process
Returns:
the new process's ID (pid)
Throws:
IOException - if the canExec() method returns false
See Also:
canExec(), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String,Process), executeFile()

executeFile

public int executeFile(InputStream stdin,
                       OutputStream stdout,
                       OutputStream stderr,
                       String[] args,
                       String[] env,
                       boolean foreground,
                       String processName)
                throws IOException
Executes this file. Applications should not invoke executeFile directly, but should instead use the methods of the java.lang.Runtime class to start new processes.
Parameters:
stdin - the stream that will become the new process's System.in
stdout - the stream that will become the new process's System.out
stderr - the stream that will become the new process's System.err
args - the arguments that will be passed to the applications main(String[]) method
env - the environment that will be added to the process's System properties
foreground - whether this method should block until the new process finishes
processName - the name of the new process
Returns:
the new process's ID (pid)
Throws:
IOException - if the canExec() method returns false
See Also:
canExec(), executeFile(InputStream,OutputStream,OutputStream,String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String,Process), executeFile()

executeFile

public int executeFile(InputStream stdin,
                       OutputStream stdout,
                       OutputStream stderr,
                       String[] args,
                       String[] env,
                       boolean foreground,
                       String processName,
                       Process procObj)
                throws IOException
Executes this file. Applications should not invoke executeFile directly, but should instead use the methods of the java.lang.Runtime class to start new processes.
Parameters:
stdin - the stream that will become the new process's System.in
stdout - the stream that will become the new process's System.out
stderr - the stream that will become the new process's System.err
args - the arguments that will be passed to the applications main(String[]) method
env - the environment that will be added to the process's System properties
foreground - whether this method should block until the new process finishes
processName - the name of the new process
procObj - the Process object to associate with the new process
Returns:
the new process's ID (pid).
Throws:
IOException - if the canExec() method returns false
See Also:
canExec(), executeFile(InputStream,OutputStream,OutputStream,String[],String[],boolean,String), executeFile(InputStream,OutputStream,OutputStream,String[],boolean,String), executeFile()