org.at4j.tar
Class TarFileEntry

java.lang.Object
  extended by org.at4j.archive.AbstractArchiveEntry<TarEntry,TarDirectoryEntry>
      extended by org.at4j.tar.TarEntry
          extended by org.at4j.tar.TarFileEntry
All Implemented Interfaces:
ArchiveEntry<TarEntry,TarDirectoryEntry>, ArchiveFileEntry<TarEntry,TarDirectoryEntry>, Lockable, ReadLockable, ReadWriteLockable, WriteLockable, Named, NamedReadableFile, RandomlyAccessibleFile, ReadableFile
Direct Known Subclasses:
UstarFileEntry

public class TarFileEntry
extends TarEntry
implements ArchiveFileEntry<TarEntry,TarDirectoryEntry>

This object represents a Unix v7 Tar file entry. All Tar file entries support being opened for random access.

Tar entry objects are always immutable.

Since:
1.0
Author:
Karl Gustafsson
See Also:
TarDirectoryEntry, TarSymbolicLinkEntry

Method Summary
 long getDataSize()
          Get the size of the file data for this Tar file entry.
protected  UnixEntityMode getDefaultEntityMode()
          Subclasses implement this to return the default Unix entity mode if none is set in the Tar file.
 long getSize()
          Get the size of the file data for this Tar file entry.
 long getStartPosOfFileData()
          Get the start position of file data in the Tar file for this Tar file entry.
 EntityLock getWriteLock()
          This method returns a dummy lock.
 boolean isWriteLockedByCurrentThread()
          This method always returns true.
 EntityLock lockForWriting()
          This method returns a dummy lock.
 ScatteringByteChannel openChannelForRead()
          Open a ScatteringByteChannel that a client can use to read file data from the Tar file entry.
 RandomAccess openForRandomAccess(RandomAccessMode ram)
          Open the file for random access in the specified mode.
 InputStream openForRead()
          Open an InputStream that a client can use to read file data from the Tar file entry.
 
Methods inherited from class org.at4j.tar.TarEntry
getChecksum, getEntityMode, getLastModificationTime, getOwnerGid, getOwnerUid
 
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, toString, 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
 

Method Detail

getDefaultEntityMode

protected UnixEntityMode getDefaultEntityMode()
Description copied from class: TarEntry
Subclasses implement this to return the default Unix entity mode if none is set in the Tar file. This is called from the constructor.

Specified by:
getDefaultEntityMode in class TarEntry
Returns:
The default entity mode for the entry type.

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()
Open a ScatteringByteChannel that a client can use to read file data from the Tar file entry.

Specified by:
openChannelForRead in interface ReadableFile
Returns:
A channel that the client can read data from.
See Also:
ReadableFile.openForRead()

openForRead

public InputStream openForRead()
Open an InputStream that a client can use to read file data from the Tar file entry.

Specified by:
openForRead in interface ReadableFile
Returns:
An open input stream.

openForRandomAccess

public RandomAccess openForRandomAccess(RandomAccessMode ram)
                                 throws ReadOnlyException
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:
ReadOnlyException - If the client tries to open a read only file for writing.

getStartPosOfFileData

public long getStartPosOfFileData()
Get the start position of file data in the Tar file for this Tar file entry.

Clients seldom have to bother with this.

Returns:
The start position of this file entry's data.

getDataSize

public long getDataSize()
Get the size of the file data for this Tar file entry. This is a value between 0 and 8589934591 bytes (~ 8.6 Gb) (inclusive).

This method returns the same value as getSize().

Specified by:
getDataSize in interface ReadableFile
Returns:
The size of the file data for this Tar file entry.
See Also:
ReadableFile.getSize()

getSize

public long getSize()
Get the size of the file data for this Tar file entry. This is a value between 0 and 8589934591 bytes (~ 8.6 Gb) (inclusive).

This method returns the same value as getDataSize().

Specified by:
getSize in interface ReadableFile
Returns:
The size of the file data for this Tar file entry.
See Also:
ReadableFile.getDataSize()