org.kde.koala
Class KSaveFile

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

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

The KSaveFile class has been made to write out changes to an existing file atomically. This means that EITHER: a) All changes have been written successfully to the file. b) Some error occurred, no changes have been written whatsoever and the old file is still in place.


Constructor Summary
protected KSaveFile(java.lang.Class dummy)
           
  KSaveFile(java.lang.String filename)
           
  KSaveFile(java.lang.String filename, int mode)
          Creates a new KSaveFile with the given file name.
 
Method Summary
 void abort()
          Aborts the write operation and removes any intermediate files This implies a close.
static boolean backupFile(java.lang.String filename)
           
static boolean backupFile(java.lang.String filename, java.lang.String backupDir)
           
static boolean backupFile(java.lang.String filename, java.lang.String backupDir, java.lang.String backupExtension)
          Static method to create a backup file before saving.
 boolean close()
          Closes the file and makes the changes definitive.
 org.kde.qt.QDataStream dataStream()
          A QDataStream open for writing to the file.
 void dispose()
          Delete the wrapped C++ instance ahead of finalize()
 org.kde.qt.QFile file()
          A QFile open for writing to the file.
protected  void finalize()
          Deletes the wrapped C++ instance
 int handle()
          An integer file descriptor open for writing to the file.
 boolean isDisposed()
          Has the wrapped C++ instance been deleted?
 java.lang.String name()
          The name of the file as passed to the constructor.
 int status()
          Returns the status of the file based on errno.
 org.kde.qt.QTextStream textStream()
          A QTextStream open for writing to the file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KSaveFile

protected KSaveFile(java.lang.Class dummy)

KSaveFile

public KSaveFile(java.lang.String filename,
                 int mode)
Creates a new KSaveFile with the given file name.

Parameters:
filename - the path of the file
mode - the mode of the file (see chmod(1))

KSaveFile

public KSaveFile(java.lang.String filename)
Method Detail

status

public int status()
Returns the status of the file based on errno. (see errno.h) 0 means OK. You should check the status after object creation to check whether a file could be created in the first place. You may check the status after closing the file to verify that the file has indeed been written correctly.

Returns:
the errno status, 0 means ok

name

public java.lang.String name()
The name of the file as passed to the constructor.

Returns:
The name of the file, or null if opening the file has failed

handle

public int handle()
An integer file descriptor open for writing to the file.

Returns:
The file descriptor, or a negative number if opening the temporary file failed

file

public org.kde.qt.QFile file()
A QFile open for writing to the file.

Returns:
A QFile open for writing to the file, or 0 if opening the temporary file failed.

textStream

public org.kde.qt.QTextStream textStream()
A QTextStream open for writing to the file.

Returns:
A QTextStream that is open for writing to the file, or 0 if opening the temporary file failed

dataStream

public org.kde.qt.QDataStream dataStream()
A QDataStream open for writing to the file.

Returns:
A QDataStream that is open for writing to the file, or 0 if opening the file failed

abort

public void abort()
Aborts the write operation and removes any intermediate files This implies a close.


close

public boolean close()
Closes the file and makes the changes definitive. Returns 'true' is successful, or 'false' if an error has occurred. See status() for details about errors.

Returns:
true if successful, or false if an error has occurred.

backupFile

public static boolean backupFile(java.lang.String filename,
                                 java.lang.String backupDir,
                                 java.lang.String backupExtension)
Static method to create a backup file before saving. You can use this method even if you don't use KSaveFile.

Parameters:
filename - the file to backup
backupDir - optional directory where to save the backup file in. If empty (the default), the backup will be in the same directory as filename.
backupExtension - the extension to append to filename, "~" by default.

backupFile

public static boolean backupFile(java.lang.String filename,
                                 java.lang.String backupDir)

backupFile

public static boolean backupFile(java.lang.String filename)

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?