org.jboss.virtual.plugins.context.zip
Class ZipEntryContext

java.lang.Object
  extended by org.jboss.virtual.plugins.context.AbstractVFSContext
      extended by org.jboss.virtual.plugins.context.zip.ZipEntryContext
All Implemented Interfaces:
VFSContext

public class ZipEntryContext
extends AbstractVFSContext

ZipEntryContext implements a VFSContext that exposes a zip archive as a virtual file system. Zip archive can be in a form of a file or a stream. Nested archives are processed through this same class. By default nested archives are cached in memory and mounted as new instances of ZipEntryContext with ZipStreamWrapper as a source. If system property jboss.vfs.forceCopy=true is specified, or URL query parameter forceCopy=true is present, nested archives are extracted into a temp directory before being mounted as new instances of ZipEntryContext. In-memory nested archives may consume a lot of memory. To reduce memory footprint at the expense of performance, system property jboss.vfs.optimizeForMemory=true can be set. This context implementation has two modes of releasing file locks. Asynchronous mode is the default one since it is better performant. To switch this to synchronous mode a system property jboss.vfs.forceNoReaper=true can be specified or URL query parameter noReaper=true can be included in context URL. This context implementation is a replacement for JarContext.

Version:
$Revision: 1.0 $
Author:
Marko Strukelj, Ales Justin, David M. Lloyd

Constructor Summary
ZipEntryContext(URL rootURL)
          Create a new ZipEntryContext
ZipEntryContext(URL rootURL, boolean autoClean)
          Create a new ZipEntryContext
ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl)
          Create a new ZipEntryContext to be mounted into another context
ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl, boolean autoClean)
          Create a new ZipEntryContext to be mounted into another context
ZipEntryContext(URL rootURL, VirtualFileHandler peer, org.jboss.virtual.plugins.context.zip.ZipWrapper zipWrapper, boolean autoClean)
          Create a new ZipEntryContext to be mounted into another context
 
Method Summary
protected  org.jboss.virtual.plugins.context.zip.ZipWrapper createZipSource(String rootPath)
          Create zip source.
protected  void finalize()
          Properly release held resources
protected  org.jboss.virtual.plugins.context.zip.ZipWrapper findEntry(InputStream is, String relative, org.jboss.virtual.plugins.context.zip.ZipEntryContext.RealURLInfo urlInfo)
          Find exact entry.
 Options getAggregatedOptions()
          Returns aggregated options.
 List<VirtualFileHandler> getChildren(VirtualFileHandler parent, boolean ignoreErrors)
          Returns a list of children for a given parent
 Set<VFSContextConstraints> getConstraints()
          Get context's constraints.
 ExceptionHandler getExceptionHandler()
          Get the exception handler.
 String getName()
          Returns archive file name - if this is a top-level ZipEntryContext.
protected  String getPath(VFSContext peer, String entryName)
          Get temp path.
 VirtualFileHandler getRoot()
          Returns this context's root
protected  org.jboss.virtual.plugins.context.zip.ZipWrapper getZipSource()
          Get zip source.
protected  DelegatingHandler mountZipFile(VirtualFileHandler parent, String name, File file)
          Mount ZipEntryContext created around extracted nested archive
protected  DelegatingHandler mountZipStream(VirtualFileHandler parent, String name, InputStream zipStream)
          Mount ZipEntryContext created around ZipStreamWrapper
static String[] splitParentChild(String pathName)
          Break to path + name
 
Methods inherited from class org.jboss.virtual.plugins.context.AbstractVFSContext
addTempInfo, cleanupTempInfo, createNewOptions, equals, getChild, getChildURL, getFurthestParentTemp, getOption, getOption, getOption, getOptions, getPeerContext, getRootPeer, getRootURI, getTempInfo, getTempInfos, getVFS, hashCode, setExceptionHandler, setOption, setOptionsToURL, setRootPeer, toString, visit, visit
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipEntryContext

public ZipEntryContext(URL rootURL)
                throws URISyntaxException,
                       IOException
Create a new ZipEntryContext

Parameters:
rootURL - - file or jar:file url
Throws:
URISyntaxException - for any URI error
IOException - for any error

ZipEntryContext

public ZipEntryContext(URL rootURL,
                       boolean autoClean)
                throws URISyntaxException,
                       IOException
Create a new ZipEntryContext

Parameters:
rootURL - - file or jar:file url
autoClean - - true if file represented by rootURL should be deleted after this context is closed
Throws:
URISyntaxException - for any URI error
IOException - for any error

ZipEntryContext

public ZipEntryContext(URL rootURL,
                       VirtualFileHandler peer,
                       URL localRootUrl)
                throws URISyntaxException,
                       IOException
Create a new ZipEntryContext to be mounted into another context

Parameters:
rootURL - - url representing this context within another context
peer - - file handler in another context through which this context is being mounted
localRootUrl - - file or jar:file url
Throws:
URISyntaxException - for any URI error
IOException - for any error

ZipEntryContext

public ZipEntryContext(URL rootURL,
                       VirtualFileHandler peer,
                       URL localRootUrl,
                       boolean autoClean)
                throws URISyntaxException,
                       IOException
Create a new ZipEntryContext to be mounted into another context

Parameters:
rootURL - - url representing this context within another context
peer - - file handler in another context through which this context is being mounted
localRootUrl - - file or jar:file url
autoClean - - true if file represented by localRootURL should be deleted after this context is closed
Throws:
URISyntaxException - for any URI error
IOException - for any error

ZipEntryContext

public ZipEntryContext(URL rootURL,
                       VirtualFileHandler peer,
                       org.jboss.virtual.plugins.context.zip.ZipWrapper zipWrapper,
                       boolean autoClean)
                throws URISyntaxException,
                       IOException
Create a new ZipEntryContext to be mounted into another context

Parameters:
rootURL - - url representing this context within another context
peer - - file handler in another context through which this context is being mounted
zipWrapper - - abstracted zip archive source
autoClean - - true if file represented by localRootURL should be deleted after this context is closed
Throws:
URISyntaxException - for any URI error
IOException - for any error
Method Detail

getZipSource

protected org.jboss.virtual.plugins.context.zip.ZipWrapper getZipSource()
Get zip source. Lazy init.

Returns:
the zip source

getAggregatedOptions

public Options getAggregatedOptions()
Returns aggregated options. If peer exists, it uses peer context's options as a basis, and overrides them with this context's options.

Returns:
map containing aggregated options

getExceptionHandler

public ExceptionHandler getExceptionHandler()
Description copied from interface: VFSContext
Get the exception handler.

Specified by:
getExceptionHandler in interface VFSContext
Overrides:
getExceptionHandler in class AbstractVFSContext
Returns:
the exception handler

createZipSource

protected org.jboss.virtual.plugins.context.zip.ZipWrapper createZipSource(String rootPath)
                                                                    throws IOException
Create zip source.

Parameters:
rootPath - the root path
Returns:
zip entry wrapper
Throws:
IOException - for any error

findEntry

protected org.jboss.virtual.plugins.context.zip.ZipWrapper findEntry(InputStream is,
                                                                     String relative,
                                                                     org.jboss.virtual.plugins.context.zip.ZipEntryContext.RealURLInfo urlInfo)
                                                              throws IOException
Find exact entry. Use recursion on relative path.

Parameters:
is - the input stream
relative - relative path
urlInfo - url info
Returns:
zip wrapper instance
Throws:
IOException - for any error

getConstraints

public Set<VFSContextConstraints> getConstraints()
Description copied from interface: VFSContext
Get context's constraints.

Specified by:
getConstraints in interface VFSContext
Overrides:
getConstraints in class AbstractVFSContext
Returns:
the constraints

getName

public String getName()
Returns archive file name - if this is a top-level ZipEntryContext. Otherwise it returns the last component of URL.

Returns:
name

getPath

protected String getPath(VFSContext peer,
                         String entryName)
Get temp path.

Parameters:
peer - the peer vfs context
entryName - the zip entry name
Returns:
full temp path

mountZipFile

protected DelegatingHandler mountZipFile(VirtualFileHandler parent,
                                         String name,
                                         File file)
                                  throws IOException,
                                         URISyntaxException
Mount ZipEntryContext created around extracted nested archive

Parameters:
parent - the parent
name - the name
file - the file
Returns:
mounted delegate
Throws:
IOException - for any error
URISyntaxException - for any URI syntax error

mountZipStream

protected DelegatingHandler mountZipStream(VirtualFileHandler parent,
                                           String name,
                                           InputStream zipStream)
                                    throws IOException,
                                           URISyntaxException
Mount ZipEntryContext created around ZipStreamWrapper

Parameters:
parent - the parent
name - the name
zipStream - the zip stream
Returns:
mounted delegate
Throws:
IOException - for any error
URISyntaxException - for any URI syntax error

getRoot

public VirtualFileHandler getRoot()
Returns this context's root

Returns:
root handler

getChildren

public List<VirtualFileHandler> getChildren(VirtualFileHandler parent,
                                            boolean ignoreErrors)
                                     throws IOException
Returns a list of children for a given parent

Specified by:
getChildren in interface VFSContext
Overrides:
getChildren in class AbstractVFSContext
Parameters:
parent - parent handler
ignoreErrors - true if errors should be silently ignored
Returns:
list of handlers representing children of the given parent
Throws:
IOException - for any error

finalize

protected void finalize()
                 throws Throwable
Properly release held resources

Overrides:
finalize in class Object
Throws:
Throwable

splitParentChild

public static String[] splitParentChild(String pathName)
Break to path + name

Parameters:
pathName - the path name
Returns:
path tokens


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