com.mucommander.file.impl.zip
Class ZipArchiveFile

java.lang.Object
  extended by com.mucommander.file.AbstractFile
      extended by com.mucommander.file.impl.ProxyFile
          extended by com.mucommander.file.AbstractArchiveFile
              extended by com.mucommander.file.AbstractRWArchiveFile
                  extended by com.mucommander.file.impl.zip.ZipArchiveFile
All Implemented Interfaces:
PermissionAccesses, PermissionTypes

public class ZipArchiveFile
extends AbstractRWArchiveFile

ZipArchiveFile provides read and write access (under certain conditions) to archives in the Zip format.

Two different packages that implement the actual Zip compression format are used: the homemade com.mucommander.file.impl.zip.provider package and Java's java.util.zip. com.mucommander.file.impl.zip.provider provides additional functionality and improved performance over java.util.zip but requires the underlying file to supply a RandomAccessInputStream for read access and a RandomAccessOutputStream for write access. If the underlying file can't provide at least a RandomAccessInputStream, the lesser java.util.zip package is used.

Author:
Maxence Bernard
See Also:
ZipFormatProvider, ZipFile

Field Summary
 
Fields inherited from class com.mucommander.file.AbstractArchiveFile
entryTreeDate, entryTreeRoot
 
Fields inherited from class com.mucommander.file.impl.ProxyFile
file
 
Fields inherited from class com.mucommander.file.AbstractFile
DEFAULT_SEPARATOR, fileURL, IO_BUFFER_SIZE, MUST_HINT, MUST_NOT_HINT, SHOULD_HINT, SHOULD_NOT_HINT, windowsDriveRootPattern
 
Fields inherited from interface com.mucommander.file.PermissionTypes
EXECUTE_PERMISSION, READ_PERMISSION, WRITE_PERMISSION
 
Fields inherited from interface com.mucommander.file.PermissionAccesses
GROUP_ACCESS, OTHER_ACCESS, USER_ACCESS
 
Constructor Summary
ZipArchiveFile(AbstractFile file)
          Creates a new ZipArchiveFile on top of the given file.
 
Method Summary
 java.io.OutputStream addEntry(ArchiveEntry entry)
          Adds the given entry to the archive and returns an OutputStream to write the entry's contents if the entry is a regular file, null if the entry is a directory.
 void deleteEntry(ArchiveEntry entry)
          Deletes the specified entry from the archive.
 java.util.Vector getEntries()
          Returns a Vector of ArchiveEntry, representing all the entries this archive file contains.
 java.io.InputStream getEntryInputStream(ArchiveEntry entry)
          Returns an InputStream to read from the given archive entry.
 boolean isWritableArchive()
          Returns true only if the proxied archive file has random read and write access, as reported by ProxyFile.hasRandomAccessInputStream() and ProxyFile.hasRandomAccessOutputStream() respectively.
 void mkfile()
          Creates an empty, valid Zip file.
 void optimizeArchive()
          Processes the archive file to leave it in an optimal form.
 void updateEntry(ArchiveEntry entry)
          Updates the specified entry in the archive with the attributes containted in the ArchiveEntry object.
 
Methods inherited from class com.mucommander.file.AbstractArchiveFile
addToEntriesTree, canRunProcess, checkEntriesTree, createEntriesTree, declareEntriesTreeUpToDate, getArchiveEntryFile, getArchiveEntryFile, getFreeSpace, isBrowsable, isDirectory, ls, ls, ls, ls, ls, removeFromEntriesTree, runProcess
 
Methods inherited from class com.mucommander.file.impl.ProxyFile
canChangeDate, canGetGroup, canGetOwner, changeDate, changePermission, changePermissions, copyStream, copyTo, delete, deleteRecursively, equals, exists, getAbsolutePath, getCanonicalFile, getCanonicalPath, getChangeablePermissions, getCopyToHint, getDate, getExtension, getGroup, getInputStream, getInputStream, getJavaNetURL, getMoveToHint, getName, getOutputStream, getOwner, getParent, getPermissions, getPermissionsString, getProxiedFile, getRandomAccessInputStream, getRandomAccessOutputStream, getRoot, getSeparator, getSize, getTotalSpace, getUnderlyingFileObject, getURL, hashCode, hasRandomAccessInputStream, hasRandomAccessOutputStream, importPermissions, importPermissions, isHidden, isRoot, isSymlink, mkdir, moveTo, setParent, toString
 
Methods inherited from class com.mucommander.file.AbstractFile
addTrailingSeparator, calculateChecksum, calculateChecksum, calculateChecksum, changePermissions, checkCopyPrerequisites, copyRecursively, deleteRecursively, getAbsolutePath, getAncestor, getAncestor, getCanonicalPath, getChild, getChildSilently, getDirectChild, getExtension, getIcon, getIcon, getNameWithoutExtension, getParentArchive, getParentSilently, getTopAncestor, hasAncestor, hasAncestor, isParentOf, mkdir, mkdirs, mkfile, removeTrailingSeparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipArchiveFile

public ZipArchiveFile(AbstractFile file)
Creates a new ZipArchiveFile on top of the given file.

Parameters:
file - the underlying archive file
Method Detail

getEntries

public java.util.Vector getEntries()
                            throws java.io.IOException
Description copied from class: AbstractArchiveFile
Returns a Vector of ArchiveEntry, representing all the entries this archive file contains. This method will be called the first time one of the ls() is called. If will not be further called, unless the file's date has changed since the last time one of the ls() methods was called.

Specified by:
getEntries in class AbstractArchiveFile
Throws:
java.io.IOException

getEntryInputStream

public java.io.InputStream getEntryInputStream(ArchiveEntry entry)
                                        throws java.io.IOException
Description copied from class: AbstractArchiveFile
Returns an InputStream to read from the given archive entry. The specified ArchiveEntry instance is necessarily one of the entries that were returned by AbstractArchiveFile.getEntries().

Specified by:
getEntryInputStream in class AbstractArchiveFile
Throws:
java.io.IOException

addEntry

public java.io.OutputStream addEntry(ArchiveEntry entry)
                              throws java.io.IOException
Description copied from class: AbstractRWArchiveFile
Adds the given entry to the archive and returns an OutputStream to write the entry's contents if the entry is a regular file, null if the entry is a directory. Throws an IOException if the entry already exists in the archive or if an I/O error occurs.

Specified by:
addEntry in class AbstractRWArchiveFile
Parameters:
entry - the entry to add to the archive
Returns:
an OutputStream to write the entry's contents if the entry is a regular file, null if the entry is a directory
Throws:
java.io.IOException - if the entry already exists in the archive or if an I/O error occurs

deleteEntry

public void deleteEntry(ArchiveEntry entry)
                 throws java.io.IOException
Description copied from class: AbstractRWArchiveFile
Deletes the specified entry from the archive. Throws an IOException if the entry doesn't exist in the archive or if an I/O error occurs.

Specified by:
deleteEntry in class AbstractRWArchiveFile
Parameters:
entry - the entry to delete from the archive
Throws:
java.io.IOException - if the entry doesn't exist in the archive or if an I/O error occurs

updateEntry

public void updateEntry(ArchiveEntry entry)
                 throws java.io.IOException
Description copied from class: AbstractRWArchiveFile
Updates the specified entry in the archive with the attributes containted in the ArchiveEntry object. Throws an IOException if the entry doesn't exist in the archive or if an I/O error occurs.

This methods can be used to update the entry's date and permissions for instance.

Specified by:
updateEntry in class AbstractRWArchiveFile
Parameters:
entry - the entry to update in the archive
Throws:
java.io.IOException - if the entry doesn't exist in the archive or if an I/O error occurs

optimizeArchive

public void optimizeArchive()
                     throws java.io.IOException
Description copied from class: AbstractRWArchiveFile
Processes the archive file to leave it in an optimal form. This method should be called after a writable archive has been modified (entries added or removed).

The actual effect of this method on the archive file depends on the kind of archive. It may be implemented as a no-op if there is no use for it. To illustrate, in the case of a ZipArchiveFile, this method removes chunks of free space that are left when entries are deleted.

Specified by:
optimizeArchive in class AbstractRWArchiveFile
Throws:
java.io.IOException - if an I/O error occurs

isWritableArchive

public boolean isWritableArchive()
Returns true only if the proxied archive file has random read and write access, as reported by ProxyFile.hasRandomAccessInputStream() and ProxyFile.hasRandomAccessOutputStream() respectively. If that is not the case, this archive has read-only access and behaves just like a AbstractROArchiveFile.

Overrides:
isWritableArchive in class AbstractRWArchiveFile
Returns:
true only if the proxied archive file has random read and write access

mkfile

public void mkfile()
            throws java.io.IOException
Creates an empty, valid Zip file. The resulting file is 22 bytes long.

Overrides:
mkfile in class ProxyFile
Throws:
java.io.IOException - if the file could not be created, either because it already exists or because of an I/O error


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard