org.kde.koala
Class KTempDir

java.lang.Object
  extended by org.kde.koala.KTempDir
All Implemented Interfaces:
org.kde.qt.QtSupport

public class KTempDir
extends java.lang.Object
implements org.kde.qt.QtSupport

The KTempDir class creates a unique directory for temporary use. This is especially useful if you need to create a directory in a world writable directory like /tmp without being vulnerable to so called symlink attacks. KDE applications, however, shouldn't create files or directories in /tmp in the first place but use the "tmp" resource instead. The standard KTempDir constructor will do that by default. To create a temporary directory that starts with a certain name in the "tmp" resource, one should use: KTempDir(locateLocal("tmp", prefix)); KTempFile does not create any missing directories, but locateLocal() does. See also KStandardDirs

Author:
Joseph Wenninger

Constructor Summary
  KTempDir()
           
protected KTempDir(java.lang.Class dummy)
           
  KTempDir(java.lang.String directoryPrefix)
           
  KTempDir(java.lang.String directoryPrefix, int mode)
          Creates a temporary directory with the name: \p \\ The default
 
Method Summary
protected  boolean create(java.lang.String directoryPrefix, int mode)
          Creates a "random" directory with specified mode
 void dispose()
          Delete the wrapped C++ instance ahead of finalize()
 boolean existing()
           
protected  void finalize()
          Deletes the wrapped C++ instance
 boolean isDisposed()
          Has the wrapped C++ instance been deleted?
 java.lang.String name()
          Returns the full path and name of the directory, including a trailing '/'.
 org.kde.qt.QDir qDir()
          Returns the QDir of the temporary directory.
 void setAutoDelete(boolean autoDelete)
          Turn automatic deletion on or off.
protected  void setError(int error)
          Sets the errno value
 int status()
          Returns the status of the directory creation based on errno.
 void unlink()
          Deletes the directory recursively
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KTempDir

protected KTempDir(java.lang.Class dummy)

KTempDir

public KTempDir(java.lang.String directoryPrefix,
                int mode)
Creates a temporary directory with the name: \p \\ The default
directoryPrefix
is "$KDEHOME/tmp-$HOST/appname"

Parameters:
directoryPrefix - the prefix of the file name, or null for the default value
mode - the file permissions, almost always in octal. The first digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the second selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.

KTempDir

public KTempDir(java.lang.String directoryPrefix)

KTempDir

public KTempDir()
Method Detail

setAutoDelete

public void setAutoDelete(boolean autoDelete)
Turn automatic deletion on or off. Automatic deletion is off by default.

Parameters:
autoDelete - true to turn automatic deletion on

status

public int status()
Returns the status of the directory creation based on errno. (see errno.h) 0 means OK. You should check the status after object creation to check whether a directory could be created in the first place.

Returns:
the errno status, 0 means ok

name

public java.lang.String name()
Returns the full path and name of the directory, including a trailing '/'.

Returns:
The name of the directory, or null if creating the directory has failed or the directory has been unlinked

qDir

public org.kde.qt.QDir qDir()
Returns the QDir of the temporary directory.

Returns:
QDir directory information of the directory or 0 if their is no managed directory The caller has to free the pointer open for writing to the

unlink

public void unlink()
Deletes the directory recursively


existing

public boolean existing()
Returns:
true if a temporary directory has successfully been created and not been unlinked yet

create

protected boolean create(java.lang.String directoryPrefix,
                         int mode)
Creates a "random" directory with specified mode

Parameters:
directoryPrefix - to use when creating temp directory (the rest is generated randomly)
mode - directory permissions
Returns:
bool true upon sucess

setError

protected void setError(int error)
Sets the errno value

Parameters:
error - the value to set the status to.

finalize

protected void finalize()
                 throws java.lang.InternalError
Deletes the wrapped C++ instance

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.InternalError

dispose

public void dispose()
Delete the wrapped C++ instance ahead of finalize()


isDisposed

public boolean isDisposed()
Has the wrapped C++ instance been deleted?