net.sf.cotta.zip
Class ZipFileSystem

java.lang.Object
  extended by net.sf.cotta.zip.ZipFileSystem
All Implemented Interfaces:
java.io.Closeable, FileSystem, TResource

public class ZipFileSystem
extends java.lang.Object
implements FileSystem, TResource

ZipFileSystem that operates on a Zip file. All the entries are loaded into the memory and the contents are retrieved on demand.


Field Summary
 
Fields inherited from interface net.sf.cotta.TResource
NULL
 
Constructor Summary
ZipFileSystem(java.io.File jarFile)
           
 
Method Summary
 void close()
           
 int compare(TPath path1, TPath path2)
          Compares the two path
 void createDir(TPath path)
           
 void createFile(TPath path)
          Create file pointed by the given path
 java.nio.channels.FileChannel createInputChannel(TPath path)
           
 java.io.InputStream createInputStream(TPath path)
           
 java.nio.channels.FileChannel createOutputChannel(TPath path, java.io.OutputStream outputStream)
           
 java.io.OutputStream createOutputStream(TPath path, OutputMode mode)
           
 void deleteDirectory(TPath path)
           
 void deleteFile(TPath path)
           
 boolean dirExists(TPath path)
           
 boolean equals(TPath path1, TPath path2)
          Check if two paths are equal.
 boolean fileExists(TPath path)
           
 long fileLastModified(TPath path)
           
 long fileLength(TPath path)
           
 int hashCode(TPath path)
          Returns the hash code for the path
 PathContent list(TPath path)
          List the content of the path
 void moveDirectory(TPath path, TPath path1)
           
 void moveFile(TPath source, TPath destination)
           
 java.lang.String pathString(TPath path)
           
static FileSystem readOnlyZipFileSystem(java.io.File jarFile)
           
 java.lang.String toCanonicalPath(TPath path)
           
 java.io.File toJavaFile(TPath path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipFileSystem

public ZipFileSystem(java.io.File jarFile)
              throws java.io.IOException
Throws:
java.io.IOException
Method Detail

fileExists

public boolean fileExists(TPath path)
Specified by:
fileExists in interface FileSystem

dirExists

public boolean dirExists(TPath path)
Specified by:
dirExists in interface FileSystem

createInputStream

public java.io.InputStream createInputStream(TPath path)
                                      throws TIoException
Specified by:
createInputStream in interface FileSystem
Throws:
TIoException

createDir

public void createDir(TPath path)
               throws TIoException
Specified by:
createDir in interface FileSystem
Throws:
TIoException

list

public PathContent list(TPath path)
Description copied from interface: FileSystem
List the content of the path

Specified by:
list in interface FileSystem
Parameters:
path - path
Returns:
path content, which contains a list of paths for the files and a list of paths for the directories

createFile

public void createFile(TPath path)
                throws TIoException
Description copied from interface: FileSystem
Create file pointed by the given path

Specified by:
createFile in interface FileSystem
Parameters:
path - path of the file to create
Throws:
TIoException - error in creating the file

deleteFile

public void deleteFile(TPath path)
                throws TIoException
Specified by:
deleteFile in interface FileSystem
Throws:
TIoException

createOutputStream

public java.io.OutputStream createOutputStream(TPath path,
                                               OutputMode mode)
                                        throws TIoException
Specified by:
createOutputStream in interface FileSystem
Throws:
TIoException

createOutputChannel

public java.nio.channels.FileChannel createOutputChannel(TPath path,
                                                         java.io.OutputStream outputStream)
                                                  throws TIoException
Specified by:
createOutputChannel in interface FileSystem
Throws:
TIoException

deleteDirectory

public void deleteDirectory(TPath path)
                     throws TIoException
Specified by:
deleteDirectory in interface FileSystem
Throws:
TIoException

moveFile

public void moveFile(TPath source,
                     TPath destination)
Specified by:
moveFile in interface FileSystem

moveDirectory

public void moveDirectory(TPath path,
                          TPath path1)
                   throws TIoException
Specified by:
moveDirectory in interface FileSystem
Throws:
TIoException

pathString

public java.lang.String pathString(TPath path)
Specified by:
pathString in interface FileSystem

fileLength

public long fileLength(TPath path)
Specified by:
fileLength in interface FileSystem

fileLastModified

public long fileLastModified(TPath path)
Specified by:
fileLastModified in interface FileSystem

compare

public int compare(TPath path1,
                   TPath path2)
Description copied from interface: FileSystem
Compares the two path

Specified by:
compare in interface FileSystem
Parameters:
path1 - path one
path2 - path two
Returns:
the comparing result used for sort

equals

public boolean equals(TPath path1,
                      TPath path2)
Description copied from interface: FileSystem
Check if two paths are equal. This is needed for cases like on Windows system "c:\a\b\c.txt" is the same as "C:\A\B\C.TXT" even though the case is different

Specified by:
equals in interface FileSystem
Parameters:
path1 - path one
path2 - path two
Returns:
true if the two paths are equal according to the file system

hashCode

public int hashCode(TPath path)
Description copied from interface: FileSystem
Returns the hash code for the path

Specified by:
hashCode in interface FileSystem
Parameters:
path - path
Returns:
hash code

toJavaFile

public java.io.File toJavaFile(TPath path)
Specified by:
toJavaFile in interface FileSystem

toCanonicalPath

public java.lang.String toCanonicalPath(TPath path)
Specified by:
toCanonicalPath in interface FileSystem

createInputChannel

public java.nio.channels.FileChannel createInputChannel(TPath path)
                                                 throws TIoException
Specified by:
createInputChannel in interface FileSystem
Throws:
TIoException

close

public void close()
           throws TIoException
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface TResource
Throws:
TIoException

readOnlyZipFileSystem

public static FileSystem readOnlyZipFileSystem(java.io.File jarFile)
                                        throws TIoException
Throws:
TIoException