JBoss VFS 3.1.0.Final-redhat-2

org.jboss.vfs.spi
Class JavaZipFileSystem

java.lang.Object
  extended by org.jboss.vfs.spi.JavaZipFileSystem
All Implemented Interfaces:
Closeable, FileSystem

public final class JavaZipFileSystem
extends Object
implements FileSystem

This implementation is backed by a zip file. The provided file must be owned by this instance; otherwise, if the file disappears unexpectedly, the filesystem will malfunction.

Author:
David M. Lloyd, Ales Justin

Constructor Summary
JavaZipFileSystem(File archiveFile, TempDir tempDir)
          Create a new instance.
JavaZipFileSystem(String name, InputStream inputStream, TempDir tempDir)
          Create a new instance.
 
Method Summary
 void close()
          Destroy this filesystem instance.
 boolean delete(VirtualFile mountPoint, VirtualFile target)
          Attempt to delete a virtual file within this filesystem.
 boolean exists(VirtualFile mountPoint, VirtualFile target)
          Ascertain the existance of a virtual file within this filesystem.
 CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target)
          Get the CodeSigners for a the virtual file.
 List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target)
          Read a directory.
 File getFile(VirtualFile mountPoint, VirtualFile target)
          Get a real File for the given path within this filesystem.
 long getLastModified(VirtualFile mountPoint, VirtualFile target)
          Get the last modification time of a virtual file within this filesystem.
 File getMountSource()
          Get the File source provided at mount time.
 URI getRootURI()
          Get the root URI for this file system, or null if there is no valid root URI.
 long getSize(VirtualFile mountPoint, VirtualFile target)
          Get the size of a virtual file within this filesystem.
 boolean isDirectory(VirtualFile mountPoint, VirtualFile target)
          Ascertain whether a virtual file within this filesystem is a directory.
 boolean isFile(VirtualFile mountPoint, VirtualFile target)
          Ascertain whether a virtual file within this filesystem is a plain file.
 boolean isReadOnly()
          Determine whether this filesystem is read-only.
 InputStream openInputStream(VirtualFile mountPoint, VirtualFile target)
          Open an input stream for the file at the given relative path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaZipFileSystem

public JavaZipFileSystem(String name,
                         InputStream inputStream,
                         TempDir tempDir)
                  throws IOException
Create a new instance.

Parameters:
name - the name of the source archive
inputStream - an input stream from the source archive
tempDir - the temp dir into which zip information is stored
Throws:
IOException - if an I/O error occurs

JavaZipFileSystem

public JavaZipFileSystem(File archiveFile,
                         TempDir tempDir)
                  throws IOException
Create a new instance.

Parameters:
archiveFile - the original archive file
tempDir - the temp dir into which zip information is stored
Throws:
IOException - if an I/O error occurs
Method Detail

getFile

public File getFile(VirtualFile mountPoint,
                    VirtualFile target)
             throws IOException
Get a real File for the given path within this filesystem. Some filesystem types will need to make a copy in order to return this file; such copies should be cached and retained until the filesystem is closed. Depending on the file type, the real path of the returned File may or may not bear a relationship to the virtual path provided; if such a relationship is required, it must be negotiated at the time the filesystem is mounted.

Specified by:
getFile in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
the file instance
Throws:
IOException - if an I/O error occurs

openInputStream

public InputStream openInputStream(VirtualFile mountPoint,
                                   VirtualFile target)
                            throws IOException
Open an input stream for the file at the given relative path.

Specified by:
openInputStream in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
the input stream
Throws:
IOException - if an I/O error occurs

delete

public boolean delete(VirtualFile mountPoint,
                      VirtualFile target)
Attempt to delete a virtual file within this filesystem.

Specified by:
delete in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
true if the file was deleted, false if it failed for any reason

getSize

public long getSize(VirtualFile mountPoint,
                    VirtualFile target)
Get the size of a virtual file within this filesystem.

Specified by:
getSize in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
the size, in bytes, or 0L if the file does not exist or is a directory

getLastModified

public long getLastModified(VirtualFile mountPoint,
                            VirtualFile target)
Get the last modification time of a virtual file within this filesystem.

Specified by:
getLastModified in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
the modification time in milliseconds, or 0L if the file does not exist or if an error occurs

exists

public boolean exists(VirtualFile mountPoint,
                      VirtualFile target)
Ascertain the existance of a virtual file within this filesystem.

Specified by:
exists in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
true if the file exists, false otherwise

isFile

public boolean isFile(VirtualFile mountPoint,
                      VirtualFile target)
Ascertain whether a virtual file within this filesystem is a plain file.

Specified by:
isFile in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
true if the file exists and is a plain file, false otherwise

isDirectory

public boolean isDirectory(VirtualFile mountPoint,
                           VirtualFile target)
Ascertain whether a virtual file within this filesystem is a directory.

Specified by:
isDirectory in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
true if the file exists and is a directory, false otherwise

getDirectoryEntries

public List<String> getDirectoryEntries(VirtualFile mountPoint,
                                        VirtualFile target)
Read a directory. Returns all the simple path names (excluding "." and ".."). The returned list will be empty if the node is not a directory.

Specified by:
getDirectoryEntries in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
the collection of children names

getCodeSigners

public CodeSigner[] getCodeSigners(VirtualFile mountPoint,
                                   VirtualFile target)
Get the CodeSigners for a the virtual file.

Specified by:
getCodeSigners in interface FileSystem
Parameters:
mountPoint - the mount point of the filesystem instance (guaranteed to be a parent of target)
target - the virtual file to act upon
Returns:
CodeSigner for the virtual file or null if not signed.

isReadOnly

public boolean isReadOnly()
Determine whether this filesystem is read-only. A read-only filesystem prohibits file modification or deletion. It is not an error to mount a read-write filesystem within a read-only filesystem however (this operation does not take place within the FileSystem implementation).

Specified by:
isReadOnly in interface FileSystem
Returns:
true if the filesystem is read-only

getMountSource

public File getMountSource()
Get the File source provided at mount time.

Specified by:
getMountSource in interface FileSystem
Returns:
the source used for mounting

getRootURI

public URI getRootURI()
               throws URISyntaxException
Description copied from interface: FileSystem
Get the root URI for this file system, or null if there is no valid root URI.

Specified by:
getRootURI in interface FileSystem
Returns:
the root URI
Throws:
URISyntaxException - if the URI isn't valid

close

public void close()
           throws IOException
Destroy this filesystem instance. After this method is called, the filesystem may not be used in any way. This method should be called only after all mounts of this filesystem have been cleared; otherwise, VFS accesses may result in IOExceptions.

Specified by:
close in interface Closeable
Specified by:
close in interface FileSystem
Throws:
IOException - if an I/O error occurs during close

JBoss VFS 3.1.0.Final-redhat-2

Copyright © 2012 JBoss, A division of Red Hat, Inc. All Rights Reserved.