com.mucommander.file
Class ArchiveEntryFile

java.lang.Object
  extended by com.mucommander.file.AbstractFile
      extended by com.mucommander.file.ArchiveEntryFile
All Implemented Interfaces:
PermissionAccesses, PermissionTypes

public class ArchiveEntryFile
extends AbstractFile

ArchiveEntryFile represents a file entry inside an archive. An ArchiveEntryFile is always associated with an ArchiveEntry object which contains information about the entry (name, size, date, ...) and with an AbstractArchiveFile which acts as an entry repository and provides operations such as listing a directory entry's files, adding or removing entries (if the archive is writable), etc...

ArchiveEntryFile implements AbstractFile by delegating methods to the ArchiveEntry and AbstractArchiveFile instances. ArchiveEntryFile is agnostic to the actual archive format. In other words, there is no need to extend this class for a particular archive format, ArchiveEntry and AbstractArchiveFile provide a general framework that isolates from the archive format's specifics.

Author:
Maxence Bernard

Field Summary
protected  AbstractArchiveFile archiveFile
          The archive file that contains this entry
protected  ArchiveEntry entry
          The ArchiveEntry object that contains information about this entry
protected  boolean exists
          True if this entry exists in the archive
protected  AbstractFile parent
          This entry file's parent, can be the archive file itself if this entry is located at the top level
 
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 ArchiveEntryFile(FileURL url, AbstractArchiveFile archiveFile, ArchiveEntry entry, boolean exists)
          Creates a new ArchiveEntryFile.
 
Method Summary
 boolean canChangeDate()
          Returns true only if the archive file that contains this entry is writable.
 boolean canGetGroup()
          Returns true if this file implementation is able to return some information about file groups, not necessarily for all files or this file in particular but at least for some of them.
 boolean canGetOwner()
          Returns true if this file implementation is able to return some information about file owners, not necessarily for all files or this file in particular but at least for some of them.
 boolean canRunProcess()
          Always returns false: archive entries cannot run processes.
 boolean changeDate(long lastModified)
          Always returns false only if the archive file that contains this entry is not writable.
 boolean changePermission(int access, int permission, boolean enabled)
          Always returns false only if the archive file that contains this entry is not writable.
 boolean changePermissions(int permissions)
          Always returns false only if the archive file that contains this entry is not writable.
 void delete()
          Deletes this entry from the associated AbstractArchiveFile if it is writable (as reported by AbstractArchiveFile.isWritableArchive()).
 boolean exists()
          Returns true if this entry exists within the archive file.
 AbstractArchiveFile getArchiveFile()
          Returns the AbstractArchiveFile that contains the entry represented by this file.
 java.lang.String getCanonicalPath()
          This method is overridden to use the archive file's canonical path as the base path of this entry file.
 PermissionBits getChangeablePermissions()
          Returns PermissionBits.FULL_PERMISSION_BITS or PermissionBits.EMPTY_PERMISSION_BITS, depending on whether the archive that contains this entry is writable or not.
 long getDate()
          Returns this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
 ArchiveEntry getEntry()
          Returns the ArchiveEntry instance that contains information about the archive entry (path, size, date, ...).
 long getFreeSpace()
          Delegates to the archive file's AbstractArchiveFile.getFreeSpace() method.
 java.lang.String getGroup()
          Returns information about the group this file belongs to.
 java.io.InputStream getInputStream()
          Delegates to the archive file's AbstractArchiveFile.getEntryInputStream(ArchiveEntry)} method.
 int getMoveToHint(AbstractFile destFile)
          Returns a hint that indicates whether the AbstractFile.moveTo(AbstractFile) method should be used to move this file to the specified destination file, rather than moving the file using AbstractFile.copyStream(InputStream, boolean) or AbstractFile.getInputStream() and AbstractFile.getOutputStream(boolean).
 java.io.OutputStream getOutputStream(boolean append)
          Returns an OutputStream that allows to write this entry's contents if the archive is writable (as reported by AbstractArchiveFile.isWritableArchive()).
 java.lang.String getOwner()
          Returns information about the owner of this file.
 AbstractFile getParent()
          Returns this file's parent, null if it doesn't have one.
 FilePermissions getPermissions()
          Returns this file's permissions, as a FilePermissions object.
 RandomAccessInputStream getRandomAccessInputStream()
          Always throws an IOException: random read access is not available for archive entries.
 RandomAccessOutputStream getRandomAccessOutputStream()
          Always throws an IOException: random write access is not available for archive entries.
 java.lang.String getRelativeEntryPath()
          Returns the relative path of this entry, with respect to the archive file.
 java.lang.String getSeparator()
          This method is overridden to return the separator of the archive file that contains this entry.
 long getSize()
          Returns this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined.
 long getTotalSpace()
          Delegates to the archive file's ProxyFile.getTotalSpace() method.
 java.lang.Object getUnderlyingFileObject()
          Returns the same ArchiveEntry instance as getEntry().
 boolean hasRandomAccessInputStream()
          Always returns false: random read access is not available for archive entries.
 boolean hasRandomAccessOutputStream()
          Always returns false: random write access is not available for archive entries.
 boolean isDirectory()
          Returns true if this file is a directory, false in any of the following cases: this file does not exist this file is a regular file this file is browsable (as reported by AbstractFile.isBrowsable() but not a directory
 boolean isSymlink()
          Always returns false.
 AbstractFile[] ls()
          Returns the children files that this file contains.
 AbstractFile[] ls(FileFilter filter)
          Returns the children files that this file contains, filtering out files that do not match the specified FileFilter.
 AbstractFile[] ls(FilenameFilter filter)
          Returns the children files that this file contains, filtering out files that do not match the specified FilenameFilter.
 void mkdir()
          Creates this entry as a directory in the associated AbstractArchiveFile if the archive is writable (as reported by AbstractArchiveFile.isWritableArchive()).
 AbstractProcess runProcess(java.lang.String[] tokens)
          Always throws an IOException: archive entries cannot run processes.
 void setParent(AbstractFile parent)
          Sets this file's parent.
 
Methods inherited from class com.mucommander.file.AbstractFile
addTrailingSeparator, calculateChecksum, calculateChecksum, calculateChecksum, changePermissions, checkCopyPrerequisites, copyRecursively, copyStream, copyTo, deleteRecursively, deleteRecursively, equals, getAbsolutePath, getAbsolutePath, getAncestor, getAncestor, getCanonicalFile, getCanonicalPath, getChild, getCopyToHint, getDirectChild, getExtension, getExtension, getIcon, getIcon, getInputStream, getJavaNetURL, getName, getNameWithoutExtension, getParentArchive, getParentSilently, getPermissionsString, getRoot, getTopAncestor, getURL, hasAncestor, hasAncestor, hashCode, importPermissions, importPermissions, isBrowsable, isHidden, isParentOf, isRoot, mkdir, mkdirs, mkfile, mkfile, moveTo, removeTrailingSeparator, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

archiveFile

protected AbstractArchiveFile archiveFile
The archive file that contains this entry


parent

protected AbstractFile parent
This entry file's parent, can be the archive file itself if this entry is located at the top level


entry

protected ArchiveEntry entry
The ArchiveEntry object that contains information about this entry


exists

protected boolean exists
True if this entry exists in the archive

Constructor Detail

ArchiveEntryFile

protected ArchiveEntryFile(FileURL url,
                           AbstractArchiveFile archiveFile,
                           ArchiveEntry entry,
                           boolean exists)
Creates a new ArchiveEntryFile.

Parameters:
url - the FileURL instance that represents this file's location
archiveFile - the AbstractArchiveFile instance that contains this entry
entry - the ArchiveEntry object that contains information about this entry
exists - true if this entry exists in the archive
Method Detail

getEntry

public ArchiveEntry getEntry()
Returns the ArchiveEntry instance that contains information about the archive entry (path, size, date, ...).

Returns:
the ArchiveEntry instance that contains information about the archive entry (path, size, date, ...)

getArchiveFile

public AbstractArchiveFile getArchiveFile()
Returns the AbstractArchiveFile that contains the entry represented by this file.

Returns:
the AbstractArchiveFile that contains the entry represented by this file

getRelativeEntryPath

public java.lang.String getRelativeEntryPath()
Returns the relative path of this entry, with respect to the archive file. The path separator of the returned path is the one returned by getSeparator(). As a relative path, the returned path does not start with a separator character.

Returns:
the relative path of this entry, with respect to the archive file.

getDate

public long getDate()
Description copied from class: AbstractFile
Returns this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).

Specified by:
getDate in class AbstractFile
Returns:
this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)

canChangeDate

public boolean canChangeDate()
Returns true only if the archive file that contains this entry is writable.

Specified by:
canChangeDate in class AbstractFile
Returns:
true if this file's date can be changed using AbstractFile.changeDate(long)

changeDate

public boolean changeDate(long lastModified)
Always returns false only if the archive file that contains this entry is not writable.

Specified by:
changeDate in class AbstractFile
Parameters:
lastModified - last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
Returns:
true if date was changed successfully.

getSize

public long getSize()
Description copied from class: AbstractFile
Returns this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined.

Specified by:
getSize in class AbstractFile
Returns:
this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined

isDirectory

public boolean isDirectory()
Description copied from class: AbstractFile
Returns true if this file is a directory, false in any of the following cases:

Specified by:
isDirectory in class AbstractFile
Returns:
true if this file is a directory, false in any of the cases listed above

ls

public AbstractFile[] ls()
                  throws java.io.IOException
Description copied from class: AbstractFile
Returns the children files that this file contains. For this operation to be successful, this file must be 'browsable', i.e. AbstractFile.isBrowsable() must return true. This method may return a zero-length array if it has no children but may never return null.

Specified by:
ls in class AbstractFile
Returns:
the children files that this file contains
Throws:
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.

ls

public AbstractFile[] ls(FilenameFilter filter)
                  throws java.io.IOException
Description copied from class: AbstractFile
Returns the children files that this file contains, filtering out files that do not match the specified FilenameFilter. For this operation to be successful, this file must be 'browsable', i.e. AbstractFile.isBrowsable() must return true.

This default implementation filters out files *after* they have been created. This method should be overridden if a more efficient implementation can be provided by subclasses.

Overrides:
ls in class AbstractFile
Parameters:
filter - the FilenameFilter to be used to filter out files from the list, may be null
Returns:
the children files that this file contains
Throws:
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.

ls

public AbstractFile[] ls(FileFilter filter)
                  throws java.io.IOException
Description copied from class: AbstractFile
Returns the children files that this file contains, filtering out files that do not match the specified FileFilter. For this operation to be successful, this file must be 'browsable', i.e. AbstractFile.isBrowsable() must return true.

Overrides:
ls in class AbstractFile
Parameters:
filter - the FileFilter to be used to filter files out from the list, may be null
Returns:
the children files that this file contains
Throws:
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.

getParent

public AbstractFile getParent()
Description copied from class: AbstractFile
Returns this file's parent, null if it doesn't have one.

Specified by:
getParent in class AbstractFile
Returns:
this file's parent, null if it doesn't have one

setParent

public void setParent(AbstractFile parent)
Description copied from class: AbstractFile
Sets this file's parent. null can be specified if this file doesn't have a parent.

Specified by:
setParent in class AbstractFile
Parameters:
parent - the new parent of this file

exists

public boolean exists()
Returns true if this entry exists within the archive file.

Specified by:
exists in class AbstractFile
Returns:
true if this entry exists within the archive file

getPermissions

public FilePermissions getPermissions()
Description copied from class: AbstractFile
Returns this file's permissions, as a FilePermissions object. Note that this file may only support certain permission bits, use the permission mask to find out which bits are supported.

This method may return permissions for which none of the bits are supported, but may never return null.

Specified by:
getPermissions in class AbstractFile
Returns:
this file's permissions, as a FilePermissions object

getChangeablePermissions

public PermissionBits getChangeablePermissions()
Returns PermissionBits.FULL_PERMISSION_BITS or PermissionBits.EMPTY_PERMISSION_BITS, depending on whether the archive that contains this entry is writable or not.

Specified by:
getChangeablePermissions in class AbstractFile
Returns:
a bit mask describing the permission bits that can be changed on this file

changePermission

public boolean changePermission(int access,
                                int permission,
                                boolean enabled)
Always returns false only if the archive file that contains this entry is not writable.

Specified by:
changePermission in class AbstractFile
Parameters:
access - see PermissionTypes for allowed values
permission - see PermissionAccesses for allowed values
enabled - true to enable the flag, false to disable it
Returns:
true if the permission flag was successfully set for the access type
See Also:
AbstractFile.getChangeablePermissions()

getOwner

public java.lang.String getOwner()
Description copied from class: AbstractFile
Returns information about the owner of this file. The kind of information that is returned is implementation-dependant. It may typically be a username (e.g. 'bob') or a user ID (e.g. '501'). If the owner information is not available to the AbstractFile implementation (cannot be retrieved or the filesystem doesn't have any notion of owner) or not available for this particular file, null will be returned.

Specified by:
getOwner in class AbstractFile
Returns:
information about the owner of this file

canGetOwner

public boolean canGetOwner()
Description copied from class: AbstractFile
Returns true if this file implementation is able to return some information about file owners, not necessarily for all files or this file in particular but at least for some of them. In other words, a true return value doesn't mean that AbstractFile.getOwner() will necessarily return a non-null value, but rather that there is a chance that it does.

Specified by:
canGetOwner in class AbstractFile
Returns:
true if this file implementation is able to return information about file owners

getGroup

public java.lang.String getGroup()
Description copied from class: AbstractFile
Returns information about the group this file belongs to. The kind of information that is returned is implementation-dependant. It may typically be a group name (e.g. 'www-data') or a group ID (e.g. '501'). If the group information is not available to the AbstractFile implementation (cannot be retrieved or the filesystem doesn't have any notion of owner) or not available for this particular file, null will be returned.

Specified by:
getGroup in class AbstractFile
Returns:
information about the owner of this file

canGetGroup

public boolean canGetGroup()
Description copied from class: AbstractFile
Returns true if this file implementation is able to return some information about file groups, not necessarily for all files or this file in particular but at least for some of them. In other words, a true return value doesn't mean that AbstractFile.getGroup() will necessarily return a non-null value, but rather that there is a chance that it does.

Specified by:
canGetGroup in class AbstractFile
Returns:
true if this file implementation is able to return information about file groups

isSymlink

public boolean isSymlink()
Always returns false.

Specified by:
isSymlink in class AbstractFile
Returns:
true if this file is a symbolic link

delete

public void delete()
            throws java.io.IOException
Deletes this entry from the associated AbstractArchiveFile if it is writable (as reported by AbstractArchiveFile.isWritableArchive()). Throws an IOException in any of the following cases:

Specified by:
delete in class AbstractFile
Throws:
java.io.IOException - in any of the cases listed above.

mkdir

public void mkdir()
           throws java.io.IOException
Creates this entry as a directory in the associated AbstractArchiveFile if the archive is writable (as reported by AbstractArchiveFile.isWritableArchive()). Throws an IOException if it isn't, if this entry already exists in the archive or if an I/O error occurred.

Specified by:
mkdir in class AbstractFile
Throws:
java.io.IOException - if the associated archive file is not writable, if this entry already exists in the archive, or if an I/O error occurred

getFreeSpace

public long getFreeSpace()
Delegates to the archive file's AbstractArchiveFile.getFreeSpace() method.

Specified by:
getFreeSpace in class AbstractFile
Returns:
the free space (in bytes) on the disk/volume where this file is, -1 if this information is not available.

getTotalSpace

public long getTotalSpace()
Delegates to the archive file's ProxyFile.getTotalSpace() method.

Specified by:
getTotalSpace in class AbstractFile
Returns:
the total space (in bytes) of the disk/volume where this file is, -1 if this information is not available

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Delegates to the archive file's AbstractArchiveFile.getEntryInputStream(ArchiveEntry)} method.

Specified by:
getInputStream in class AbstractFile
Returns:
an InputStream to read the contents of this file
Throws:
java.io.IOException - in any of the cases listed above

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.IOException
Returns an OutputStream that allows to write this entry's contents if the archive is writable (as reported by AbstractArchiveFile.isWritableArchive()). Throws an IOException if it isn't or if an I/O error occurred.

This method will create this entry as a regular file in the archive if it doesn't already exist, or replace it if it already does.

Specified by:
getOutputStream in class AbstractFile
Parameters:
append - if true, data written to the OutputStream will be appended to the end of this file. If false, any existing data this file contains will be discarded and overwritten.
Returns:
an OuputStream to write the contents of this file
Throws:
java.io.IOException - if the associated archive file is not writable, if this entry already exists in the archive, or if an I/O error occurred

hasRandomAccessInputStream

public boolean hasRandomAccessInputStream()
Always returns false: random read access is not available for archive entries.

Specified by:
hasRandomAccessInputStream in class AbstractFile
Returns:
true if the underlying filesystem has support for random access input streams

getRandomAccessInputStream

public RandomAccessInputStream getRandomAccessInputStream()
                                                   throws java.io.IOException
Always throws an IOException: random read access is not available for archive entries.

Specified by:
getRandomAccessInputStream in class AbstractFile
Returns:
a RandomAccessInputStream to read the contents of this file with random access
Throws:
java.io.IOException - in any of the cases listed above

hasRandomAccessOutputStream

public boolean hasRandomAccessOutputStream()
Always returns false: random write access is not available for archive entries.

Specified by:
hasRandomAccessOutputStream in class AbstractFile
Returns:
true if the underlying filesystem has support for random access output streams

getRandomAccessOutputStream

public RandomAccessOutputStream getRandomAccessOutputStream()
                                                     throws java.io.IOException
Always throws an IOException: random write access is not available for archive entries.

Specified by:
getRandomAccessOutputStream in class AbstractFile
Returns:
a RandomAccessOutputStream to write the contents of this file with random access
Throws:
java.io.IOException - in any of the cases listed above

getUnderlyingFileObject

public java.lang.Object getUnderlyingFileObject()
Returns the same ArchiveEntry instance as getEntry().

Specified by:
getUnderlyingFileObject in class AbstractFile
Returns:
the file Object of the underlying API providing access to the filesystem, null if there is none

canRunProcess

public boolean canRunProcess()
Always returns false: archive entries cannot run processes.

Specified by:
canRunProcess in class AbstractFile
Returns:
true if it's possible to run processes on the underlying file system, false otherwise.

runProcess

public AbstractProcess runProcess(java.lang.String[] tokens)
                           throws java.io.IOException
Always throws an IOException: archive entries cannot run processes.

Specified by:
runProcess in class AbstractFile
Parameters:
tokens - command and its arguments for the process to create.
Returns:
a process executing the specified command tokens using this file as a working directory.
Throws:
java.io.IOException - thrown if an error occured while creating the process, if the current file is not a directory or if the operation is not supported.

getSeparator

public java.lang.String getSeparator()
This method is overridden to return the separator of the archive file that contains this entry.

Overrides:
getSeparator in class AbstractFile
Returns:
the separator of the archive file that contains this entry

getCanonicalPath

public java.lang.String getCanonicalPath()
This method is overridden to use the archive file's canonical path as the base path of this entry file.

Overrides:
getCanonicalPath in class AbstractFile
Returns:
the canonical path to this file

changePermissions

public boolean changePermissions(int permissions)
Always returns false only if the archive file that contains this entry is not writable.

Overrides:
changePermissions in class AbstractFile
Parameters:
permissions - new permissions for this file
Returns:
true if the operation was successful, false if at least one of the file permissions could not be changed

getMoveToHint

public int getMoveToHint(AbstractFile destFile)
Description copied from class: AbstractFile
Returns a hint that indicates whether the AbstractFile.moveTo(AbstractFile) method should be used to move this file to the specified destination file, rather than moving the file using AbstractFile.copyStream(InputStream, boolean) or AbstractFile.getInputStream() and AbstractFile.getOutputStream(boolean).

Potential returned values are:

This default implementation returns AbstractFile.SHOULD_HINT if both this file and the specified destination file use the same protocol and are located on the same host, AbstractFile.SHOULD_NOT_HINT otherwise. This method should be overridden to return AbstractFile.SHOULD_NOT_HINT if the underlying file protocol doesn't not allow direct move/renaming without copying the contents of the source (this) file.

Overrides:
getMoveToHint in class AbstractFile
Parameters:
destFile - the destination file that is considered being copied
Returns:
the hint int indicating whether the AbstractFile.moveTo(AbstractFile) method should be used


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