org.at4j.zip
Class ZipFileEntry

java.lang.Object
  extended by org.at4j.archive.AbstractArchiveEntry<ZipEntry,ZipDirectoryEntry>
      extended by org.at4j.zip.ZipEntry
          extended by org.at4j.zip.ZipFileEntry
All Implemented Interfaces:
ArchiveEntry<ZipEntry,ZipDirectoryEntry>, ArchiveFileEntry<ZipEntry,ZipDirectoryEntry>, Lockable, ReadLockable, ReadWriteLockable, WriteLockable, Named, NamedReadableFile, RandomlyAccessibleFile, ReadableFile

public class ZipFileEntry
extends ZipEntry
implements ArchiveFileEntry<ZipEntry,ZipDirectoryEntry>

This object represents a file entry in a Zip archive. In addition to the properties inherited from the ZipEntry object, a file entry has some properties of its own. The file's data is compressed using a ZipEntryCompressionMethod. The file has a set of internal file attributes represented by a ZipInternalFileAttributes object and the entry keeps track of the compressed and the uncompressed size of the file data, and the file has a CRC 32 checksum of its data.

Only the Zip file entries that are stored uncompressed ( StoredCompressionMethod) support being opened for random access. If it is stored with another compression method, its openForRandomAccess method will throw an UnsupportedOperationException.

Zip entries are always immutable.

Since:
1.0
Author:
Karl Gustafsson
See Also:
ZipDirectoryEntry, ZipSymbolicLinkEntry

Constructor Summary
ZipFileEntry(ZipEntryCollaborator collaborator, ZipEntryCentralFileHeaderData zecd, ZipEntryLocalFileHeaderData zeld)
          Create a new Zip file entry.
 
Method Summary
 UnsignedInteger getCompressedSize()
          Get the size of the file data when as it is compressed in the Zip file.
 ZipEntryCompressionMethod getCompressionMethod()
          Get the compression method for the Zip file entry.
 UnsignedInteger getCrc32()
          Get the checksum calculated on the file contents.
 long getDataSize()
          Get the uncompressed size of file data.
 long getSize()
          Get the compressed size of the Zip file entry.
 UnsignedInteger getUncompressedSize()
          Get the size of the file data when it has been uncompressed.
 EntityLock getWriteLock()
          This method returns a dummy lock.
 boolean isAppearingToBeTextFile()
          Does this file appear to be a text file?
 boolean isCompressedPatchData()
          Is the Zip file entry compressed patched data?
 boolean isWriteLockedByCurrentThread()
          This method always returns true.
 EntityLock lockForWriting()
          This method returns a dummy lock.
 ScatteringByteChannel openChannelForRead()
          Open a ReadableByteChannel for reading from the file.
 RandomAccess openForRandomAccess(RandomAccessMode ram)
          Open the file for random access in the specified mode.
 InputStream openForRead()
          Opens the file for reading.
 String toString()
           
 
Methods inherited from class org.at4j.zip.ZipEntry
getComment, getDiskNumberStart, getExternalFileAttributes, getExtraField, getExtraFields, getGeneralPurposeBitFlags, getLastModified, getVersionNeededToExtract, getVersionUsedToCreate, isEncrypted, isStrongEncryption
 
Methods inherited from class org.at4j.archive.AbstractArchiveEntry
getCollaborator, getLocation, getName, getParent, getReadLock, isReadLockedByCurrentThread, lockForReading
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.at4j.archive.ArchiveEntry
getLocation, getParent
 
Methods inherited from interface org.entityfs.Named
getName
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 

Constructor Detail

ZipFileEntry

public ZipFileEntry(ZipEntryCollaborator collaborator,
                    ZipEntryCentralFileHeaderData zecd,
                    ZipEntryLocalFileHeaderData zeld)
Create a new Zip file entry.

Parameters:
collaborator - The parent Zip archive's entry collaborator.
zecd - Data parsed from the file's record in the central directory.
zeld - Data parsed from the file entry's local header.
Method Detail

isCompressedPatchData

public boolean isCompressedPatchData()
Is the Zip file entry compressed patched data?

Returns:
true if the Zip file entry is compressed patched data.

getCompressionMethod

public ZipEntryCompressionMethod getCompressionMethod()
Get the compression method for the Zip file entry.

Returns:
The compression method for the Zip file entry.

getDataSize

public long getDataSize()
Get the uncompressed size of file data. This method returns the same value as getUncompressedSize().

Specified by:
getDataSize in interface ReadableFile
Returns:
The size of uncompressed data, in bytes.
See Also:
getUncompressedSize(), getSize()

getUncompressedSize

public UnsignedInteger getUncompressedSize()
Get the size of the file data when it has been uncompressed. This method returns the same value as getSize().

Returns:
The size of uncompressed data, in bytes.
See Also:
getDataSize(), getCompressedSize()

getCompressedSize

public UnsignedInteger getCompressedSize()
Get the size of the file data when as it is compressed in the Zip file. This method returns the same value as getSize().

Returns:
The size of compressed data, in bytes.
See Also:
getSize(), getUncompressedSize()

getSize

public long getSize()
Get the compressed size of the Zip file entry. This method returns the same value as getCompressedSize().

Specified by:
getSize in interface ReadableFile
Returns:
The size of compressed data, in bytes.
See Also:
getDataSize(), getCompressedSize()

getCrc32

public UnsignedInteger getCrc32()
Get the checksum calculated on the file contents.

Returns:
The checksum calculated on the file contents.
See Also:
CRC32

isAppearingToBeTextFile

public boolean isAppearingToBeTextFile()
Does this file appear to be a text file?

Returns:
true if the file appears to be a text file, false if it appears to be a binary file.

lockForWriting

public EntityLock lockForWriting()
                          throws LockTimeoutException
This method returns a dummy lock.

Specified by:
lockForWriting in interface WriteLockable
Returns:
A dummy lock.
Throws:
LockTimeoutException - If the lock acquiring timed out. (It is up to the LockAcquiringStrategy to decide if lock acquiring can time out.)

getWriteLock

public EntityLock getWriteLock()
This method returns a dummy lock.

Specified by:
getWriteLock in interface WriteLockable
Returns:
A dummy lock.

isWriteLockedByCurrentThread

public boolean isWriteLockedByCurrentThread()
This method always returns true.

Specified by:
isWriteLockedByCurrentThread in interface WriteLockable
Returns:
true, always.

openChannelForRead

public ScatteringByteChannel openChannelForRead()
                                         throws UnsupportedOperationException
Description copied from interface: ReadableFile
Open a ReadableByteChannel for reading from the file. The semantics of this method is the same as for ReadableFile.openForRead().

Although a read lock on the file is required for the execution thread opening the channel, the channel itself is not protected from access by other threads. It can be protected by wrapping it in a LockAwareReadableByteChannel.

Specified by:
openChannelForRead in interface ReadableFile
Returns:
An open ReadableByteChannel. The channel must be closed by the caller. The channel may be a ScatteringByteChannel, but that is not required.
Throws:
UnsupportedOperationException
See Also:
ReadableFile.openForRead()

openForRead

public InputStream openForRead()
                        throws UnsupportedCompressionMethodException,
                               ZipFileParseException
Description copied from interface: ReadableFile
Opens the file for reading. The caller is responsible for closing the returned stream.

Although a read lock on the file is required for the execution thread opening the stream, the stream itself is not protected from access by other threads. It can be protected by wrapping it in a LockAwareInputStream.

Specified by:
openForRead in interface ReadableFile
Returns:
An InputStream on the file. The stream must be closed by the caller.
Throws:
UnsupportedCompressionMethodException
ZipFileParseException

openForRandomAccess

public RandomAccess openForRandomAccess(RandomAccessMode ram)
                                 throws UnsupportedCompressionMethodException,
                                        UnsupportedOperationException,
                                        ZipFileParseException
Description copied from interface: RandomlyAccessibleFile
Open the file for random access in the specified mode.

Although a read or write lock on the file is required for the execution thread opening the RandomAccess, the RandomAccess object itself is not protected from access by other threads. It can be protected by wrapping it in a LockAwareRandomAccess object.

Specified by:
openForRandomAccess in interface RandomlyAccessibleFile
Parameters:
ram - The mode to open the file in.
Returns:
An open RandomAccess object. It must be closed by the caller.
Throws:
UnsupportedCompressionMethodException
UnsupportedOperationException
ZipFileParseException

toString

public String toString()
Overrides:
toString in class Object