org.kde.koala
Class KArchive

java.lang.Object
  extended by org.kde.koala.KArchive
All Implemented Interfaces:
org.kde.qt.QtSupport
Direct Known Subclasses:
KAr, KTar, KZip

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

KArchive is a base class for reading and writing archives.

Author:
David Faure

Field Summary
static int VIRTUAL_PREPARE_WRITING
           
static int VIRTUAL_WRITE_DATA
           
static int VIRTUAL_WRITE_DIR
           
static int VIRTUAL_WRITE_FILE
           
static int VIRTUAL_WRITE_SYMLINK
           
 
Constructor Summary
protected KArchive(java.lang.Class dummy)
           
 
Method Summary
 boolean addLocalDirectory(java.lang.String path, java.lang.String destName)
          Writes a local directory into the archive, including all its contents, recursively.
 boolean addLocalFile(java.lang.String fileName, java.lang.String destName)
          Writes a local file into the archive.
 void close()
          Closes the archive.
 boolean closeSucceeded()
          Use to check if close had any problem
 org.kde.qt.QIODeviceInterface device()
          The underlying device.
 KArchiveDirectory directory()
          If an archive is opened for reading, then the contents of the archive can be accessed via this function.
 boolean doneWriting(int size)
          Call doneWriting after writing the data.
 boolean isOpened()
          Checks whether the archive is open.
 int mode()
          Returns the mode in which the archive was opened
 boolean open(int mode)
          Opens the archive for reading or writing.
 boolean prepareWriting(java.lang.String name, java.lang.String user, java.lang.String group, int size)
          Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as many times as wanted then call doneWriting( totalSize ).
 boolean prepareWriting(java.lang.String name, java.lang.String user, java.lang.String group, int size, long perm, int atime, int mtime, int ctime)
          Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as many times as wanted then call doneWriting( totalSize ).
 boolean writeData(java.lang.String data, int size)
          Write data into the current file - to be called after calling prepareWriting
 boolean writeDir(java.lang.String name, java.lang.String user, java.lang.String group)
          If an archive is opened for writing then you can add new directories using this function.
 boolean writeDir(java.lang.String name, java.lang.String user, java.lang.String group, long perm, int atime, int mtime, int ctime)
          If an archive is opened for writing then you can add new directories using this function.
 boolean writeFile(java.lang.String name, java.lang.String user, java.lang.String group, int size, long perm, int atime, int mtime, int ctime, java.lang.String data)
          If an archive is opened for writing then you can add a new file using this function.
 boolean writeFile(java.lang.String name, java.lang.String user, java.lang.String group, int size, java.lang.String data)
          If an archive is opened for writing then you can add a new file using this function.
 boolean writeSymLink(java.lang.String name, java.lang.String target, java.lang.String user, java.lang.String group, long perm, int atime, int mtime, int ctime)
          Writes a symbolic link to the archive if the archive must be opened for writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIRTUAL_WRITE_DATA

public static final int VIRTUAL_WRITE_DATA
See Also:
Constant Field Values

VIRTUAL_WRITE_SYMLINK

public static final int VIRTUAL_WRITE_SYMLINK
See Also:
Constant Field Values

VIRTUAL_WRITE_DIR

public static final int VIRTUAL_WRITE_DIR
See Also:
Constant Field Values

VIRTUAL_WRITE_FILE

public static final int VIRTUAL_WRITE_FILE
See Also:
Constant Field Values

VIRTUAL_PREPARE_WRITING

public static final int VIRTUAL_PREPARE_WRITING
See Also:
Constant Field Values
Constructor Detail

KArchive

protected KArchive(java.lang.Class dummy)
Method Detail

open

public boolean open(int mode)
Opens the archive for reading or writing. Inherited classes might want to reimplement openArchive instead.

Parameters:
mode - may be IO_ReadOnly or IO_WriteOnly
See Also:
close()

close

public void close()
Closes the archive. Inherited classes might want to reimplement closeArchive instead.

See Also:
open(int)

closeSucceeded

public boolean closeSucceeded()
Use to check if close had any problem

Returns:
true if close succeded without problems

isOpened

public boolean isOpened()
Checks whether the archive is open.

Returns:
true if the archive is opened

mode

public int mode()
Returns the mode in which the archive was opened

Returns:
the mode in which the archive was opened (IO_ReadOnly or IO_WriteOnly)
See Also:
open(int)

device

public org.kde.qt.QIODeviceInterface device()
The underlying device.

Returns:
the underlying device.

directory

public KArchiveDirectory directory()
If an archive is opened for reading, then the contents of the archive can be accessed via this function.

Returns:
the directory of the archive

addLocalFile

public boolean addLocalFile(java.lang.String fileName,
                            java.lang.String destName)
Writes a local file into the archive. The main difference with writeFile, is that this method minimizes memory usage, by not loading the whole file into memory in one go. If fileName is a symbolic link, it will be written as is, i. e. it will not be resolved before.

Parameters:
fileName - full path to an existing local file, to be added to the archive.
destName - the resulting name (or relative path) of the file in the archive.

addLocalDirectory

public boolean addLocalDirectory(java.lang.String path,
                                 java.lang.String destName)
Writes a local directory into the archive, including all its contents, recursively. Calls addLocalFile for each file to be added. Since KDE 3.2 it will also add a path that is a symbolic link to a directory. The symbolic link will be dereferenced and the content of the directory it is pointing to added recursively. However, symbolic links under path will be stored as is.

Parameters:
path - full path to an existing local directory, to be added to the archive.
destName - the resulting name (or relative path) of the file in the archive.

writeDir

public boolean writeDir(java.lang.String name,
                        java.lang.String user,
                        java.lang.String group)
If an archive is opened for writing then you can add new directories using this function. KArchive won't write one directory twice.

Parameters:
name - the name of the directory
user - the user that owns the directory
group - the group that owns the directory

writeDir

public boolean writeDir(java.lang.String name,
                        java.lang.String user,
                        java.lang.String group,
                        long perm,
                        int atime,
                        int mtime,
                        int ctime)
If an archive is opened for writing then you can add new directories using this function. KArchive won't write one directory twice. This method also allows some file metadata to be set. However, depending on the archive type not all metadata might be regarded.

Parameters:
name - the name of the directory
user - the user that owns the directory
group - the group that owns the directory
perm - permissions of the directory
atime - time the file was last accessed
mtime - modification time of the file
ctime - creation time of the file

writeSymLink

public boolean writeSymLink(java.lang.String name,
                            java.lang.String target,
                            java.lang.String user,
                            java.lang.String group,
                            long perm,
                            int atime,
                            int mtime,
                            int ctime)
Writes a symbolic link to the archive if the archive must be opened for writing.

Parameters:
name - name of symbolic link
target - target of symbolic link
user - the user that owns the directory
group - the group that owns the directory
perm - permissions of the directory
atime - time the file was last accessed
mtime - modification time of the file
ctime - creation time of the file

writeFile

public boolean writeFile(java.lang.String name,
                         java.lang.String user,
                         java.lang.String group,
                         int size,
                         java.lang.String data)
If an archive is opened for writing then you can add a new file using this function. If the file name is for example "mydir/test1" then the directory "mydir" is automatically appended first if that did not happen yet.

Parameters:
name - the name of the file
user - the user that owns the file
group - the group that owns the file
size - the size of the file
data - the data to write (size bytes)

writeFile

public boolean writeFile(java.lang.String name,
                         java.lang.String user,
                         java.lang.String group,
                         int size,
                         long perm,
                         int atime,
                         int mtime,
                         int ctime,
                         java.lang.String data)
If an archive is opened for writing then you can add a new file using this function. If the file name is for example "mydir/test1" then the directory "mydir" is automatically appended first if that did not happen yet. This method also allows some file metadata to be set. However, depending on the archive type not all metadata might be regarded.

Parameters:
name - the name of the file
user - the user that owns the file
group - the group that owns the file
size - the size of the file
perm - permissions of the file
atime - time the file was last accessed
mtime - modification time of the file
ctime - creation time of the file
data - the data to write (size bytes)

prepareWriting

public boolean prepareWriting(java.lang.String name,
                              java.lang.String user,
                              java.lang.String group,
                              int size)
Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as many times as wanted then call doneWriting( totalSize ). For tar.gz files, you need to know the size before hand, since it is needed in the header. For zip files, size isn't used.

Parameters:
name - the name of the file
user - the user that owns the file
group - the group that owns the file
size - the size of the file

prepareWriting

public boolean prepareWriting(java.lang.String name,
                              java.lang.String user,
                              java.lang.String group,
                              int size,
                              long perm,
                              int atime,
                              int mtime,
                              int ctime)
Here's another way of writing a file into an archive: Call prepareWriting, then call writeData() as many times as wanted then call doneWriting( totalSize ). For tar.gz files, you need to know the size before hand, it is needed in the header! For zip files, size isn't used. This method also allows some file metadata to be set. However, depending on the archive type not all metadata might be regarded.

Parameters:
name - the name of the file
user - the user that owns the file
group - the group that owns the file
size - the size of the file
perm - permissions of the file
atime - time the file was last accessed
mtime - modification time of the file
ctime - creation time of the file

writeData

public boolean writeData(java.lang.String data,
                         int size)
Write data into the current file - to be called after calling prepareWriting


doneWriting

public boolean doneWriting(int size)
Call doneWriting after writing the data.

Parameters:
size - the size of the file
See Also:
prepareWriting(java.lang.String, java.lang.String, java.lang.String, int)