g-Eclipse
Release 1.0.0

eu.geclipse.core.util
Class SecureFile

java.lang.Object
  extended by java.io.File
      extended by eu.geclipse.core.util.SecureFile
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class SecureFile
extends java.io.File

This class is an extension of java.io.File providing creation of files and folders with secure permissions, if supported by the underlying OS! Sadly there is no way to manage file/folder permissions in Java <= 5 or in Eclipse itself. This class should go away with the use of Java 6...

See Also:
File, Serialized Form

Field Summary
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
SecureFile(java.io.File parent, java.lang.String child)
          Creates a new SecureFile instance from a parent abstract pathname and a child pathname string.
SecureFile(java.lang.String pathname)
          Creates a new SecureFile instance by converting the given pathname string into an abstract pathname.
SecureFile(java.lang.String parent, java.lang.String child)
          Creates a new SecureFile instance from a parent pathname string and a child pathname string.
SecureFile(java.net.URI uri)
          Creates a new SecureFile instance by converting the given URI into an abstract pathname.
 
Method Summary
 boolean createNewFile()
          Atomically creates a new, empty, protected file named by this abstract pathname if and only if a file with this name does not yet exist.
static SecureFile createTempFile(java.lang.String prefix, java.lang.String suffix)
          Creates a protected empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
static SecureFile createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
          Creates a protected empty file in the specified directory, using the given prefix and suffix to generate its name.
 boolean isSecure()
          Tests whether the file named by this abstract pathname has secure permissions.
 boolean mkdir()
          Creates the secure directory named by this abstract pathname.
 boolean mkdirs()
          Creates the secure directory named by this abstract pathname, including any necessary but nonexistent parent directories.
 boolean renameTo(java.io.File dest)
          Renames the file denoted by this abstract pathname.
 boolean setSecure()
          Set secure permissions on the existing file named by this abstract pathname.
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SecureFile

public SecureFile(java.lang.String pathname)
Creates a new SecureFile instance by converting the given pathname string into an abstract pathname. Never forget to actually _create_ the file with one of the create*File() methods, or call setSecure() if the file already exists, before writing data inside with a FileOutputStream!

Parameters:
pathname - A pathname string
See Also:
File.File(String)

SecureFile

public SecureFile(java.lang.String parent,
                  java.lang.String child)
Creates a new SecureFile instance from a parent pathname string and a child pathname string. Never forget to actually _create_ the file with one of the create*File() methods, or call setSecure() if the file already exists, before writing data inside with a FileOutputStream!

Parameters:
parent - The parent abstract pathname
child - The child pathname string
See Also:
File.File(String, String)

SecureFile

public SecureFile(java.io.File parent,
                  java.lang.String child)
Creates a new SecureFile instance from a parent abstract pathname and a child pathname string. Never forget to actually _create_ the file with one of the create*File() methods, or call setSecure() if the file already exists, before writing data inside with a FileOutputStream!

Parameters:
parent - The parent abstract pathname
child - The child pathname string
See Also:
File.File(File, String)

SecureFile

public SecureFile(java.net.URI uri)
Creates a new SecureFile instance by converting the given URI into an abstract pathname. Never forget to actually _create_ the file with one of the create*File() methods, or call setSecure() if the file already exists, before writing data inside with a FileOutputStream!

Parameters:
uri - A URI
See Also:
File.File(URI)
Method Detail

setSecure

public boolean setSecure()
                  throws java.io.IOException
Set secure permissions on the existing file named by this abstract pathname.

Returns:
true if the named file could be set to secure permissions; false if the file didn't exist
Throws:
java.io.IOException - if setting the permissions failed

isSecure

public boolean isSecure()
Tests whether the file named by this abstract pathname has secure permissions.

Returns:
true if the named file exists and has secure permissions; false otherwise

createNewFile

public boolean createNewFile()
                      throws java.io.IOException
Atomically creates a new, empty, protected file named by this abstract pathname if and only if a file with this name does not yet exist.

Overrides:
createNewFile in class java.io.File
Returns:
true if the named file does not exist and was successfully created with secure permissions; false if the named file already exists
Throws:
java.io.IOException - if setting the permissions failed

createTempFile

public static SecureFile createTempFile(java.lang.String prefix,
                                        java.lang.String suffix)
                                 throws java.io.IOException
Creates a protected empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. Invoking this method is equivalent to invoking createTempFile(prefix, suffix, null).

Returns:
An abstract pathname denoting a new empty protected file
Throws:
java.io.IOException
See Also:
File.createTempFile(String, String)

createTempFile

public static SecureFile createTempFile(java.lang.String prefix,
                                        java.lang.String suffix,
                                        java.io.File directory)
                                 throws java.io.IOException
Creates a protected empty file in the specified directory, using the given prefix and suffix to generate its name.

Returns:
An abstract pathname denoting a new empty protected file
Throws:
java.io.IOException
See Also:
File.createTempFile(String, String, File)

renameTo

public boolean renameTo(java.io.File dest)
Renames the file denoted by this abstract pathname.

Overrides:
renameTo in class java.io.File
Returns:
true if and only if the renaming succeeded; false otherwise
See Also:
File.renameTo(File)

mkdir

public boolean mkdir()
Creates the secure directory named by this abstract pathname.

Overrides:
mkdir in class java.io.File
Returns:
true if and only if the directory was created with secure permissions; false otherwise
See Also:
File.mkdir()

mkdirs

public boolean mkdirs()
Creates the secure directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Overrides:
mkdirs in class java.io.File
Returns:
true if and only if the directory was created with secure permissions, along with all necessary parent directories; false otherwise
See Also:
File.mkdirs()

g-Eclipse
Release 1.0.0