org.kde.koala
Class KTar

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

public class KTar
extends KArchive

A class for reading / writing (optionally compressed) tar archives. KTar allows you to read and write tar archives, including those that are compressed using gzip or bzip2.

Author:
Torben Weis , David Faure

Field Summary
 
Fields inherited from class org.kde.koala.KArchive
VIRTUAL_PREPARE_WRITING, VIRTUAL_WRITE_DATA, VIRTUAL_WRITE_DIR, VIRTUAL_WRITE_FILE, VIRTUAL_WRITE_SYMLINK
 
Constructor Summary
protected KTar(java.lang.Class dummy)
           
  KTar(org.kde.qt.QIODeviceInterface dev)
          Creates an instance that operates on the given device.
  KTar(java.lang.String filename)
           
  KTar(java.lang.String filename, java.lang.String mimetype)
          Creates an instance that operates on the given filename using the compression filter associated to given mimetype.
 
Method Summary
protected  boolean closeArchive()
           
 void dispose()
          Delete the wrapped C++ instance ahead of finalize()
 boolean doneWriting(int size)
          Call doneWriting after writing the data.
 java.lang.String fileName()
          The name of the tar file, as passed to the constructor Null if you used the QIODevice constructor.
protected  void finalize()
          Deletes the wrapped C++ instance
 boolean isDisposed()
          Has the wrapped C++ instance been deleted?
protected  boolean openArchive(int mode)
          Opens the archive for reading.
protected  boolean prepareWriting_impl(java.lang.String name, java.lang.String user, java.lang.String group, int size, long perm, int atime, int mtime, int ctime)
           
 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 ).
 void setOrigFileName(java.lang.String fileName)
          Special function for setting the "original file name" in the gzip header, when writing a tar.gz file.
protected  boolean writeDir_impl(java.lang.String name, java.lang.String user, java.lang.String group, long perm, int atime, int mtime, int ctime)
           
 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.
protected  boolean writeSymLink_impl(java.lang.String name, java.lang.String target, java.lang.String user, java.lang.String group, long perm, int atime, int mtime, int ctime)
           
 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 org.kde.koala.KArchive
addLocalDirectory, addLocalFile, close, closeSucceeded, device, directory, isOpened, mode, open, writeData, writeFile, writeFile
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KTar

protected KTar(java.lang.Class dummy)

KTar

public KTar(java.lang.String filename,
            java.lang.String mimetype)
Creates an instance that operates on the given filename using the compression filter associated to given mimetype.

Parameters:
filename - is a local path (e.g. "/home/weis/myfile.tgz")
mimetype - "application/x-gzip" or "application/x-bzip2" Do not use application/x-tgz or similar - you only need to specify the compression layer ! If the mimetype is omitted, it will be determined from the filename.

KTar

public KTar(java.lang.String filename)

KTar

public KTar(org.kde.qt.QIODeviceInterface dev)
Creates an instance that operates on the given device. The device can be compressed (KFilterDev) or not (QFile, etc.).

Parameters:
dev - the device to read from. If the source is compressed, the QIODevice must take care of decompression
Method Detail

fileName

public java.lang.String fileName()
The name of the tar file, as passed to the constructor Null if you used the QIODevice constructor.

Returns:
the name of the file, or null if unknown

setOrigFileName

public void setOrigFileName(java.lang.String fileName)
Special function for setting the "original file name" in the gzip header, when writing a tar.gz file. It appears when using in the "file" command, for instance. Should only be called if the underlying device is a KFilterDev!

Parameters:
fileName - the original file name

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)
Description copied from class: KArchive
Writes a symbolic link to the archive if the archive must be opened for writing.

Overrides:
writeSymLink in class KArchive
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

writeDir

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

Overrides:
writeDir in class KArchive
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)
Description copied from class: KArchive
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.

Overrides:
writeDir in class KArchive
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

prepareWriting

public boolean prepareWriting(java.lang.String name,
                              java.lang.String user,
                              java.lang.String group,
                              int size)
Description copied from class: KArchive
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.

Overrides:
prepareWriting in class KArchive
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)
Description copied from class: KArchive
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.

Overrides:
prepareWriting in class KArchive
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

doneWriting

public boolean doneWriting(int size)
Description copied from class: KArchive
Call doneWriting after writing the data.

Overrides:
doneWriting in class KArchive
Parameters:
size - the size of the file
See Also:
KArchive.prepareWriting(java.lang.String, java.lang.String, java.lang.String, int)

openArchive

protected boolean openArchive(int mode)
Opens the archive for reading. Parses the directory listing of the archive and creates the KArchiveDirectory/KArchiveFile entries.

Parameters:
mode - the mode of the file

closeArchive

protected boolean closeArchive()

prepareWriting_impl

protected boolean prepareWriting_impl(java.lang.String name,
                                      java.lang.String user,
                                      java.lang.String group,
                                      int size,
                                      long perm,
                                      int atime,
                                      int mtime,
                                      int ctime)

writeDir_impl

protected boolean writeDir_impl(java.lang.String name,
                                java.lang.String user,
                                java.lang.String group,
                                long perm,
                                int atime,
                                int mtime,
                                int ctime)

writeSymLink_impl

protected boolean writeSymLink_impl(java.lang.String name,
                                    java.lang.String target,
                                    java.lang.String user,
                                    java.lang.String group,
                                    long perm,
                                    int atime,
                                    int mtime,
                                    int ctime)

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?