org.apache.aries.util.filesystem.impl
Class ZipDirectory

java.lang.Object
  extended by org.apache.aries.util.filesystem.impl.ZipFileImpl
      extended by org.apache.aries.util.filesystem.impl.ZipDirectory
All Implemented Interfaces:
Iterable<IFile>, IDirectory, IFile

public class ZipDirectory
extends ZipFileImpl
implements IDirectory

A directory in the zip.


Field Summary
 
Fields inherited from class org.apache.aries.util.filesystem.impl.ZipFileImpl
cache, entry, zip
 
Constructor Summary
ZipDirectory(File fs, IDirectory parent)
          This constructor creates the root of the zip.
ZipDirectory(File zip1, ZipEntry entry1, ZipDirectory parent, ZipCloseableDirectory cache)
          Constructs a directory in the zip.
ZipDirectory(ZipDirectory other, ZipCloseableDirectory cache)
           
 
Method Summary
 IDirectory convert()
           
 boolean equals(Object other)
           
 IFile getFile(String name)
          Gets the requested file under this directory.
 IDirectory getRoot()
           
 int hashCode()
           
 boolean isDirectory()
           
 boolean isFile()
           
protected static boolean isInDir(String parentDir, ZipEntry possibleEntry, boolean allowSubDirs)
          This method works out if the provided entry is inside this directory.
 boolean isRoot()
           
 boolean isZipRoot()
           
 Iterator<IFile> iterator()
           
 List<IFile> listAllFiles()
           
 List<IFile> listFiles()
           
 InputStream open()
          The input stream returned by this method should always be closed after use.
 ICloseableDirectory toCloseable()
          Open a more effective implementation with user regulated resource management.
 
Methods inherited from class org.apache.aries.util.filesystem.impl.ZipFileImpl
convertNested, getLastModified, getName, getNameInZip, getParent, getSize, getZipPathToRoot, toString, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.aries.util.filesystem.IFile
convertNested, getLastModified, getName, getParent, getSize, toURL
 

Constructor Detail

ZipDirectory

public ZipDirectory(File zip1,
                    ZipEntry entry1,
                    ZipDirectory parent,
                    ZipCloseableDirectory cache)
Constructs a directory in the zip.

Parameters:
zip1 - the zip file.
entry1 - the entry in the zip representing this dir.
parent - the parent directory.

ZipDirectory

public ZipDirectory(File fs,
                    IDirectory parent)
             throws MalformedURLException
This constructor creates the root of the zip.

Parameters:
file -
fs -
parent -
Throws:
MalformedURLException

ZipDirectory

public ZipDirectory(ZipDirectory other,
                    ZipCloseableDirectory cache)
Method Detail

getFile

public IFile getFile(String name)
Description copied from interface: IDirectory
Gets the requested file under this directory. The file may be located any number of levels within this directory. The name is relative to this directory. If the file cannot be found it will return null.

Specified by:
getFile in interface IDirectory
Parameters:
name - the name of the file.
Returns:
the IFile, or null if no such file exists.

isRoot

public boolean isRoot()
Specified by:
isRoot in interface IDirectory
Returns:
true if this IDirectory is the root of the virtual file system.

listFiles

public List<IFile> listFiles()
Specified by:
listFiles in interface IDirectory
Returns:
the list of files in this directory. Files must be in this directory and not in sub-directories.

listAllFiles

public List<IFile> listAllFiles()
Specified by:
listAllFiles in interface IDirectory
Returns:
the list of files in all directories (including sub-directories). This is the complete list.

isInDir

protected static boolean isInDir(String parentDir,
                                 ZipEntry possibleEntry,
                                 boolean allowSubDirs)
This method works out if the provided entry is inside this directory. It returns false if it is not, or if it is in a sub-directory.

Parameters:
possibleEntry -
whether - files in subdirectories are to be included
Returns:
true if it is in this directory.

iterator

public Iterator<IFile> iterator()
Specified by:
iterator in interface Iterable<IFile>

convert

public IDirectory convert()
Specified by:
convert in interface IFile
Overrides:
convert in class ZipFileImpl
Returns:
if this is a directory return this as an IDirectory, otherwise return null.

isDirectory

public boolean isDirectory()
Specified by:
isDirectory in interface IFile
Overrides:
isDirectory in class ZipFileImpl
Returns:
true iff this IFile is also an IDirectory

isFile

public boolean isFile()
Specified by:
isFile in interface IFile
Overrides:
isFile in class ZipFileImpl
Returns:
true iff this IFile is not an IDirectory

open

public InputStream open()
Description copied from interface: IFile
The input stream returned by this method should always be closed after use.

Specified by:
open in interface IFile
Overrides:
open in class ZipFileImpl
Returns:
An InputStream to read the file from.

getRoot

public IDirectory getRoot()
Specified by:
getRoot in interface IFile
Overrides:
getRoot in class ZipFileImpl
Returns:
the root of this file system.

isZipRoot

public boolean isZipRoot()

equals

public boolean equals(Object other)
Overrides:
equals in class ZipFileImpl

hashCode

public int hashCode()
Overrides:
hashCode in class ZipFileImpl

toCloseable

public ICloseableDirectory toCloseable()
Description copied from interface: IDirectory
Open a more effective implementation with user regulated resource management. The implementation will be more efficient for batch operations. Make sure to call close when finished with the returned IDirectory. IFiles and IDirectories other than the returned closeable directory will stay valid after calling the close method but will no longer perform as efficiently. InputStreams that are open at the time of calling close may be invalidated.

Specified by:
toCloseable in interface IDirectory
Returns:
ICloseableDirectory or null if a batch aware version of this IDirectory is not supported


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.