com.mucommander.file
Class AbstractRWArchiveFile

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
All Implemented Interfaces:
PermissionAccesses, PermissionTypes
Direct Known Subclasses:
ZipArchiveFile

public abstract class AbstractRWArchiveFile
extends AbstractArchiveFile

AbstractRWArchiveFile represents a read-write archive file. This class is abstract and implemented by all read-write archive files. In addition to the read-only operations defined by AbstractArchiveFile, it provides abstract methods for adding and deleting entries from the archive. The isWritableArchive() method impletemented by this class always returns true. However, write operations may not always be available depending on the underlying file (e.g. if random file access is required). In that case, isWritableArchive() should be overridden to return true only when write operations are available.

Author:
Maxence Bernard

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
protected AbstractRWArchiveFile(AbstractFile file)
          Creates an AbstractRWArchiveFile on top of the given file.
 
Method Summary
abstract  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.
abstract  void deleteEntry(ArchiveEntry entry)
          Deletes the specified entry from the archive.
 boolean isWritableArchive()
          Returns true: AbstractRWArchiveFile implementations are capable of adding or deleting entries.
abstract  void optimizeArchive()
          Processes the archive file to leave it in an optimal form.
abstract  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, getEntries, getEntryInputStream, 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, mkfile, moveTo, setParent, toString
 
Methods inherited from class com.mucommander.file.AbstractFile
addTrailingSeparator, calculateChecksum, calculateChecksum, calculateChecksum, changePermissions, checkCopyPrerequisites, copyRecursively, deleteRecursively, getAbsolutePath, getAncestor, getAncestor, getCanonicalPath, getChild, 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

AbstractRWArchiveFile

protected AbstractRWArchiveFile(AbstractFile file)
Creates an AbstractRWArchiveFile on top of the given file.

Parameters:
file - the file on top of which to create the archive
Method Detail

isWritableArchive

public boolean isWritableArchive()
Returns true: AbstractRWArchiveFile implementations are capable of adding or deleting entries. This method should be overridden if the implementation is capable of providing write access only under certain conditions, for example if it requires random access to the proxied archive file which may not always be available depending on the udnderlying file. If that is the case, this method should return true only when all conditions for providing write operations are met.

Specified by:
isWritableArchive in class AbstractArchiveFile
Returns:
true

addEntry

public abstract java.io.OutputStream addEntry(ArchiveEntry entry)
                                       throws java.io.IOException
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.

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 abstract void deleteEntry(ArchiveEntry entry)
                          throws java.io.IOException
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.

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 abstract void updateEntry(ArchiveEntry entry)
                          throws java.io.IOException
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.

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 abstract void optimizeArchive()
                              throws java.io.IOException
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.

Throws:
java.io.IOException - if an I/O error occurs


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