wt.clients.dndMicroApplet
Class FileOperation

java.lang.Object
  extended bywt.clients.dndMicroApplet.FileOperation
All Implemented Interfaces:
PrivilegedAction

final class FileOperation
extends Object
implements PrivilegedAction

Privileged file operation class for use by this package (only)

For security reasons all operations will fail if the file is not actually a subclass of java.io.File.

The Sun JDK on Windows does not subclass java.io.File for its File instances. It is unclear if any other JVM does, but since there are public constructors it is highly doubtful that any JVM does such subclassing. [If one does we can workaround it by creating java.io.File objects from the File sub-class objects that are passed in...]


Field Summary
private static int CREATE_TEMP_FILE
          Operation code to create a temporary file.
(package private) static int DELETE_FILE_OP
          Operation code to delete the given file.
private  Exception exception
          Exception thrown during file operation (during run())
private  File file
          Primary file to be operated upon
(package private) static int GET_OUTPUT_STREAM_OP
          Operation code to get an output stream from/for the given file.
(package private) static int IS_DIRECTORY_OP
          Operation code for isDirectory() operation.
private  int opCode
          Type of file operation to be done
private  String prefix
          Prefix for createTempFile()
private  String suffix
          Suffix for createTempFile()
private static Set trackedFiles
          Files being tracked
 
Constructor Summary
(package private) FileOperation(File file, int opCode)
          Construct file operation
(package private) FileOperation(String prefix, String suffix)
          Construct createTempFile()-like file operation.
 
Method Summary
private  File createTempFile()
          Return file named exactly as per prefix and suffix if it does not exist, else generate a temp file whose name is based on prefix and suffix.
(package private)  Exception getException()
          Retrieve exception thrown by operation
private static boolean isTracking(File file)
          Determine whether the given file is being tracked - and thus whether sensitive operations are allowed on this file (e.g.
 Object run()
          Main (required) privileged engine method (called by AccessController, not directly by caller code).
private static void startTracking(File file)
          Add file to list of files being tracked by this class - and thus allow sensitive operations on this file (e.g.
(package private) static void stopTracking(File file)
          Stop tracking the given file - after which point it cannot be written to or deleted by this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CREATE_TEMP_FILE

private static final int CREATE_TEMP_FILE
Operation code to create a temporary file. Note that this is not a direct mapping to File.createTempFile() as we attempt to use a better name than it generates if possible. Also, see notes on GET_OUTPUT_STREAM_OP and DELETE_FILE_OP.

See Also:
Constant Field Values

GET_OUTPUT_STREAM_OP

static final int GET_OUTPUT_STREAM_OP
Operation code to get an output stream from/for the given file. Note that only files created by this class in this JVM/classloader context (and for which stopTracking() has not been called) will actually yield an output stream. An exception will be thrown upon an attempt to get an output stream for any other file.

See Also:
Constant Field Values

DELETE_FILE_OP

static final int DELETE_FILE_OP
Operation code to delete the given file. Note that only files created by this class in this JVM/classloader context (and for which stopTracking() has not been called) will actually be deleted. An exception will be thrown upon an attempt to delete any other file.

See Also:
Constant Field Values

IS_DIRECTORY_OP

static final int IS_DIRECTORY_OP
Operation code for isDirectory() operation.

See Also:
Constant Field Values

opCode

private int opCode
Type of file operation to be done


file

private File file
Primary file to be operated upon


prefix

private String prefix
Prefix for createTempFile()


suffix

private String suffix
Suffix for createTempFile()


exception

private Exception exception
Exception thrown during file operation (during run())


trackedFiles

private static Set trackedFiles
Files being tracked

Constructor Detail

FileOperation

FileOperation(File file,
              int opCode)
Construct file operation


FileOperation

FileOperation(String prefix,
              String suffix)
Construct createTempFile()-like file operation.

Method Detail

getException

Exception getException()
Retrieve exception thrown by operation


stopTracking

static void stopTracking(File file)
Stop tracking the given file - after which point it cannot be written to or deleted by this class.


startTracking

private static void startTracking(File file)
Add file to list of files being tracked by this class - and thus allow sensitive operations on this file (e.g. overwrite and delete).


isTracking

private static boolean isTracking(File file)
Determine whether the given file is being tracked - and thus whether sensitive operations are allowed on this file (e.g. overwrite and delete).


run

public Object run()
Main (required) privileged engine method (called by AccessController, not directly by caller code).

Specified by:
run in interface PrivilegedAction

createTempFile

private File createTempFile()
                     throws IOException
Return file named exactly as per prefix and suffix if it does not exist, else generate a temp file whose name is based on prefix and suffix.

Throws:
IOException