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

java.lang.Object
  extended by org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
      extended by org.jboss.virtual.plugins.context.zip.ZipEntryHandler
All Implemented Interfaces:
Serializable, StructuredVirtualFileHandler, VirtualFileHandler

public class ZipEntryHandler
extends AbstractVirtualFileHandler
implements StructuredVirtualFileHandler

Handler representing an individual file (ZipEntry) within ZipEntryContext

Version:
$Revision: 1.0 $
Author:
Marko Strukelj
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
cachedLastModified, log
 
Constructor Summary
ZipEntryHandler(ZipEntryContext context, AbstractVirtualFileHandler parent, String name, boolean isLeaf)
          Create a new ZipEntryHandler.
 
Method Summary
 void cleanup()
          Cleanup resources.
 VirtualFileHandler createChildHandler(String name)
          Create a virtual file context
 boolean delete(int gracePeriod)
          Delete the file represented by this handler.
 boolean exists()
          Tests whether the underlying implementation file still exists.
 VirtualFileHandler getChild(String path)
          Get a child
 List<VirtualFileHandler> getChildren(boolean ignoreErrors)
          Get the children
 long getLastModified()
          When the file was last modified
 URL getRealURL()
          Get a file: or jar:file: URL representing a resource as precisely as possible.
 long getSize()
          Get the size
protected  void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
          Replace original child with unpacked replacement.
 boolean isArchive()
          Does this represent an archive.
 boolean isHidden()
          Whether it is hidden
 boolean isLeaf()
          Whether it is a simple leaf of the VFS, i.e.
 boolean isNested()
          Are we nested in some archive.
 InputStream openStream()
          Access the file contents.
 boolean removeChild(String name)
          Remove a child
protected  URL toInternalVfsUrl()
          Get internal representation of vfs url.
 URI toURI()
          Get the VF URI (file://root/org/jboss/X.java)
 
Methods inherited from class org.jboss.virtual.plugins.context.AbstractVirtualFileHandler
checkClosed, checkParentExists, close, decrement, doClose, equals, getChildPathName, getChildVfsUrl, getLocalPathName, getLocalVFSContext, getName, getParent, getPathName, getReferences, getVFSContext, getVfsUrl, getVirtualFile, hasBeenModified, hashCode, increment, isTemporary, replaceChild, setPathName, setVfsUrl, simpleFindChild, structuredFindChild, toString, toStringLocal, toURL, toVfsUrl
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipEntryHandler

public ZipEntryHandler(ZipEntryContext context,
                       AbstractVirtualFileHandler parent,
                       String name,
                       boolean isLeaf)
                throws IOException
Create a new ZipEntryHandler.

Parameters:
context - ZipEntryContext
parent - parent within the same context
name - name of this file within context
isLeaf - true if this file should have a URL not ending with '/', false otherwise
Throws:
IOException - for any error
Method Detail

toURI

public URI toURI()
          throws URISyntaxException
Description copied from interface: VirtualFileHandler
Get the VF URI (file://root/org/jboss/X.java)

Specified by:
toURI in interface VirtualFileHandler
Returns:
the full URI to the VF in the VFS.
Throws:
URISyntaxException - for an error parsing the URI

getLastModified

public long getLastModified()
                     throws IOException
Description copied from interface: VirtualFileHandler
When the file was last modified

Specified by:
getLastModified in interface VirtualFileHandler
Returns:
the last modified time
Throws:
IOException - for any problem accessing the virtual file system

getSize

public long getSize()
             throws IOException
Description copied from interface: VirtualFileHandler
Get the size

Specified by:
getSize in interface VirtualFileHandler
Returns:
the size
Throws:
IOException - for any problem accessing the virtual file system

exists

public boolean exists()
               throws IOException
Description copied from interface: VirtualFileHandler
Tests whether the underlying implementation file still exists.

Specified by:
exists in interface VirtualFileHandler
Returns:
true if the file exists, false otherwise.
Throws:
IOException - - thrown on failure to detect existence.

isLeaf

public boolean isLeaf()
               throws IOException
Description copied from interface: VirtualFileHandler
Whether it is a simple leaf of the VFS, i.e. whether it can contain other files

Specified by:
isLeaf in interface VirtualFileHandler
Returns:
true if a simple file.
Throws:
IOException - for any problem accessing the virtual file system

isArchive

public boolean isArchive()
                  throws IOException
Description copied from interface: VirtualFileHandler
Does this represent an archive. e.g. zip, tar, ...

Specified by:
isArchive in interface VirtualFileHandler
Overrides:
isArchive in class AbstractVirtualFileHandler
Returns:
true if archive, false otherwise
Throws:
IOException - for any problem accessing the virtual file system

isHidden

public boolean isHidden()
                 throws IOException
Description copied from interface: VirtualFileHandler
Whether it is hidden

Specified by:
isHidden in interface VirtualFileHandler
Returns:
true if hidden.
Throws:
IOException - for any problem accessing the virtual file system

isNested

public boolean isNested()
                 throws IOException
Description copied from interface: VirtualFileHandler
Are we nested in some archive.

Specified by:
isNested in interface VirtualFileHandler
Returns:
true if this is archive entry
Throws:
IOException - for any error

openStream

public InputStream openStream()
                       throws IOException
Description copied from interface: VirtualFileHandler
Access the file contents.

Specified by:
openStream in interface VirtualFileHandler
Returns:
An InputStream for the file contents.
Throws:
IOException - for any problem accessing the virtual file system

getChildren

public List<VirtualFileHandler> getChildren(boolean ignoreErrors)
                                     throws IOException
Description copied from interface: VirtualFileHandler
Get the children

Specified by:
getChildren in interface VirtualFileHandler
Parameters:
ignoreErrors - whether to ignore errors
Returns:
the children
Throws:
IOException - for an error accessing the file system

getChild

public VirtualFileHandler getChild(String path)
                            throws IOException
Description copied from interface: VirtualFileHandler
Get a child

Specified by:
getChild in interface VirtualFileHandler
Parameters:
path - the path
Returns:
the child or null if not found
Throws:
IOException - for an error accessing the file system

removeChild

public boolean removeChild(String name)
                    throws IOException
Description copied from interface: VirtualFileHandler
Remove a child

Specified by:
removeChild in interface VirtualFileHandler
Parameters:
name - child name
Returns:
true if child was removed, false otherwise
Throws:
IOException - if an error occurs

cleanup

public void cleanup()
Description copied from interface: VirtualFileHandler
Cleanup resources.

Specified by:
cleanup in interface VirtualFileHandler
Overrides:
cleanup in class AbstractVirtualFileHandler

delete

public boolean delete(int gracePeriod)
               throws IOException
Description copied from class: AbstractVirtualFileHandler
Delete the file represented by this handler. File deletion is comprised of two parts:
  1. physical file deletion - performed by this method or its override
  2. removal of any child references from the parent - performed by VirtualFileHandler.removeChild(String) of the parent
This method doesn't do any physical file removal because it has no concept of underlying physical file. An implementation that does physical file removal should override this method and call super.delete() at the end.

Specified by:
delete in interface VirtualFileHandler
Overrides:
delete in class AbstractVirtualFileHandler
Parameters:
gracePeriod - max time to wait for any locks
Returns:
true if file was deleted, false otherwise
Throws:
IOException - if an error occurs

createChildHandler

public VirtualFileHandler createChildHandler(String name)
                                      throws IOException
Description copied from interface: StructuredVirtualFileHandler
Create a virtual file context

Specified by:
createChildHandler in interface StructuredVirtualFileHandler
Parameters:
name - the name
Returns:
the handler
Throws:
IOException - for any error accessing the virtual file system

internalReplaceChild

protected void internalReplaceChild(VirtualFileHandler original,
                                    VirtualFileHandler replacement)
Description copied from class: AbstractVirtualFileHandler
Replace original child with unpacked replacement.

Overrides:
internalReplaceChild in class AbstractVirtualFileHandler
Parameters:
original - the original
replacement - the replacement

toInternalVfsUrl

protected URL toInternalVfsUrl()
Description copied from class: AbstractVirtualFileHandler
Get internal representation of vfs url.

Overrides:
toInternalVfsUrl in class AbstractVirtualFileHandler
Returns:
the vfs url

getRealURL

public URL getRealURL()
               throws IOException,
                      URISyntaxException
Description copied from interface: VirtualFileHandler
Get a file: or jar:file: URL representing a resource as precisely as possible. file: urls can represent files in the file system (i.e.: file:/classes/MyClass.class) jar:file: urls can represent entries within zip archives in the filesystem (i.e.: jar:file:/lib/classes.jar!/MyClass.class) There is no standard URL handler to represent entries within archives that are themselves entries within archives. (i.e.: this doesn't work: jar:file:/lib/app.ear!/classes.jar!/MyClass.class In this case the most precise supported resource locator is: jar:file:/lib/app.ear!/classes.jar )

Specified by:
getRealURL in interface VirtualFileHandler
Overrides:
getRealURL in class AbstractVirtualFileHandler
Returns:
the url
Throws:
MalformedURLException - for any error constructing the URL
URISyntaxException - for an error parsing the URI
IOException


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