cbr.service
Class PrivilegedOpen

java.lang.Object
  extended bycbr.service.PrivilegedOpen
All Implemented Interfaces:
PrivilegedAction

public class PrivilegedOpen
extends Object
implements PrivilegedAction

This class opens either a FileInputStream or a FileOutputStream to the file that is passed in the constructor, depending on the mode also passed to the constructor.

Version:
"$Id: PrivilegedOpen.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Field Summary
private  boolean create_
          If true then the parent directory is created if it does not already exist.
private  File file_
          The file from which the image is read.
private  boolean mode_
          The mode, either read or write
static boolean READ
           
static boolean WRITE
           
 
Constructor Summary
PrivilegedOpen(File file, boolean mode)
          Creates an instance that opens the given file for the given mode.
PrivilegedOpen(File file, boolean mode, boolean create)
          Creates an instance that opens the given file for the given mode.
 
Method Summary
 Object run()
          Depending on the mode that was passed to the constructor this method returns either a FileInputStream or a FileOutputStream to the file passed to the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ

public static final boolean READ
See Also:
Constant Field Values

WRITE

public static final boolean WRITE
See Also:
Constant Field Values

file_

private File file_
The file from which the image is read.


mode_

private boolean mode_
The mode, either read or write


create_

private boolean create_
If true then the parent directory is created if it does not already exist.

Constructor Detail

PrivilegedOpen

public PrivilegedOpen(File file,
                      boolean mode)
Creates an instance that opens the given file for the given mode. The parent directory of the given file must exist or an exception is thrown upon running this instance.

Parameters:
file - The file to open.
mode - The mode, either READ or WRITE.
Throws:
NullPointerException - if no file is given.

PrivilegedOpen

public PrivilegedOpen(File file,
                      boolean mode,
                      boolean create)
Creates an instance that opens the given file for the given mode. If create is true then the parent directory is created if it does not already exist.

Parameters:
file - The file to open.
mode - The mode, either READ or WRITE.
create - true if the parent directory shall be created if it does not already exist.
Throws:
NullPointerException - if no file is given.
Method Detail

run

public Object run()
Depending on the mode that was passed to the constructor this method returns either a FileInputStream or a FileOutputStream to the file passed to the constructor. If for some reason the file could not be opened then null is returned.

Specified by:
run in interface PrivilegedAction
Returns:
The FileInputStream or FileOutputStream or null.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.