org.entityfs.zip
Class ZipFileAdapter

java.lang.Object
  extended by org.entityfs.impl.impl.adapter.AbstractROEntityAdapter<ZipFileSystemAdapter,ZipDirectoryAdapter>
      extended by org.entityfs.zip.ZipFileAdapter
All Implemented Interfaces:
EntityAdapter, FileAdapter, ZipEntityAdapter

public class ZipFileAdapter
extends AbstractROEntityAdapter<ZipFileSystemAdapter,ZipDirectoryAdapter>
implements FileAdapter, ZipEntityAdapter


Constructor Summary
ZipFileAdapter(ZipFileSystemAdapter fs, ZipDirectoryAdapter parent, String name, ZipEntry entry)
           
 
Method Summary
 boolean canRead()
          Subclasses may override as needed.
 void copyFrom(ReadableByteChannel rbc)
           
 void copyTo(OutputStream os)
          Copy the file contents to the output stream.
 void copyTo(WritableByteChannel wbc)
          Copy the file contents to the writable channel.
 boolean exists()
          Subclasses may override as needed.
 long getDataSize()
          Get the file's data size in bytes.
 EntityType getEntityType()
          Get the EntityType for this entity.
 T getFileSystemAdapter()
          Get the FileSystemAdapter for the file system where the entity is.
 long getLastModified()
          Get the last modification time for an entity.
 long getSize()
          Get the file size in bytes.
 ZipEntry getZipEntry()
           
 void init()
          This implementation does nothing.
 ReadableByteChannel openChannelForRead()
           
 FileChannel openChannelForWrite(boolean append)
           
 RandomAccess openForRandomAccess(RandomAccessMode mode)
           
 InputStream openForRead()
          Open an InputStream on the file.
 OutputStream openForWrite(boolean append)
          Open the file for writing.
 void replaceContents(FileAdapter fa)
          Replace the contents of this file adapter with the contents of the supplied file adapter.
 
Methods inherited from class org.entityfs.impl.impl.adapter.AbstractROEntityAdapter
assertCanBeDeleted, canWrite, create, delete, getName, getParent, rename, setLastModified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.zip.ZipEntityAdapter
getZipEntry
 
Methods inherited from interface org.entityfs.impl.adapter.EntityAdapter
canRead, canWrite, create, delete, exists, getFileSystemAdapter, getLastModified, getName, getParent, init, rename, setLastModified
 

Constructor Detail

ZipFileAdapter

public ZipFileAdapter(ZipFileSystemAdapter fs,
                      ZipDirectoryAdapter parent,
                      String name,
                      ZipEntry entry)
Method Detail

copyTo

public void copyTo(OutputStream os)
Description copied from interface: FileAdapter
Copy the file contents to the output stream.

Specified by:
copyTo in interface FileAdapter
Parameters:
os - The output stream. The stream is not closed by this method.

copyTo

public void copyTo(WritableByteChannel wbc)
Description copied from interface: FileAdapter
Copy the file contents to the writable channel.

Specified by:
copyTo in interface FileAdapter
Parameters:
wbc - The writable channel. The channel is not closed by this method.

copyFrom

public void copyFrom(ReadableByteChannel rbc)

openForWrite

public OutputStream openForWrite(boolean append)
Description copied from interface: FileAdapter
Open the file for writing.

See WritableFile.openForWrite() and WritableFile.openForAppend() for the subtle and the not-so-subtle differences between the append and overwrite modes.

Specified by:
openForWrite in interface FileAdapter
Parameters:
append - If true, new data will be appended to existing data in the file. If false, existing data will be overwritten.

openChannelForWrite

public FileChannel openChannelForWrite(boolean append)
Specified by:
openChannelForWrite in interface FileAdapter

openForRandomAccess

public RandomAccess openForRandomAccess(RandomAccessMode mode)
Specified by:
openForRandomAccess in interface FileAdapter

getSize

public long getSize()
Description copied from interface: FileAdapter
Get the file size in bytes.

Specified by:
getSize in interface FileAdapter
Returns:
The file size in bytes.

getDataSize

public long getDataSize()
Description copied from interface: FileAdapter
Get the file's data size in bytes.

Specified by:
getDataSize in interface FileAdapter
Returns:
The file's data size in bytes.

openForRead

public InputStream openForRead()
Description copied from interface: FileAdapter
Open an InputStream on the file.

Specified by:
openForRead in interface FileAdapter
Returns:
An open InputStream for the file.

openChannelForRead

public ReadableByteChannel openChannelForRead()
Specified by:
openChannelForRead in interface FileAdapter

getEntityType

public EntityType getEntityType()
Description copied from interface: EntityAdapter
Get the EntityType for this entity.

Specified by:
getEntityType in interface EntityAdapter
Returns:
The EntityType for this entity.

replaceContents

public void replaceContents(FileAdapter fa)
Description copied from interface: FileAdapter
Replace the contents of this file adapter with the contents of the supplied file adapter.

Implementations must make sure that the file's last modification time is updated.

Specified by:
replaceContents in interface FileAdapter
Parameters:
fa - The file adapter whose contents this file adapter's contents should be replaced with. fa is guaranteed to be in the same file system as this file adapter.

getZipEntry

public ZipEntry getZipEntry()

getLastModified

public long getLastModified()
Description copied from interface: EntityAdapter
Get the last modification time for an entity.

Specified by:
getLastModified in interface EntityAdapter
Returns:
The last modification time for an entity.

init

public void init()
This implementation does nothing. Override if necessary.

Specified by:
init in interface EntityAdapter

getFileSystemAdapter

public T getFileSystemAdapter()
Description copied from interface: EntityAdapter
Get the FileSystemAdapter for the file system where the entity is.

Specified by:
getFileSystemAdapter in interface EntityAdapter
Returns:
The entity adapter's FileSystemAdapter.

exists

public boolean exists()
Subclasses may override as needed.

Specified by:
exists in interface EntityAdapter
Returns:
true if the entity exists.

canRead

public boolean canRead()
Subclasses may override as needed.

Specified by:
canRead in interface EntityAdapter
Returns:
true if the entity can be read.