[jboss-cvs] JBossAS SVN: r90528 - in projects/vfs/branches/dml-zip-rework/src: main/java/org/jboss/virtual/plugins/context/file and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 23 11:20:03 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-06-23 11:20:01 -0400 (Tue, 23 Jun 2009)
New Revision: 90528
Added:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipContextFactory.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipEntryContext.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipFileHandler.java
Removed:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContextFactory.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/ZipEntryWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileLockReaper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/JarOAContextFactory.java
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java
projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
Log:
Yoink!
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -38,9 +38,8 @@
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.plugins.context.AbstractVFSContext;
import org.jboss.virtual.plugins.context.DelegatingHandler;
-import org.jboss.virtual.plugins.context.jar.JarHandler;
import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
+import org.jboss.virtual.plugins.context.jzip.ZipEntryContext;
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.VFSContextConstraints;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -48,11 +47,8 @@
/**
* FileSystemContext.
*
- * Jar archives are processed through {@link org.jboss.virtual.plugins.context.zip.ZipEntryContext}.
+ * Jar archives are processed through {@link org.jboss.virtual.plugins.context.jzip.ZipEntryContext}.
*
- * To switch back to {@link org.jboss.virtual.plugins.context.jar.JarHandler}
- * set a system property <em>jboss.vfs.forceVfsJar=true</em>
- *
* Explicit case sensitive path checking can be turned on by adding an option parameter
* <em>?caseSensitive=true<em> to context URL. This may be desired when native filesystem is not
* case sensitive (i.e. if running on Windows).
@@ -69,19 +65,11 @@
{
protected static final Logger staticLog = Logger.getLogger(FileSystemContext.class);
- /** true if forcing fallback to vfsjar from default vfszip */
- private static boolean forceVfsJar;
-
/** true if case sensitivity should be enforced */
private static boolean forceCaseSensitive;
static
{
- forceVfsJar = AccessController.doPrivileged(new CheckForceVfsJar());
-
- if (forceVfsJar)
- staticLog.info("VFS forced fallback to vfsjar is enabled.");
-
forceCaseSensitive = AccessController.doPrivileged(new CheckForceCaseSensitive());
if (forceCaseSensitive)
@@ -245,27 +233,13 @@
if (exists(file) == false)
return null;
- if (forceVfsJar)
+ try
{
- try
- {
- return new JarHandler(this, parent, file, file.toURI().toURL(), name);
- }
- catch(IOException e)
- {
- log.debug("Exception while trying to handle file (" + name + ") as a jar: " + e.getMessage());
- }
+ return mountZipFS(parent, name, file);
}
- else
+ catch (Exception e)
{
- try
- {
- return mountZipFS(parent, name, file);
- }
- catch (Exception e)
- {
- log.debug("IGNORING: Exception while trying to handle file (" + name + ") as a jar through ZipEntryContext: ", e);
- }
+ log.debug("IGNORING: Exception while trying to handle file (" + name + ") as a jar through ZipEntryContext: ", e);
}
}
return createVirtualFileHandler(parent, file, getFileURI(file));
@@ -410,15 +384,6 @@
return forceCaseSensitive;
}
- private static class CheckForceVfsJar implements PrivilegedAction<Boolean>
- {
- public Boolean run()
- {
- String forceString = System.getProperty(VFSUtils.FORCE_VFS_JAR_KEY, "false");
- return Boolean.valueOf(forceString);
- }
- }
-
private static class CheckForceCaseSensitive implements PrivilegedAction<Boolean>
{
public Boolean run()
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,247 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.net.JarURLConnection;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Stack;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import org.jboss.virtual.plugins.context.AbstractURLHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * AbstractJarHandler.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
- */
-public abstract class AbstractJarHandler extends AbstractURLHandler
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1;
-
- /**
- * The jar file
- */
- private transient JarFile jar;
- /**
- * The jar entry
- */
- private transient ZipEntry entry;
-
- /**
- * Create a new JarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param url the url
- * @param jar the jar
- * @param entry the entry
- * @param name the name
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
- */
- protected AbstractJarHandler(VFSContext context, VirtualFileHandler parent, URL url, JarFile jar, ZipEntry entry, String name) throws IOException
- {
- super(context, parent, url, name);
- this.jar = jar;
- this.entry = entry;
- }
-
- /**
- * Get the jar.
- *
- * @return the jar.
- */
- public JarFile getJar()
- {
- if (jar == null)
- throw new IllegalArgumentException("Null jar");
- return jar;
- }
-
- /**
- * Get the entry.
- *
- * @return jar entry
- */
- public ZipEntry getEntry()
- {
- checkClosed();
- if (entry == null)
- throw new IllegalArgumentException("Null entry");
- return entry;
- }
-
- /**
- * Create the URL for the entry represented by path.
- *
- * @param parent - the parent handler
- * @param path - the simple path to the entry without any trailing '/'
- * @param isDirEntry - whether this is a directory entry
- * @return the jar entry URL
- * @throws MalformedURLException if illegal URL form
- */
- protected URL getURL(VirtualFileHandler parent, String path, boolean isDirEntry) throws MalformedURLException
- {
- StringBuilder buffer = new StringBuilder();
- try
- {
- String parentUrl = parent.toURL().toString();
- if (parent instanceof JarEntryHandler || parent instanceof SynthenticDirEntryHandler)
- {
- buffer.append(parentUrl);
- }
- else
- {
- buffer.append("jar:").append(parentUrl).append("!/");
- }
-
- if (buffer.charAt(buffer.length() - 1) != '/')
- buffer.append('/');
- buffer.append(path);
- }
- catch (URISyntaxException e)
- {
- // Should not happen
- throw new MalformedURLException(e.getMessage());
- }
- // Jar directory URLs must end in /
- if( isDirEntry && buffer.charAt(buffer.length() - 1) != '/')
- buffer.append('/');
- return new URL(buffer.toString());
- }
-
- public boolean isLeaf()
- {
- checkClosed();
- return false;
- }
-
- /**
- * Convert a URL into a JarFIle
- *
- * @param url the url to convert
- * @return the jar file
- * @throws IOException for any IO error
- */
- public static JarFile fromURL(URL url) throws IOException
- {
- try
- {
- URLConnection connection = openConnection(url);
- JarURLConnection jarConnection;
- if (connection instanceof JarURLConnection)
- {
- jarConnection = (JarURLConnection)connection;
- }
- else
- {
- // try wrapping it in jar:
- URL jarUrl = new URL("jar:" + url + "!/");
- jarConnection = (JarURLConnection)openConnection(jarUrl);
- }
- return jarConnection.getJarFile();
- }
- catch (IOException original)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
- e.setStackTrace(original.getStackTrace());
- throw e;
-
- }
- }
-
- /**
- * Restore the jar file from the jar URL
- *
- * @param in object input string
- * @throws IOException for any IO error
- * @throws ClassNotFoundException if any error reading object
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- in.defaultReadObject();
- // Initialize the transient values
- URL jarURL = getURL();
- String jarAsString = jarURL.toString();
- if (jarAsString.startsWith("file:"))
- {
- File fp = new File(jarAsString.substring(5));
- jar = new JarFile(fp);
- }
- else
- {
- URLConnection conn = openConnection(jarURL);
- if (conn instanceof JarURLConnection)
- {
- JarURLConnection jconn = (JarURLConnection) conn;
- jar = jconn.getJarFile();
- }
- else
- {
- throw new IOException("Cannot restore from non-JarURLConnection, url: " + jarURL);
- }
- }
- handleJarFile();
- }
-
- /**
- * Handle jar file after read.
- * Find the real jar file, if nested.
- *
- * @throws IOException for any error
- */
- protected void handleJarFile() throws IOException
- {
- Stack<AbstractJarHandler> handlers = new Stack<AbstractJarHandler>();
- AbstractJarHandler current = this;
- while(current.getParent() instanceof AbstractJarHandler)
- {
- handlers.push(current);
- current = (AbstractJarHandler)current.getParent();
- }
- while(handlers.isEmpty() == false)
- {
- if (entry != null)
- {
- // TODO - change jar
- }
- current = handlers.pop();
- entry = jar.getEntry(current.getName());
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,380 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.context.HierarchyVirtualFileHandler;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * AbstractStructuredJarHandler.
- *
- * @param <T> exact extra wrapper type
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class AbstractStructuredJarHandler<T> extends AbstractJarHandler implements StructuredVirtualFileHandler
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1;
-
- /**
- * The jar entries
- */
- private transient List<VirtualFileHandler> entries;
- private transient Map<String, VirtualFileHandler> entryMap;
-
- /**
- * Force no copy nested jar handler.
- */
- private static boolean forceCopy;
-
- static
- {
- forceCopy = AccessController.doPrivileged(new CheckForceCopy());
- if (forceCopy)
- log.info("VFS force copy (NestedJarHandler) is enabled.");
- }
-
- /**
- * Create a new JarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param url the url
- * @param jar the jar
- * @param entry the entry
- * @param name the name
- * @throws java.io.IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
- */
- protected AbstractStructuredJarHandler(VFSContext context, VirtualFileHandler parent, URL url, JarFile jar, ZipEntry entry, String name) throws IOException
- {
- super(context, parent, url, jar, entry, name);
- }
-
- /**
- * Initialize the jar file
- *
- * @throws java.io.IOException for any error reading the jar file
- * @throws IllegalArgumentException for a null jarFile
- */
- protected void initJarFile() throws IOException
- {
- /* This cannot be checked because of serialization
- if (this.jar != null)
- throw new IllegalStateException("jarFile has already been set");
- */
- Enumeration<ZipEntryWrapper<T>> enumeration = new JarEntryEnumeration(getJar().entries());
- initJarFile(enumeration);
- }
-
- /**
- * Initialise the jar file.
- *
- * @param enumeration jar entry enumeration
- * @throws IOException for any error
- */
- protected void initJarFile(Enumeration<ZipEntryWrapper<T>> enumeration) throws IOException
- {
- if (enumeration.hasMoreElements() == false)
- {
- entries = Collections.emptyList();
- entryMap = Collections.emptyMap();
- return;
- }
-
- // Go through and create a structured representation of the jar
- Map<String, VirtualFileHandler> parentMap = new HashMap<String, VirtualFileHandler>();
- List<ArrayList<ZipEntryWrapper<T>>> levelMapList = new ArrayList<ArrayList<ZipEntryWrapper<T>>>();
- entries = new ArrayList<VirtualFileHandler>();
- entryMap = new HashMap<String, VirtualFileHandler>();
-
- boolean trace = log.isTraceEnabled();
-
- while (enumeration.hasMoreElements())
- {
- ZipEntryWrapper<T> wrapper = enumeration.nextElement();
- extraWrapperInfo(wrapper);
- String[] paths = wrapper.getName().split("/");
- int depth = paths.length;
- if (depth >= levelMapList.size())
- {
- for (int n = levelMapList.size(); n <= depth; n++)
- levelMapList.add(new ArrayList<ZipEntryWrapper<T>>());
- }
- ArrayList<ZipEntryWrapper<T>> levelMap = levelMapList.get(depth);
- levelMap.add(wrapper);
- if (trace)
- log.trace("added " + wrapper.getName() + " at depth " + depth);
- }
- // Process each level to build the handlers in parent first order
- int level = 0;
- for (ArrayList<ZipEntryWrapper<T>> levels : levelMapList)
- {
- if (trace)
- log.trace("Level(" + level++ + "): " + levels);
- for (ZipEntryWrapper<T> wrapper : levels)
- {
- String name = wrapper.getName();
- int slash = wrapper.isDirectory() ? name.lastIndexOf('/', name.length() - 2) : name.lastIndexOf('/', name.length() - 1);
- VirtualFileHandler parent = this;
- if (slash >= 0)
- {
- // Need to include the slash in the name to match the ZipEntry.name
- String parentName = name.substring(0, slash + 1);
- parent = parentMap.get(parentName);
- if (parent == null)
- {
- // Build up the parent(s)
- parent = buildParents(parentName, parentMap, wrapper);
- }
- }
- // Get the entry name without any directory '/' ending
- int start = slash + 1;
- int end = wrapper.isDirectory() ? name.length() - 1 : name.length();
- String entryName = name.substring(start, end);
- VirtualFileHandler handler = createVirtualFileHandler(parent, wrapper, entryName);
- if (wrapper.isDirectory())
- {
- parentMap.put(name, handler);
- if (trace)
- log.trace("Added parent: " + name);
- }
- if (parent == this)
- {
- // This is an immeadiate child of the jar handler
- entries.add(handler);
- entryMap.put(entryName, handler);
- }
- else if (parent instanceof HierarchyVirtualFileHandler)
- {
- HierarchyVirtualFileHandler ehandler = (HierarchyVirtualFileHandler) parent;
- ehandler.addChild(handler);
- }
- }
- }
- }
-
- /**
- * Handle additional information about wrapper.
- *
- * @param wrapper the zip entry wrapper
- * @throws IOException for any error
- */
- protected void extraWrapperInfo(ZipEntryWrapper<T> wrapper) throws IOException
- {
- }
-
- /**
- * Create any missing parents.
- *
- * @param parentName full vfs path name of parent
- * @param parentMap initJarFile parentMap
- * @param wrapper ZipEntryWrapper missing a parent
- * @return the VirtualFileHandler for the parent
- * @throws java.io.IOException for any IO error
- */
- protected VirtualFileHandler buildParents(String parentName, Map<String, VirtualFileHandler> parentMap, ZipEntryWrapper<T> wrapper)
- throws IOException
- {
- VirtualFileHandler parent = this;
- List<String> paths = PathTokenizer.getTokens(parentName);
- StringBuilder pathName = new StringBuilder();
- for (String path : paths)
- {
- pathName.append(path);
- pathName.append('/');
- VirtualFileHandler next = parent.getChild(path);
- if (next == null)
- next = createSynthenticParent(parent, path, wrapper);
- parentMap.put(pathName.toString(), next);
- parent = next;
- }
- return parent;
- }
-
- protected VirtualFileHandler createSynthenticParent(VirtualFileHandler parent, String path, ZipEntryWrapper<T> wrapper)
- throws IOException
- {
- URL url = getURL(parent, path, true);
- // Create a synthetic parent
- VirtualFileHandler next = new SynthenticDirEntryHandler(getVFSContext(), parent, path, wrapper.getTime(), url);
-
- if (parent == this)
- {
- // This is an immeadiate child of the jar handler
- entries.add(next);
- entryMap.put(path, next);
- }
- else if (parent instanceof HierarchyVirtualFileHandler)
- {
- HierarchyVirtualFileHandler ehandler = (HierarchyVirtualFileHandler) parent;
- ehandler.addChild(next);
- }
- return next;
- }
-
- @Override
- public boolean isArchive() throws IOException
- {
- return true;
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- checkClosed();
- if (entries == null)
- return Collections.emptyList();
- else
- return Collections.unmodifiableList(entries);
- }
-
- public VirtualFileHandler createChildHandler(String name) throws IOException
- {
- return entryMap.get(name);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- return structuredFindChild(path);
- }
-
- /**
- * Create a new virtual file handler
- *
- * @param parent the parent
- * @param wrapper the entry wrapper
- * @param entryName - the entry name without any trailing '/'
- * @return the handler
- * @throws java.io.IOException for any error accessing the file system
- * @throws IllegalArgumentException for a null parent or entry
- */
- protected VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, ZipEntryWrapper<T> wrapper, String entryName)
- throws IOException
- {
- if (parent == null)
- throw new IllegalArgumentException("Null parent");
- if (wrapper == null)
- throw new IllegalArgumentException("Null entry wrapper");
-
- ZipEntry entry = wrapper.getEntry();
- URL url = getURL(parent, entryName, entry.isDirectory());
- VFSContext context = parent.getVFSContext();
-
- VirtualFileHandler vfh;
- if (JarUtils.isArchive(entry.getName()))
- {
- boolean useCopyJarHandler = forceCopy;
- if (useCopyJarHandler == false)
- {
- String flag = context.getOptions().getOption(VFSUtils.USE_COPY_QUERY, String.class);
- useCopyJarHandler = Boolean.valueOf(flag);
- }
-
- if (useCopyJarHandler)
- vfh = NestedJarHandler.create(context, parent, getJar(), entry, url, entryName);
- else
- vfh = new NoCopyNestedJarHandler(context, parent, getJar(), entry, url, entryName);
- }
- else
- {
- vfh = new JarEntryHandler(context, parent, getJar(), entry, entryName, url);
- }
-
- return vfh;
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- entries.remove(original);
- entries.add(replacement);
- entryMap.put(original.getName(), replacement);
- }
-
- /**
- * Restore the jar file
- *
- * @param in the input stream
- * @throws IOException for any error reading the jar file
- * @throws ClassNotFoundException for any jar class finding errors
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- // Initial the parent jar entries
- initJarFile();
- }
-
- private class JarEntryEnumeration implements Enumeration<ZipEntryWrapper<T>>
- {
- private Enumeration<JarEntry> enumeration;
-
- public JarEntryEnumeration(Enumeration<JarEntry> enumeration)
- {
- if (enumeration == null)
- throw new IllegalArgumentException("Null enumeration");
- this.enumeration = enumeration;
- }
-
- public boolean hasMoreElements()
- {
- return enumeration.hasMoreElements();
- }
-
- public ZipEntryWrapper<T> nextElement()
- {
- JarEntry entry = enumeration.nextElement();
- return new ZipEntryWrapper<T>(entry);
- }
- }
-
- /**
- * Check if force no copy system property exists.
- */
- private static class CheckForceCopy implements PrivilegedAction<Boolean>
- {
- public Boolean run()
- {
- String forceString = System.getProperty(VFSUtils.FORCE_COPY_KEY, "false");
- return Boolean.valueOf(forceString);
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContext.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,152 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.AbstractVFSContext;
-import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * JarContext.
- *
- * @author Scott.Stark at jboss.org
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class JarContext extends AbstractVFSContext
-{
- /** The root file */
- private final VirtualFileHandler root;
-
- /** A reference to the virtual file of the root to stop it getting closed */
- private final VirtualFile rootFile;
-
- /**
- * Create a new JarContext.
- *
- * @param rootURL the root url
- * @throws IOException for an error accessing the file system
- * @throws URISyntaxException for an error parsing the URI
- */
- public JarContext(URL rootURL) throws IOException, URISyntaxException
- {
- super(rootURL);
- root = createVirtualFileHandler(null, rootURL);
- rootFile = root.getVirtualFile();
- }
-
- public String getName()
- {
- return root.getName();
- }
-
- public VirtualFileHandler getRoot() throws IOException
- {
- return root;
- }
-
- /**
- * Create a new virtual file handler
- *
- * @param parent the parent
- * @param url the url
- * @return the handler
- * @throws IOException for any error accessing the file system
- * @throws IllegalArgumentException for a null entry or url
- */
- protected VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, URL url) throws IOException
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
-
- String urlStr = url.toString();
- String jarName = extractJarName(urlStr);
- String entryPath = urlStr;
- entryPath = entryPath(entryPath);
- // make sure that JarHandler.initJar works on the jar itself
- if(entryPath != null)
- {
- String s = url.toExternalForm();
- url = new URL(s.substring(0, s.length() - entryPath.length()));
- }
- JarHandler jar = new JarHandler(this, parent, url, jarName);
- if (entryPath == null)
- return jar;
-
- // todo This is a hack until we can fix http://jira.jboss.com/jira/browse/JBMICROCONT-164
- AbstractVirtualFileHandler result = (AbstractVirtualFileHandler)jar.getChild(entryPath);
- if (result == null)
- throw new IllegalArgumentException("Null child, entryPath: " + entryPath);
-
- result.setPathName("");
- return result;
- }
-
- public static String entryPath(String entryName)
- {
- int index;
- index = entryName.indexOf("!/");
- if (index != -1)
- {
- entryName = entryName.substring(index + 2);
- }
- else
- {
- entryName = null;
- }
- if (entryName == null || "".equals(entryName.trim()))
- return null;
-
- return entryName;
- }
-
- /**
- * Extract jar name.
- *
- * @param urlStr the url string
- * @return jar name
- */
- public static String extractJarName(String urlStr)
- {
- String jarName = urlStr;
- int index = jarName.indexOf('!');
- if (index != -1)
- jarName = jarName.substring(0, index);
- index = jarName.lastIndexOf('/');
- if (index != -1 && index < jarName.length()-1)
- jarName = jarName.substring(index+1);
- return jarName;
- }
-
- @Override
- protected void finalize() throws Throwable
- {
- if (rootFile != null)
- rootFile.close();
- super.finalize();
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContextFactory.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContextFactory.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarContextFactory.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.jboss.virtual.plugins.context.AbstractContextFactory;
-import org.jboss.virtual.spi.VFSContext;
-
-/**
- * A jar context factory
- *
- * @author Scott.Stark at jboss.org
- * @author adrian at jboss.org
- * @version $Revision: 44217 $
- */
-public class JarContextFactory extends AbstractContextFactory
-{
- public JarContextFactory()
- {
- super("jar", "vfsjar");
- }
-
- public VFSContext getVFS(URL root) throws IOException
- {
- try
- {
- return new JarContext(fromVFS(root));
- }
- catch(URISyntaxException e)
- {
- MalformedURLException ex = new MalformedURLException("non-URI compliant URL");
- ex.initCause(e);
- throw ex;
- }
- }
-
- public VFSContext getVFS(URI root) throws IOException
- {
- return getVFS(root.toURL());
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,301 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.jboss.virtual.plugins.context.HierarchyVirtualFileHandler;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * A nested jar contents implementation used to represent a jar within a jar.
- *
- * @author Ales.Justin at jboss.org
- * @author Scott.Stark at jboss.org
- */
-public class JarEntryContents extends AbstractJarHandler implements StructuredVirtualFileHandler, HierarchyVirtualFileHandler
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- private URL entryURL;
- private byte[] contents;
- private boolean isJar;
- private NestedJarFromStream njar;
- private InputStream openStream;
-
- private List<VirtualFileHandler> entryChildren;
- private transient Map<String, VirtualFileHandler> entryMap;
-
- JarEntryContents(VFSContext context, VirtualFileHandler parent, ZipEntry entry, String entryName, URL jarURL, URL entryURL, byte[] contents)
- throws IOException
- {
- super(context, parent, jarURL, null, entry, entryName);
- try
- {
- setPathName(getChildPathName(entryName, false));
- setVfsUrl(getChildVfsUrl(entryName, false));
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- this.entryURL = entryURL;
- this.isJar = JarUtils.isArchive(getName());
- this.contents = contents;
- }
-
- protected void initCacheLastModified()
- {
- }
-
- /**
- * Add a child to an entry
- *
- * @param child the child
- */
- public synchronized void addChild(VirtualFileHandler child)
- {
- if (entryChildren == null)
- entryChildren = new ArrayList<VirtualFileHandler>();
- entryChildren.add(child);
- if (entryMap != null)
- entryMap.put(child.getName(), child);
- }
-
- /**
- * TODO: removing the entry/jar that resulted in this needs
- * to be detected.
- */
- public boolean exists() throws IOException
- {
- return true;
- }
-
- public boolean isHidden() throws IOException
- {
- return false;
- }
-
- public boolean isNested() throws IOException
- {
- return true;
- }
-
- byte[] getContents()
- {
- return contents;
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- List<VirtualFileHandler> children;
-
- if (isJar)
- {
- initNestedJar();
- children = njar.getChildren(ignoreErrors);
- }
- else
- {
- children = entryChildren;
- }
-
- if (children == null)
- return Collections.emptyList();
- else
- return Collections.unmodifiableList(children);
- }
-
- public VirtualFileHandler createChildHandler(String name) throws IOException
- {
- if (isJar)
- {
- initNestedJar();
- return njar.createChildHandler(name);
- }
- else
- return findChildHandler(name);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- if (path == null)
- throw new IllegalArgumentException("Null path");
-
- if ("".equals(path))
- return this;
-
- if (isJar)
- {
- initNestedJar();
- return njar.getChild(path);
- }
- else if (getEntry().isDirectory())
- {
- return structuredFindChild(path);
- }
- return null;
- }
-
- public boolean removeChild(String path)
- {
- return false;
- }
-
- /**
- * Find the handler.
- * TODO: synchronization on lazy entryMap creation
- *
- * @param name the path name
- * @return handler or <code>null</code> is it doesn't exist
- * @throws IOException for any error
- */
- protected synchronized VirtualFileHandler findChildHandler(String name) throws IOException
- {
- if (entryChildren == null)
- return null;
-
- if (entryMap == null)
- {
- entryMap = new HashMap<String, VirtualFileHandler>();
- for (VirtualFileHandler child : entryChildren)
- entryMap.put(child.getName(), child);
- }
- return entryMap.get(name);
- }
-
- // Convience attribute accessors
- public long getLastModified()
- {
- return getEntry().getTime();
- }
-
- public long getSize()
- {
- return getEntry().getSize();
- }
-
- public boolean isLeaf()
- {
- return isJar == false && getEntry().isDirectory() == false;
- }
-
- public boolean delete(int gracePeriod)
- {
- return false;
- }
-
- // Stream accessor
- public synchronized InputStream openStream() throws IOException
- {
- initNestedJar();
- if (njar != null)
- openStream = njar.openStream();
- else
- openStream = new ByteArrayInputStream(contents);
- return openStream;
- }
-
- public synchronized void close()
- {
- if (openStream != null)
- {
- try
- {
- openStream.close();
- }
- catch (IOException e)
- {
- log.error("close error", e);
- }
- openStream = null;
- }
- }
-
- public URI toURI() throws URISyntaxException
- {
- return entryURL.toURI();
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- if (isJar)
- {
- njar.internalReplaceChild(original, replacement);
- }
- else
- {
- entryChildren.remove(original);
- entryChildren.add(replacement);
- entryMap.put(original.getName(), replacement);
- }
- }
-
- public String toString()
- {
- StringBuffer tmp = new StringBuffer(super.toString());
- tmp.append('[');
- tmp.append("name=");
- tmp.append(getName());
- tmp.append(",size=");
- tmp.append(getSize());
- tmp.append(",time=");
- tmp.append(getLastModified());
- tmp.append(",URI=");
- try
- {
- tmp.append(toURI());
- }
- catch (URISyntaxException ignored)
- {
- }
- tmp.append(']');
- return tmp.toString();
- }
-
- protected synchronized void initNestedJar() throws IOException
- {
- if (isJar && njar == null)
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(contents);
- ZipInputStream zis = new ZipInputStream(bais);
- njar = new NestedJarFromStream(getVFSContext(), getParent(), zis, entryURL, null, getEntry(), getName());
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,190 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import org.jboss.virtual.plugins.context.HierarchyVirtualFileHandler;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * JarEntryHandler.
- * TODO: JBVFS-7
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
- */
-public class JarEntryHandler extends AbstractJarHandler implements StructuredVirtualFileHandler, HierarchyVirtualFileHandler
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- private List<VirtualFileHandler> entryChildren;
- private transient Map<String, VirtualFileHandler> entryMap;
-
- /**
- * Create a new JarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param jar the jar file
- * @param entry the entry
- * @param entryName the entry name
- * @param url the url
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url, jar or entry
- */
- public JarEntryHandler(VFSContext context, VirtualFileHandler parent, JarFile jar, ZipEntry entry, String entryName, URL url)
- throws IOException
- {
- super(context, parent, url, jar, entry, entryName);
- try
- {
- setVfsUrl(getChildVfsUrl(entryName, entry.isDirectory()));
- }
- catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- protected void initCacheLastModified()
- {
- // complete
- }
-
- @Override
- public boolean hasBeenModified() throws IOException
- {
- return false; // right now, jar entries should always
- }
-
- /**
- * Add a child to an entry
- *
- * @param child the child
- */
- public void addChild(VirtualFileHandler child)
- {
- if (entryChildren == null)
- entryChildren = new ArrayList<VirtualFileHandler>();
- entryChildren.add(child);
- if (entryMap != null)
- entryMap.put(child.getName(), child);
- }
-
- @Override
- public long getLastModified()
- {
- return getEntry().getTime();
- }
-
- @Override
- public long getSize()
- {
- return getEntry().getSize();
- }
-
- public boolean isLeaf()
- {
- return getEntry().isDirectory() == false;
- }
-
- public boolean isHidden()
- {
- checkClosed();
- return false;
- }
-
- public boolean isNested() throws IOException
- {
- return true;
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- checkClosed();
- if (entryChildren == null)
- return Collections.emptyList();
- return Collections.unmodifiableList(entryChildren);
- }
-
- @Override
- public InputStream openStream() throws IOException
- {
- return getJar().getInputStream(getEntry());
- }
-
- // TODO: synchronization on lazy entryMap creation
- public synchronized VirtualFileHandler createChildHandler(String name) throws IOException
- {
- if (entryChildren == null)
- return null;
-
- if (entryMap == null)
- {
- entryMap = new HashMap<String, VirtualFileHandler>();
- for (VirtualFileHandler child : entryChildren)
- entryMap.put(child.getName(), child);
- }
- return entryMap.get(name);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- return structuredFindChild(path);
- }
-
- public boolean removeChild(String path) throws IOException
- {
- return false;
- }
-
- public boolean delete(String path)
- {
- return false;
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- entryChildren.remove(original);
- entryChildren.add(replacement);
- entryMap.put(original.getName(), replacement);
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/JarHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,107 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.JarURLConnection;
-import java.net.URL;
-import java.util.jar.JarFile;
-
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * JarHandler.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @version $Revision: 1.1 $
- */
-public class JarHandler extends AbstractStructuredJarHandler<Object>
-{
- /** serialVersionUID */
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a new JarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param url the url
- * @param name the name
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
- */
- public JarHandler(VFSContext context, VirtualFileHandler parent, URL url, String name) throws IOException
- {
- super(context, parent, url, ((JarURLConnection)openConnection(url)).getJarFile(), null, name);
- setVfsUrl(new URL("vfs" + url));
-
- try
- {
- initJarFile();
- }
- catch (IOException original)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
- e.setStackTrace(original.getStackTrace());
- throw e;
- }
- }
-
- public JarHandler(VFSContext context, VirtualFileHandler parent, File file, URL url, String name) throws IOException
- {
- super(context, parent, url, new JarFile(file), null, name);
- setVfsUrl(new URL("vfs" + url));
-
- try
- {
- initJarFile();
- }
- catch (IOException original)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
- e.setStackTrace(original.getStackTrace());
- throw e;
- }
- }
-
- public boolean removeChild(String path) throws IOException
- {
- return false;
- }
-
- public boolean delete(int gracePeriod) throws IOException
- {
- getJar().close();
- File jarFile = new File(getJar().getName());
- return jarFile.delete();
- }
-
- public boolean isNested() throws IOException
- {
- return false;
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,409 +0,0 @@
-/*
- * Copyright (c) 2005 Your Corporation. All Rights Reserved.
- */
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamField;
-import java.io.ObjectInputStream.GetField;
-import java.io.ObjectOutputStream.PutField;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * A nested jar implementation used to represent a jar within a jar.
- *
- * @author Ales.Justin at jboss.org
- * @author Scott.Stark at jboss.org
- * @version $Revision: 44334 $
- */
-public class NestedJarFromStream extends AbstractStructuredJarHandler<byte[]>
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 2L;
- /** The class serial fields */
- private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("zisBytes", byte[].class),
- new ObjectStreamField("jarURL", URL.class),
- new ObjectStreamField("entryURL", String.class),
- new ObjectStreamField("lastModified", long.class),
- new ObjectStreamField("size", long.class)
- };
-
- private transient ZipInputStream zis;
- private transient AtomicBoolean inited = new AtomicBoolean(false);
- private URL jarURL;
- private URL entryURL;
- private long lastModified;
- private long size;
-
- /**
- * Create a nested jar from the parent zip inputstream/zip entry.
- *
- * @param context - the context containing the jar
- * @param parent - the jar handler for this nested jar
- * @param zis - the jar zip input stream
- * @param jarURL - the URL to use as the jar URL
- * @param jar - the parent jar file for the nested jar
- * @param entry - the zip entry
- * @param entryName - the entry name
- * @throws IOException for any error
- */
- public NestedJarFromStream(VFSContext context, VirtualFileHandler parent, ZipInputStream zis, URL jarURL, JarFile jar, ZipEntry entry, String entryName) throws IOException
- {
- super(context, parent, jarURL, jar, entry, entryName);
- this.jarURL = jarURL;
- this.lastModified = entry.getTime();
- this.size = entry.getSize();
- this.zis = zis;
- try
- {
- setPathName(getChildPathName(entryName, false));
- setVfsUrl(getChildVfsUrl(entryName, false));
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- protected void initCacheLastModified()
- {
- cachedLastModified = lastModified;
- }
-
- /**
- * Initialize entries.
- *
- * @throws IOException for any error
- */
- protected void init() throws IOException
- {
- if (inited.get() == false)
- {
- inited.set(true);
- try
- {
- initJarFile(new ZisEnumeration());
- }
- finally
- {
- close();
- }
- }
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- init();
- return super.getChildren(ignoreErrors);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- init();
- return super.getChild(path);
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return false;
- }
-
- public VirtualFileHandler createChildHandler(String name) throws IOException
- {
- init();
- return super.createChildHandler(name);
- }
-
- protected void extraWrapperInfo(ZipEntryWrapper<byte[]> wrapper) throws IOException
- {
- byte[] contents;
- int size = (int)wrapper.getSize();
- if (size != 0)
- {
- ByteArrayOutputStream baos = size > 0 ? new ByteArrayOutputStream(size) : new ByteArrayOutputStream();
- byte[] tmp = new byte[1024];
- while (zis.available() > 0)
- {
- int length = zis.read(tmp);
- if (length > 0)
- baos.write(tmp, 0, length);
- }
- contents = baos.toByteArray();
- }
- else
- contents = new byte[0];
- wrapper.setExtra(contents);
- }
-
- protected VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, ZipEntryWrapper<byte[]> wrapper, String entryName) throws IOException
- {
- try
- {
- String url = toURI().toASCIIString() + "!/" + wrapper.getName();
- URL jecURL = new URL(url);
- VFSContext context = parent.getVFSContext();
- if (wrapper.isDirectory())
- {
- return new SynthenticDirEntryHandler(context, parent, entryName, System.currentTimeMillis(), jecURL);
- }
- else
- {
- byte[] contents = wrapper.getExtra();
- return new JarEntryContents(context, parent, wrapper.getEntry(), entryName, toURL(), jecURL, contents);
- }
- }
- catch (Throwable t)
- {
- IOException ioe = new IOException("Exception while reading nested jar entry: " + this);
- ioe.initCause(t);
- ioe.setStackTrace(t.getStackTrace());
- throw ioe;
- }
- }
-
- /**
- * TODO: removing the entry/jar that resulted in this needs
- * to be detected.
- */
- public boolean exists() throws IOException
- {
- return true;
- }
-
- public boolean isHidden()
- {
- return false;
- }
-
- public long getSize()
- {
- return size;
- }
-
- public long getLastModified() throws IOException
- {
- return lastModified;
- }
-
- public boolean isNested() throws IOException
- {
- return true;
- }
-
- public boolean delete(int gracePeriod)
- {
- return false;
- }
-
- // Stream accessor
- public InputStream openStream() throws IOException
- {
- if(zis == null)
- {
- // Need to obtain this nested jar input stream from parent
- InputStream parentIS = super.getParent().openStream();
- if(parentIS == null)
- throw new IOException("Failed to open parent stream, "+this);
- if(parentIS instanceof ZipInputStream)
- {
- zis = (ZipInputStream) parentIS;
- }
- else
- {
- zis = new ZipInputStream(parentIS);
- }
- // First find our entry
- ZipEntry entry = zis.getNextEntry();
- while(entry != null)
- {
- if(entry.getName().equals(getName()))
- break;
- entry = zis.getNextEntry();
- }
- if(entry == null)
- throw new IOException("Failed to find nested jar entry: "+this.getName()+" in parent: "+getParent());
- }
- return zis;
- }
-
- public void close()
- {
- if (zis != null)
- {
- try
- {
- zis.close();
- }
- catch (IOException e)
- {
- log.error("close error", e);
- }
- zis = null;
- }
- }
-
- public URI toURI() throws URISyntaxException
- {
- try
- {
- if (entryURL == null)
- entryURL = new URL(jarURL, getName());
- }
- catch (MalformedURLException e)
- {
- throw new URISyntaxException("Failed to create relative jarURL", e.getMessage());
- }
- return entryURL.toURI();
- }
-
- public String toString()
- {
- StringBuffer tmp = new StringBuffer(super.toString());
- tmp.append('[');
- tmp.append("name=");
- tmp.append(getName());
- tmp.append(",size=");
- tmp.append(getSize());
- tmp.append(",lastModified=");
- tmp.append(lastModified);
- tmp.append(",URI=");
- try
- {
- tmp.append(toURI());
- }
- catch (URISyntaxException e)
- {
- }
- tmp.append(']');
- return tmp.toString();
- }
-
- protected void initJarFile() throws IOException
- {
- // todo - deserialize
- }
-
- private class ZisEnumeration implements Enumeration<ZipEntryWrapper<byte[]>>
- {
- private boolean moved = true;
- private ZipEntry next = null;
-
- public boolean hasMoreElements()
- {
- if (zis == null)
- return false;
-
- try
- {
- if (moved)
- {
- next = zis.getNextEntry();
- moved = false;
- }
- return next != null;
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- public ZipEntryWrapper<byte[]> nextElement()
- {
- moved = true;
- return new ZipEntryWrapper<byte[]>(next);
- }
- }
- /**
- * Write the jar contents and information
- * @param out
- * @throws IOException
- */
- private void writeObject(ObjectOutputStream out)
- throws IOException
- {
- PutField fields = out.putFields();
-
- byte[] zisBytes;
- ZipInputStream jarStream = zis;
- if(jarStream == null)
- {
- // Need to obtain this nested jar input stream from parent
- InputStream parentIS = super.getParent().openStream();
- if(parentIS == null)
- throw new IOException("Failed to open parent stream, "+this);
- jarStream = new ZipInputStream(parentIS);
- // First find our entry
- ZipEntry entry = jarStream.getNextEntry();
- while(entry != null)
- {
- if(entry.getName().equals(getName()))
- break;
- entry = jarStream.getNextEntry();
- }
- if(entry == null)
- throw new IOException("Failed to find nested jar entry: "+this.getName()+" in parent: "+getParent());
- }
- // Now read zis for this entry
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] tmp = new byte[1024];
- int length = jarStream.read(tmp);
- while(length > 0)
- {
- baos.write(tmp, 0, length);
- length = jarStream.read(tmp);
- }
- jarStream.close();
- jarStream = null;
- zisBytes = baos.toByteArray();
- fields.put("zisBytes", zisBytes);
- fields.put("jarURL", jarURL);
- fields.put("entryURL", entryURL);
- fields.put("lastModified", lastModified);
- fields.put("size", size);
- out.writeFields();
- }
-
- /**
- * Read the jar contents and reinitialize the entry map
- * @param in
- * @throws IOException
- * @throws ClassNotFoundException
- */
- private void readObject(ObjectInputStream in)
- throws IOException, ClassNotFoundException
- {
- // Read in the serialPersistentFields
- GetField fields = in.readFields();
- byte[] zisBytes = (byte[]) fields.get("zisBytes", null);
- this.jarURL = (URL) fields.get("jarURL", null);
- this.entryURL = (URL) fields.get("entryURL", null);
- this.lastModified = fields.get("lastModified", (long)-1);
- this.size = fields.get("size", (long)-1);
- // Initialize the jar entry map
- inited = new AtomicBoolean(false);
- ByteArrayInputStream bais = new ByteArrayInputStream(zisBytes);
- zis = new ZipInputStream(bais);
- this.init();
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NestedJarHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,224 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.VFSUtils;
-
-/**
- * Nested Jar Handler.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @version $Revision: 1.1 $
- */
-public class NestedJarHandler extends AbstractStructuredJarHandler<Object>
-{
- /** serialVersionUID */
- private static final long serialVersionUID = 1L;
-
- /** The temporary file */
- private transient File temp;
-
- /**
- * Create a temporary jar
- *
- * @param temp the temporary file
- * @param parentJar the jar
- * @param entry the jar entry
- * @return the jar file
- * @throws IOException for any error
- */
- private static JarFile createTempJar(File temp, JarFile parentJar, ZipEntry entry) throws IOException
- {
- InputStream inputStream = parentJar.getInputStream(entry);
- try
- {
- FileOutputStream outputStream = new FileOutputStream(temp);
- try
- {
- byte[] buffer = new byte[8096];
- int read = inputStream.read(buffer);
- while (read != -1)
- {
- outputStream.write(buffer, 0, read);
- read = inputStream.read(buffer);
- }
- }
- finally
- {
- VFSUtils.safeClose(outputStream);
- }
- }
- finally
- {
- VFSUtils.safeClose(inputStream);
- }
-
- return new JarFile(temp);
- }
-
- public static NestedJarHandler create(VFSContext context, VirtualFileHandler parent,
- JarFile parentJar, ZipEntry entry, URL url, String entryName) throws IOException
- {
- File temp;
- try
- {
- temp = File.createTempFile("nestedjar", null);
- temp.deleteOnExit();
- }
- catch (IOException original)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
- e.setStackTrace(original.getStackTrace());
- throw e;
- }
- return new NestedJarHandler(context, parent, parentJar, entry, url, temp, entryName);
- }
-
- /**
- * Create a new NestedJarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param parentJar the parent jar file
- * @param entry the jar entry
- * @param original the original url
- * @param temp the temporary file
- * @param entryName the entry name
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
- */
- protected NestedJarHandler(VFSContext context, VirtualFileHandler parent, JarFile parentJar, ZipEntry entry, URL original, File temp, String entryName)
- throws IOException
- {
- super(context, parent, temp.toURI().toURL(), createTempJar(temp, parentJar, entry), entry, entryName);
-
- try
- {
- setPathName(getChildPathName(entryName, false));
- setVfsUrl(getChildVfsUrl(entryName, false));
- }
- catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
-
- this.temp = temp;
-
- try
- {
- initJarFile();
- }
- catch (IOException old)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + original + " reason=" + old.getMessage());
- e.setStackTrace(old.getStackTrace());
- throw e;
- }
- }
-
- @Override
- public long getLastModified() throws IOException
- {
- return getEntry().getTime();
- }
-
- @Override
- public long getSize() throws IOException
- {
- return getEntry().getSize();
- }
-
- public boolean isNested() throws IOException
- {
- return false;
- }
-
- /**
- * Overriden to return the raw tmp jar file stream
- */
- @Override
- public InputStream openStream() throws IOException
- {
- return new FileInputStream(temp);
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return false;
- }
-
- @Override
- public void cleanup()
- {
- try
- {
- delete(2000);
- }
- catch (Exception ignored)
- {
- }
- }
-
- public boolean delete(int gracePeriod) throws IOException
- {
- if (temp != null)
- {
- boolean deleted = temp.delete();
- if (deleted)
- return super.delete(gracePeriod);
- return deleted;
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Restore the temp file
- *
- * @param in the input stream
- * @throws IOException for any error reading the jar file
- * @throws ClassNotFoundException for any jar class finding errors
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- // TODO - temp?
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,163 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * Nested Jar Handler.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- * @version $Revision: 1.1 $
- */
-public class NoCopyNestedJarHandler extends AbstractJarHandler
-{
- /** serialVersionUID */
- private static final long serialVersionUID = 1L;
-
- /** The nested jar */
- private NestedJarFromStream njar;
-
- /**
- * Create a new NestedJarHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param parentJar the parent jar file
- * @param entry the jar entry
- * @param url the url
- * @param entryName the entry name
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
- */
- public NoCopyNestedJarHandler(VFSContext context, VirtualFileHandler parent, JarFile parentJar, ZipEntry entry, URL url, String entryName) throws IOException
- {
- super(context, parent, url, parentJar, entry, entryName);
-
- try
- {
- setPathName(getChildPathName(entryName, false));
- setVfsUrl(getChildVfsUrl(entryName, false));
- }
- catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
-
- try
- {
- InputStream is = parentJar.getInputStream(entry);
- ZipInputStream zis;
- if(is instanceof ZipInputStream)
- {
- zis = (ZipInputStream) is;
- }
- else
- {
- zis = new ZipInputStream(is);
- }
- njar = new NestedJarFromStream(context, parent, zis, url, parentJar, entry, entryName);
- }
- catch (IOException original)
- {
- // Fix the context of the error message
- IOException e = new IOException("Error opening jar file: " + url + " reason=" + original.getMessage());
- e.setStackTrace(original.getStackTrace());
- throw e;
- }
- }
-
- protected void initCacheLastModified()
- {
- }
-
- @Override
- public long getLastModified() throws IOException
- {
- return getEntry().getTime();
- }
-
- @Override
- public long getSize() throws IOException
- {
- return getEntry().getSize();
- }
-
- @Override
- public boolean isArchive() throws IOException
- {
- return njar.isArchive();
- }
-
- public boolean isNested() throws IOException
- {
- return true;
- }
-
- @Override
- public InputStream openStream() throws IOException
- {
- return getJar().getInputStream(getEntry());
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- if (path == null)
- throw new IllegalArgumentException("Null path");
-
- if ("".equals(path))
- return this;
-
- return njar.getChild(path);
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return false;
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- return njar.getChildren(ignoreErrors);
- }
-
- public boolean delete(int gracePeriod)
- {
- return false;
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- njar.internalReplaceChild(original, replacement);
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,204 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.virtual.plugins.context.AbstractURLHandler;
-import org.jboss.virtual.plugins.context.HierarchyVirtualFileHandler;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * SynthenticDirEntryHandler represents non-existent directory jar entry.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
- */
-public class SynthenticDirEntryHandler extends AbstractURLHandler
- implements StructuredVirtualFileHandler, HierarchyVirtualFileHandler
-{
- /**
- * serialVersionUID
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * The jar file
- */
- private List<VirtualFileHandler> entryChildren;
- private transient Map<String, VirtualFileHandler> entryMap;
-
- /**
- * Create a new SynthenticDirEntryHandler.
- *
- * @param context the context
- * @param parent the parent
- * @param entryName - the simple name for the dir
- * @param lastModified the timestamp for the dir
- * @param url the full url
- * @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url, jar or entry
- */
- public SynthenticDirEntryHandler(VFSContext context, VirtualFileHandler parent,
- String entryName, long lastModified, URL url)
- throws IOException
- {
- super(context, parent, url, entryName);
- try
- {
- URL parentVfsUrl = parent.toVfsUrl();
- String vfsParentUrl = parentVfsUrl.toString();
- setVfsUrl(getChildVfsUrl(entryName, vfsParentUrl.endsWith("/") == false));
- }
- catch (URISyntaxException e)
- {
- throw new RuntimeException(e);
- }
- this.cachedLastModified = lastModified;
- }
-
- protected void initCacheLastModified()
- {
- }
-
- /**
- * Add a child to an entry
- *
- * @param child the child file handler
- */
- public synchronized void addChild(VirtualFileHandler child)
- {
- if (entryChildren == null)
- entryChildren = new ArrayList<VirtualFileHandler>();
- entryChildren.add(child);
- if (entryMap != null)
- entryMap.put(child.getName(), child);
- }
-
- @Override
- public long getLastModified() throws IOException
- {
- checkParentExists();
- return getParent().getLastModified();
- }
-
- @Override
- public long getSize()
- {
- return 0;
- }
-
- /**
- * TODO: removing the entry/jar that resulted in this needs
- * to be detected.
- */
- public boolean exists() throws IOException
- {
- return true;
- }
-
- public boolean isLeaf()
- {
- return false;
- }
-
- public boolean isHidden()
- {
- checkClosed();
- return false;
- }
-
- public boolean isNested() throws IOException
- {
- return true;
- }
-
- public boolean delete(int gracePeriod)
- {
- return false;
- }
-
- @Override
- public InputStream openStream() throws IOException
- {
- throw new IOException("Directories cannot be opened");
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- checkClosed();
- if (entryChildren == null)
- return Collections.emptyList();
- return Collections.unmodifiableList(entryChildren);
- }
-
- /**
- * Create a child handler for the given name. This looks to the entryMap
- * for an existing child.
- *
- * @param name - the simple name of an immeadiate child.
- * @return the VirtualFileHandler previously added via addChild.
- * @throws IOException - thrown if there are no children or the
- * name does not match a child
- */
- // TODO: synchronization on lazy entryMap creation
- public synchronized VirtualFileHandler createChildHandler(String name) throws IOException
- {
- if (entryChildren == null)
- return null;
-
- if (entryMap == null)
- {
- entryMap = new HashMap<String, VirtualFileHandler>();
- for (VirtualFileHandler child : entryChildren)
- entryMap.put(child.getName(), child);
- }
- return entryMap.get(name);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- return structuredFindChild(path);
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return false;
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- entryChildren.remove(original);
- entryChildren.add(replacement);
- entryMap.put(original.getName(), replacement);
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/ZipEntryWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/ZipEntryWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jar/ZipEntryWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,78 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.jar;
-
-import java.util.zip.ZipEntry;
-
-/**
- * Zip entry wrapper.
- *
- * @param <T> exact extra type
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-class ZipEntryWrapper<T>
-{
- private ZipEntry entry;
- private T extra;
-
- ZipEntryWrapper(ZipEntry entry)
- {
- if (entry == null)
- throw new IllegalArgumentException("Null zip entry");
- this.entry = entry;
- }
-
- public ZipEntry getEntry()
- {
- return entry;
- }
-
- public String getName()
- {
- return entry.getName();
- }
-
- public boolean isDirectory()
- {
- return entry.isDirectory();
- }
-
- public long getTime()
- {
- return entry.getTime();
- }
-
- public long getSize()
- {
- return entry.getSize();
- }
-
- public T getExtra()
- {
- return extra;
- }
-
- public void setExtra(T extra)
- {
- this.extra = extra;
- }
-}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipContextFactory.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipContextFactory.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipContextFactory.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.virtual.plugins.context.jzip;
+
+import org.jboss.virtual.plugins.context.AbstractContextFactory;
+import org.jboss.virtual.spi.VFSContext;
+
+import java.net.URL;
+import java.net.URI;
+import java.io.IOException;
+
+public final class ZipContextFactory extends AbstractContextFactory
+{
+ private static final ZipContextFactory instance = new ZipContextFactory();
+
+ public VFSContext getVFS(URL rootURL) throws IOException
+ {
+ return null;
+ }
+
+ public VFSContext getVFS(URI rootURI) throws IOException
+ {
+ return null;
+ }
+
+ public static ZipContextFactory getInstance()
+ {
+ return instance;
+ }
+}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipEntryContext.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipEntryContext.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.virtual.plugins.context.jzip;
+
+import org.jboss.virtual.plugins.context.AbstractVFSContext;
+import org.jboss.virtual.plugins.context.DelegatingHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URISyntaxException;
+
+public final class ZipEntryContext extends AbstractVFSContext
+{
+
+ public ZipEntryContext(URL url) throws URISyntaxException
+ {
+ super(url);
+ }
+
+ public ZipEntryContext(URL delegatorUrl, DelegatingHandler delegator, URL fileUrl) throws URISyntaxException
+ {
+ super(delegatorUrl);
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public VirtualFileHandler getRoot() throws IOException
+ {
+ return null;
+ }
+}
Added: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipFileHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipFileHandler.java (rev 0)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/jzip/ZipFileHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.virtual.plugins.context.jzip;
+
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.jzipfile.ZipEntry;
+import org.jboss.jzipfile.Zip;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.util.List;
+
+public final class ZipFileHandler extends AbstractVirtualFileHandler
+{
+ private final File zipFile;
+ private final ZipEntry zipEntry;
+
+ public URI toURI() throws URISyntaxException
+ {
+ return null;
+ }
+
+ public long getLastModified() throws IOException
+ {
+ return zipEntry.getModificationTime();
+ }
+
+ public long getSize() throws IOException
+ {
+ return zipEntry.getSize();
+ }
+
+ public boolean exists() throws IOException
+ {
+ return true;
+ }
+
+ public boolean isLeaf() throws IOException
+ {
+ return true;
+ }
+
+ public boolean isHidden() throws IOException
+ {
+ return false;
+ }
+
+ public InputStream openStream() throws IOException
+ {
+ return Zip.openEntry(zipFile, zipEntry);
+ }
+
+ public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
+ {
+ return null;
+ }
+
+ public VirtualFileHandler getChild(String path) throws IOException
+ {
+ return null;
+ }
+
+ public boolean removeChild(String name) throws IOException
+ {
+ return false;
+ }
+
+ public boolean isNested() throws IOException
+ {
+ return false;
+ }
+}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,148 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import org.jboss.virtual.VFSUtils;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * ZipBytesWrapper - for abstracted access to in-memory bytes entry
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-abstract class ZipBytesWrapper extends ZipWrapper
-{
- /** Zip archive loaded in memory */
- private byte [] zipBytes;
-
- /** Name */
- private String name;
-
- /**
- * ZipBytesWrapper is not aware of actual zip source so it can not detect
- * if it's been modified, like ZipFileWrapper does.
- *
- * @param zipStream the current zip input stream
- * @param name the name
- * @param lastModified passed by zip stream provider - constant value
- * @throws IOException for any error
- */
- ZipBytesWrapper(InputStream zipStream, String name, long lastModified) throws IOException
- {
- // read the contents into memory buffer
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- VFSUtils.copyStreamAndClose(zipStream, bout);
- zipBytes = bout.toByteArray();
-
- // TODO - delegate file meta info operations to parent?
- this.name = name;
- this.lastModified = lastModified;
- }
-
- /**
- * Returns true if archive exists
- *
- * @return always true
- */
- boolean exists()
- {
- return true;
- }
-
- /**
- * Returns lastModified of this archive
- *
- * @return constant lastModified
- */
- long getLastModified()
- {
- return lastModified;
- }
-
- /**
- * Returns the name of this archive
- *
- * @return name
- */
- String getName()
- {
- return name;
- }
-
- /**
- * Returns the size of this archive
- *
- * @return uncompressed size of this archive
- */
- long getSize()
- {
- return zipBytes.length;
- }
-
- /**
- * Returns raw bytes that represent this archive in its compressed form
- *
- * @return compressed bytes of this archive - as <tt>InputStream<tt>
- * @throws FileNotFoundException for any error
- */
- InputStream getRootAsStream() throws FileNotFoundException
- {
- return new ByteArrayInputStream(zipBytes);
- }
-
- /**
- * Acquire lock. No-op in this implementation
- */
- void acquire()
- {
- }
-
- /**
- * Close this wrapper - release memory buffer that stores
- * raw bytes of the archive in its compressed form
- */
- void close()
- {
- zipBytes = null;
- }
-
- boolean delete(int gracePeriod) throws IOException
- {
- close();
- return true;
- }
-
- /**
- * String description of this archive
- *
- * @return string description of this archive
- */
- public String toString()
- {
- return super.toString() + " - " + name;
- }
-}
\ No newline at end of file
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,113 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Enumeration;
-
-import org.jboss.virtual.spi.zip.ZipEntry;
-import org.jboss.virtual.spi.zip.ZipEntryProvider;
-import org.jboss.virtual.spi.zip.ZipFactory;
-import org.jboss.virtual.spi.zip.ZipUtils;
-
-/**
- * ZipDirWrapper - for abstracted access to in-memory directory
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-class ZipDirWrapper extends ZipBytesWrapper
-{
- private ByteArrayInputStream zisCopy;
-
- /**
- * ZipStreamWrapper is not aware of actual zip source so it can not detect
- * if it's been modified, like ZipFileWrapper does.
- *
- * @param zipStream the current zip input stream
- * @param name the name
- * @param lastModified passed by zip stream provider - constant value
- * @param zisCopy zis copy
- * @throws java.io.IOException for any error
- */
- ZipDirWrapper(InputStream zipStream, String name, long lastModified, ByteArrayInputStream zisCopy) throws IOException
- {
- super(zipStream, name, lastModified);
- this.zisCopy = zisCopy;
- }
-
- InputStream openStream(ZipEntry ent) throws IOException
- {
- zisCopy.reset();
- // TODO - optimize this
- ZipFactory factory = ZipUtils.getFactory();
- ZipEntryProvider zis = factory.createProvider(zisCopy);
- ZipEntry entry = zis.getNextEntry();
- while (entry != null && entry.getName().equals(ent.getName()) == false)
- entry = zis.getNextEntry();
-
- return zis.currentStream();
- }
-
- Enumeration<? extends ZipEntry> entries() throws IOException
- {
- zisCopy.reset();
- return new DirEnumeration();
- }
-
- /**
- * Zip stream enumeration.
- */
- private class DirEnumeration implements Enumeration<ZipEntry>
- {
- private ZipEntryProvider zis;
- private ZipEntry entry;
-
- private DirEnumeration() throws IOException
- {
- ZipFactory factory = ZipUtils.getFactory();
- this.zis = factory.createProvider(zisCopy);
- }
-
- public boolean hasMoreElements()
- {
- try
- {
- entry = zis.getNextEntry();
- while (entry != null && entry.getName().startsWith(getName()) == false)
- entry = zis.getNextEntry();
- return entry != null;
- }
- catch (IOException e)
- {
- log.warn("Error retrieving entries for entry " + getName() + ", cause: " + e);
- return false;
- }
- }
-
- public ZipEntry nextElement()
- {
- return entry;
- }
- }
-}
\ No newline at end of file
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,1437 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.context.AbstractVFSContext;
-import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
-import org.jboss.virtual.plugins.context.DelegatingHandler;
-import org.jboss.virtual.plugins.context.ReplacementHandler;
-import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
-import org.jboss.virtual.spi.ExceptionHandler;
-import org.jboss.virtual.spi.Options;
-import org.jboss.virtual.spi.TempInfo;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VFSContextConstraints;
-import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.spi.zip.ZipEntry;
-import org.jboss.virtual.spi.zip.ZipEntryProvider;
-import org.jboss.virtual.spi.zip.ZipUtils;
-import org.jboss.virtual.spi.zip.ZipFactory;
-
-/**
- * <tt>ZipEntryContext</tt> implements a {@link org.jboss.virtual.spi.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 <tt>ZipEntryContext</tt> with <tt>ZipStreamWrapper</tt> as a source.
- * If system property <em>jboss.vfs.forceCopy=true</em> is specified,
- * or URL query parameter <em>forceCopy=true</em> is present,
- * nested archives are extracted into a temp directory before being
- * mounted as new instances of <tt>ZipEntryContext</tt>.
- *
- * In-memory nested archives may consume a lot of memory. To reduce memory footprint
- * at the expense of performance, system property <em>jboss.vfs.optimizeForMemory=true<em>
- * can be set.
- *
- * This context implementation has two modes of releasing file locks.
- * <em>Asynchronous</em> mode is the default one since it is better performant.
- * To switch this to <em>synchronous</em> mode a system property
- * <em>jboss.vfs.forceNoReaper=true</em> can be specified or URL query parameter
- * <em>noReaper=true</em> can be included in context URL.
- *
- * This context implementation is a replacement for
- * {@link org.jboss.virtual.plugins.context.jar.JarContext}.
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- * @author <a href="david.lloyd at jboss.com">David M. Lloyd</a>
- * @version $Revision: 1.0 $
- */
-public class ZipEntryContext extends AbstractVFSContext
-{
- /** Logger */
- private static final Logger log = Logger.getLogger(ZipEntryContext.class);
-
- /** Global setting for nested archive processing mode: copy or no-copy (default) */
- private static boolean forceCopy;
-
- static
- {
- deleteTmpDirContents();
-
- forceCopy = AccessController.doPrivileged(new CheckForceCopy());
-
- if (forceCopy)
- log.info("VFS force nested jars copy-mode is enabled.");
- }
-
- /** The empty bytes const */
- private static final byte[] NO_BYTES = new byte[0];
-
- /** The constraints set */
- private static final Set<VFSContextConstraints> CONSTRAINTS = Collections.singleton(VFSContextConstraints.CACHEABLE);
-
- /** Abstracted access to zip archive - either ZipFileWrapper or ZipStreamWrapper */
- private volatile ZipWrapper zipSource;
-
- /** Entry path representing a context root - archive root is not necessarily a context root */
- private volatile String rootEntryPath = "";
-
- /** path to zip file - used for lazy ZipWrapper initialization */
- private volatile String filePath = null;
-
- /** AutoClean signals if zip archive should be deleted after closing the context - true for nested archives */
- private final boolean autoClean;
-
- /** Registry of everything that zipSource contains */
- private final Map<String, EntryInfo> entries = new ConcurrentHashMap<String, EntryInfo>(16,.75f,4);
-
- /** Have zip entries been navigated yet */
- private volatile InitializationStatus initStatus = InitializationStatus.NOT_INITIALIZED;
-
- /** RealURL of this context */
- private volatile URL realURL;
-
- /**
- * Create a new ZipEntryContext
- *
- * @param rootURL - file or jar:file url
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- public ZipEntryContext(URL rootURL) throws URISyntaxException, IOException
- {
- this(rootURL, false);
- }
-
- /**
- * Create a new ZipEntryContext
- *
- * @param rootURL - file or jar:file url
- * @param autoClean - true if file represented by rootURL should be deleted after this context is closed
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- public ZipEntryContext(URL rootURL, boolean autoClean) throws URISyntaxException, IOException
- {
- super(VFSUtils.toURI(fixUrl(rootURL)));
- this.autoClean = autoClean;
- init(rootURL, null, null);
- }
-
- /**
- * Create a new ZipEntryContext to be mounted into another context
- *
- * @param rootURL - url representing this context within another context
- * @param peer - file handler in another context through which this context is being mounted
- * @param localRootUrl - file or jar:file url
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- public ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl) throws URISyntaxException, IOException
- {
- this(rootURL, peer, localRootUrl, false);
- }
-
- /**
- * Create a new ZipEntryContext to be mounted into another context
- *
- * @param rootURL - url representing this context within another context
- * @param peer - file handler in another context through which this context is being mounted
- * @param localRootUrl - file or jar:file url
- * @param autoClean - true if file represented by localRootURL should be deleted after this context is closed
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- public ZipEntryContext(URL rootURL, VirtualFileHandler peer, URL localRootUrl, boolean autoClean) throws URISyntaxException, IOException
- {
- super(VFSUtils.toURI(fixUrl(rootURL)));
- this.autoClean = autoClean;
- init(localRootUrl, peer, null);
- }
-
- /**
- * Create a new ZipEntryContext to be mounted into another context
- *
- * @param rootURL - url representing this context within another context
- * @param peer - file handler in another context through which this context is being mounted
- * @param zipWrapper - abstracted zip archive source
- * @param autoClean - true if file represented by localRootURL should be deleted after this context is closed
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- public ZipEntryContext(URL rootURL, VirtualFileHandler peer, ZipWrapper zipWrapper, boolean autoClean) throws URISyntaxException, IOException
- {
- super(VFSUtils.toURI(fixUrl(rootURL)));
- this.autoClean = autoClean;
- init(null, peer, zipWrapper);
- }
-
- /**
- * Extra initialization in addition to what's inside constructors
- *
- * @param localRootURL the local url
- * @param peer the peer
- * @param zipWrapper zip wrapper
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- private void init(URL localRootURL, VirtualFileHandler peer, ZipWrapper zipWrapper) throws IOException, URISyntaxException
- {
- if (zipWrapper == null)
- {
- if (localRootURL == null)
- throw new IllegalArgumentException("No ZipWrapper specified and localRootURL is null");
-
- // initialize rootEntryPath and get archive file path
- filePath = initRootAndPath(localRootURL);
- }
- else
- {
- zipSource = zipWrapper;
- }
-
- setRootPeer(peer);
- String name = getRootURI().getPath();
- int toPos = name.length();
-
- // cut off any ending slash
- if(name.length() != 0 && name.charAt(name.length()-1) == '/')
- toPos --;
-
- // name is last path component
- int namePos = name.lastIndexOf("/", toPos-1);
- name = name.substring(namePos+1, toPos);
-
- // cut off any ending exclamation
- if(name.length() != 0 && name.charAt(name.length()-1) == '!')
- name = name.substring(0, name.length()-1);
-
- // init initial root EntryInfo that will be overwritten
- // if zip entry exists for rootEntryPath
- entries.put("", new EntryInfo(new ZipEntryHandler(this, null, name, false), null));
-
- // It's lazy init now
- //initEntries();
- }
-
- /**
- * Get zip source.
- * Lazy init.
- *
- * @return the zip source
- */
- protected synchronized ZipWrapper getZipSource()
- {
- if (zipSource == null)
- {
- try
- {
- zipSource = createZipSource(filePath);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Failed to initialize ZipWrapper: " + filePath, e);
- }
- }
- return zipSource;
- }
-
- /**
- * Returns aggregated options.
- *
- * If peer exists, it uses peer context's options as a basis,
- * and overrides them with this context's options.
- *
- * @return map containing aggregated options
- */
- public Options getAggregatedOptions()
- {
- Options aggregatedOptions = createNewOptions();
- VFSContext peerContext = getPeerContext();
- if (peerContext != null)
- aggregatedOptions.merge(peerContext.getOptions());
- aggregatedOptions.merge(super.getOptions()); // put them after peer, possible override
- return aggregatedOptions;
- }
-
- public ExceptionHandler getExceptionHandler()
- {
- ExceptionHandler eh = super.getExceptionHandler();
- if (eh != null)
- return eh;
-
- VFSContext peerContext = getPeerContext();
- return peerContext != null ? peerContext.getExceptionHandler() : null;
- }
-
- /**
- * Create zip source.
- *
- * @param rootPath the root path
- * @return zip entry wrapper
- * @throws IOException for any error
- */
- protected ZipWrapper createZipSource(String rootPath) throws IOException
- {
- File file = null;
- String relative = null;
- File fp = new File(VFSUtils.decode(rootPath));
- if (fp.exists())
- {
- file = fp;
- }
- else
- {
- File curr = fp;
- relative = fp.getName();
- while ((curr = curr.getParentFile()) != null)
- {
- if (curr.exists())
- {
- file = curr;
- break;
- }
- else
- {
- relative = curr.getName() + "/" + relative;
- }
- }
- }
-
- if (file == null)
- throw new IOException("VFS file does not exist: " + rootPath);
-
- RealURLInfo urlInfo = new RealURLInfo(file);
-
- if (relative != null)
- {
- ZipWrapper wrapper = findEntry(new FileInputStream(file), relative, urlInfo);
- realURL = urlInfo.toURL();
- return wrapper;
- }
- else
- {
- Options aggregatedOptions = getAggregatedOptions();
- boolean noReaper = aggregatedOptions.getBooleanOption(VFSUtils.NO_REAPER_QUERY);
- realURL = urlInfo.toURL();
- boolean isAutoClean = autoClean || aggregatedOptions.getBooleanOption(VFSUtils.IS_TEMP_FILE);
- return new ZipFileWrapper(file, isAutoClean, noReaper);
- }
- }
-
- /**
- * Find exact entry.
- * Use recursion on relative path.
- *
- * @param is the input stream
- * @param relative relative path
- * @param urlInfo url info
- * @return zip wrapper instance
- * @throws IOException for any error
- */
- protected ZipWrapper findEntry(InputStream is, String relative, RealURLInfo urlInfo) throws IOException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStreamAndClose(is, baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- ZipFactory factory = ZipUtils.getFactory();
- ZipEntry entry;
- String longestNameMatch = null;
-
- // first we need to find best/longest name
- ZipEntryProvider zis = factory.createProvider(bais);
- try
- {
- while((entry = zis.getNextEntry()) != null)
- {
- String entryName = entry.getName();
- String match = entryName;
- if (entry.isDirectory())
- match = match.substring(0, match.length() - 1);
-
- if (relative.startsWith(match))
- {
- if (match.equals(relative))
- {
- if (entry.isDirectory())
- {
- this.rootEntryPath = relative;
- return new ZipDirWrapper(zis.currentStream(), entryName, System.currentTimeMillis(), bais);
- }
- else if (JarUtils.isArchive(match) == false)
- {
- return new ZipEntryWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
- }
- else
- {
- return new ZipStreamWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
- }
- }
-
- if (longestNameMatch == null || longestNameMatch.length() < entryName.length())
- {
- longestNameMatch = entryName; // keep entry name
- }
- }
- }
- if (longestNameMatch == null)
- throw new IllegalArgumentException("Cannot find entry: " + is + ", " + relative);
- zis.close();
- }
- finally
- {
- VFSUtils.safeClose(zis);
- }
-
- // do recursion on relative
- bais.reset();
- zis = factory.createProvider(bais);
- try
- {
- while((entry = zis.getNextEntry()) != null)
- {
- String entryName = entry.getName();
- if (entryName.equals(longestNameMatch))
- {
- if (urlInfo != null)
- urlInfo.relativePath = longestNameMatch;
-
- relative = relative.substring(longestNameMatch.length() + 1);
- return findEntry(zis.currentStream(), relative, null);
- }
- }
- zis.close();
- }
- finally
- {
- VFSUtils.safeClose(zis);
- }
- throw new IllegalArgumentException("No such entry: " + is + ", " + relative);
- }
-
- public Set<VFSContextConstraints> getConstraints()
- {
- return CONSTRAINTS;
- }
-
- /**
- * Returns archive file name - if this is a top-level ZipEntryContext.
- * Otherwise it returns the last component of URL.
- *
- * @return name
- */
- public String getName()
- {
- VirtualFileHandler peer = getRootPeer();
- if (peer != null)
- return peer.getName();
- else
- return getZipSource().getName();
- }
-
- /**
- * Iterate through zip archive entries, compose a tree structure of archive's content
- *
- * @throws URISyntaxException for any URI error
- * @throws java.io.IOException for any error
- */
- private synchronized void initEntries() throws IOException, URISyntaxException
- {
- boolean trace = log.isTraceEnabled();
-
- // we're using a two phase approach - we first select the relevant ones
- // then we order these by name and only then we process them
- // this way we ensure that parent entries are processed before child entries
-
- Map<String, ZipEntry> relevant = new HashMap<String, ZipEntry>();
- ZipWrapper zipSource = getZipSource();
- zipSource.acquire();
- try
- {
- Enumeration<? extends ZipEntry> zipEntries = zipSource.entries();
- // zoom-in on entries under rootEntryPath - ignoring the rest
- while (zipEntries.hasMoreElements())
- {
- ZipEntry ent = zipEntries.nextElement();
- if (ent.getName().startsWith(rootEntryPath))
- {
- relevant.put(ent.getName(), ent);
- }
- }
-
- Map<String, ZipEntry> orderedRelevant = new TreeMap<String, ZipEntry>(relevant);
- for (Map.Entry<String, ZipEntry> entry : orderedRelevant.entrySet())
- {
- ZipEntry ent = entry.getValue();
- String fullName = ent.getName().substring(rootEntryPath.length());
-
- String[] split = splitParentChild(fullName);
- String parentPath = split[0];
- String name = split[1];
-
- EntryInfo ei = null;
- if ("".equals(name) == false)
- {
- ei = entries.get(parentPath);
- if (ei == null)
- ei = makeDummyParent(parentPath);
- }
- AbstractVirtualFileHandler parent = ei != null ? ei.handler : null;
-
- // it's a nested jar
- if (ent.isDirectory() == false && JarUtils.isArchive(ent.getName()))
- {
- boolean useCopyMode = forceCopy;
- if (useCopyMode == false)
- useCopyMode = getAggregatedOptions().getBooleanOption(VFSUtils.USE_COPY_QUERY);
-
- DelegatingHandler delegator;
-
- if (useCopyMode)
- {
- File dest = null;
- String entryName = ent.getName();
- String path = null;
-
- VFSContext context = getPeerContext();
- if (context != null)
- {
- path = getPath(context, entryName);
- TempInfo ti = context.getTempInfo(path);
- if (ti != null && ti.isValid())
- {
- dest = ti.getTempFile();
- }
- }
-
- boolean createNewTempInfo = (dest == null || dest.exists() == false);
-
- if (createNewTempInfo)
- {
- // extract it to temp dir
- dest = new File(getTempDir() + "/" + getTempFileName(entryName));
- dest.deleteOnExit();
-
- if (trace)
- {
- StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
- log.trace("Dest: " + dest + ", Stack-trace:\n" + Arrays.toString(stackTraceElements));
- }
-
- // ensure parent exists
- dest.getParentFile().mkdirs();
-
- InputStream is = zipSource.openStream(ent);
- OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
- VFSUtils.copyStreamAndClose(is, os);
- }
-
- // mount another instance of ZipEntryContext
- delegator = mountZipFile(parent, name, dest);
-
- if (context != null && path != null && createNewTempInfo)
- context.addTempInfo(new ZipEntryTempInfo(path, dest, delegator, this));
- }
- else
- {
- // mount another instance of ZipEntryContext
- delegator = mountZipStream(parent, name, zipSource.openStream(ent));
- }
-
- entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
- addChild(parent, delegator);
- }
- else
- {
- ZipEntryHandler wrapper = new ZipEntryHandler(this, parent, name, ent.isDirectory() == false);
- entries.put(wrapper.getLocalPathName(), new EntryInfo(wrapper, ent));
- }
- }
- }
- finally
- {
- zipSource.release();
- }
- }
-
- /**
- * Get temp path.
- *
- * @param peer the peer vfs context
- * @param entryName the zip entry name
- * @return full temp path
- */
- protected String getPath(VFSContext peer, String entryName)
- {
- URI peerURI = peer.getRootURI();
- String peerString = VFSUtils.stripProtocol(peerURI);
- String thisString = VFSUtils.stripProtocol(getRootURI());
- return thisString.substring(peerString.length()) + entryName;
- }
-
- /**
- * Perform initialization only if it hasn't been done yet
- */
- private synchronized void ensureEntries()
- {
- if (initStatus != InitializationStatus.NOT_INITIALIZED)
- return;
-
- try
- {
- initStatus = InitializationStatus.INITIALIZING;
- initEntries();
- initStatus = InitializationStatus.INITIALIZED;
- }
- catch (Exception ex)
- {
- ExceptionHandler eh = getExceptionHandler();
- if (eh != null)
- eh.handleZipEntriesInitException(ex, getZipSource().getName());
- else
- throw new RuntimeException("Failed to read zip file: " + getZipSource(), ex);
- }
- finally
- {
- if (initStatus == InitializationStatus.INITIALIZING)
- initStatus = InitializationStatus.NOT_INITIALIZED;
- }
- }
-
- /**
- * Reset init status.
- */
- synchronized void resetInitStatus()
- {
- if (initStatus != InitializationStatus.NOT_INITIALIZED)
- {
- EntryInfo rootInfo = entries.get("");
- entries.clear();
- entries.put("", rootInfo);
-
- initStatus = InitializationStatus.NOT_INITIALIZED;
- }
- }
-
- /**
- * Mount ZipEntryContext created around extracted nested archive
- *
- * @param parent the parent
- * @param name the name
- * @param file the file
- * @return mounted delegate
- * @throws IOException for any error
- * @throws URISyntaxException for any URI syntax error
- */
- protected DelegatingHandler mountZipFile(VirtualFileHandler parent, String name, File file) throws IOException, URISyntaxException
- {
- DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
- URL fileUrl = file.toURI().toURL();
- URL delegatorUrl = fileUrl;
-
- if (parent != null)
- delegatorUrl = getChildURL(parent, name);
-
- delegatorUrl = setOptionsToURL(delegatorUrl);
- ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, fileUrl, true);
-
- VirtualFileHandler handler = ctx.getRoot();
- delegator.setDelegate(handler);
-
- return delegator;
- }
-
- /**
- * Mount ZipEntryContext created around ZipStreamWrapper
- *
- * @param parent the parent
- * @param name the name
- * @param zipStream the zip stream
- * @return mounted delegate
- * @throws IOException for any error
- * @throws URISyntaxException for any URI syntax error
- */
- protected DelegatingHandler mountZipStream(VirtualFileHandler parent, String name, InputStream zipStream) throws IOException, URISyntaxException
- {
- DelegatingHandler delegator = new DelegatingHandler(this, parent, name);
- ZipStreamWrapper wrapper = new ZipStreamWrapper(zipStream, name, parent.getLastModified());
-
- URL delegatorUrl = null;
-
- if (parent != null)
- delegatorUrl = getChildURL(parent, name);
-
- delegatorUrl = setOptionsToURL(delegatorUrl);
- ZipEntryContext ctx = new ZipEntryContext(delegatorUrl, delegator, wrapper, false);
-
- VirtualFileHandler handler = ctx.getRoot();
- delegator.setDelegate(handler);
-
- return delegator;
- }
-
- /**
- * Zip archives sometimes don't contain directory entries - only leaf entries
- *
- * @param parentPath the parent path
- * @return entry info
- * @throws IOException for any error
- */
- private EntryInfo makeDummyParent(String parentPath) throws IOException
- {
- // get grand parent first
- String [] split = splitParentChild(parentPath);
- String grandPa = split[0];
-
- EntryInfo eiParent = entries.get(grandPa);
- if(eiParent == null)
- eiParent = makeDummyParent(grandPa);
-
- ZipEntryHandler handler = new ZipEntryHandler(this, eiParent.handler, split[1], false);
- EntryInfo ei = new EntryInfo(handler, null);
- entries.put(parentPath, ei);
- return ei;
- }
-
- /**
- * Initialize rootEntryPath and return archive file path
- *
- * @param localRootUrl local root url
- * @return file path
- */
- private String initRootAndPath(URL localRootUrl)
- {
- String filePath = localRootUrl.toString();
- String zipPath = filePath;
-
- int pos = filePath.indexOf("!");
- if(pos > 0)
- {
- zipPath = filePath.substring(0, pos);
- rootEntryPath = filePath.substring(pos+2);
- if(rootEntryPath.length() != 0)
- rootEntryPath += "/";
- }
-
- // find where url protocol ends - i.e. jar:file:/ ...
- pos= zipPath.indexOf(":/");
- filePath = zipPath.substring(pos + 1);
-
- // cut out url query part if present
- int queryStart = filePath.indexOf("?");
- if (queryStart != -1)
- filePath = filePath.substring(0, queryStart);
-
- return filePath;
- }
-
- /**
- * If archive has been modified, clear <em>entries</em> and re-initialize.
- * If not initialized yet, initialize it.
- */
- private synchronized void checkIfModified()
- {
- // TODO: if zipSource represents a nested archive we should maybe delegate lastModified to its parent
- if (initStatus == InitializationStatus.NOT_INITIALIZED)
- {
- ensureEntries();
- }
- else if (initStatus == InitializationStatus.INITIALIZED && getZipSource().hasBeenModified())
- {
- EntryInfo rootInfo = entries.get("");
- entries.clear();
- entries.put("", rootInfo);
-
- if (getZipSource().exists())
- {
- try
- {
- initEntries();
- }
- catch(Exception ignored)
- {
- log.warn("IGNORING: Failed to reinitialize context: " + getRootURI(), ignored);
- }
- }
- }
- }
-
- /**
- * Returns this context's root
- *
- * @return root handler
- */
- public VirtualFileHandler getRoot()
- {
- return entries.get("").handler;
- }
-
- /**
- * Find a child with a given name and a given parent
- *
- * @param parent parent handler
- * @param name name of the child
- * @return child handler or null if not found
- */
- VirtualFileHandler getChild(ZipEntryHandler parent, String name)
- {
- if (parent == null)
- throw new IllegalArgumentException("Null parent");
-
- checkIfModified();
-
- String pathName = parent.getLocalPathName();
- if("".equals(pathName))
- pathName = name;
- else
- pathName = pathName + "/" + name;
-
- EntryInfo ei = entries.get(pathName);
- if(ei != null)
- return ei.handler;
-
- return null;
- }
-
- /**
- * Returns a list of children for a given parent
- *
- * @param parent parent handler
- * @param ignoreErrors true if errors should be silently ignored
- * @return list of handlers representing children of the given parent
- * @throws IOException for any error
- */
- public List<VirtualFileHandler> getChildren(VirtualFileHandler parent, boolean ignoreErrors) throws IOException
- {
- if (parent == null)
- throw new IllegalArgumentException("Null parent");
-
- checkIfModified();
- if(parent instanceof AbstractVirtualFileHandler)
- {
- AbstractVirtualFileHandler parentHandler = (AbstractVirtualFileHandler) parent;
- EntryInfo parentEntry = entries.get(parentHandler.getLocalPathName());
- if (parentEntry != null)
- {
- if (parentEntry.handler instanceof DelegatingHandler)
- return parentEntry.handler.getChildren(ignoreErrors);
-
- return parentEntry.getChildren();
- }
- }
- return Collections.emptyList();
- }
-
- /**
- * Do delete.
- *
- * @param handler the zip entry handler
- * @param gracePeriod the grace period
- * @return true if delete succeeded
- * @throws IOException for any error
- */
- boolean delete(ZipEntryHandler handler, int gracePeriod) throws IOException
- {
- return getRoot().equals(handler) && getZipSource().delete(gracePeriod);
- }
-
- /**
- * Close the handler, if it's root.
- *
- * @param handler the handler to close
- */
- void cleanup(ZipEntryHandler handler)
- {
- VirtualFileHandler rootHandler = getRoot();
- if (rootHandler.equals(handler))
- {
- getZipSource().close(); // close == cleanup in zip source impl
- }
- }
-
- /**
- * Returns lastModified timestamp for a given handler
- *
- * @param handler a handler
- * @return lastModified timestamp
- */
- long getLastModified(ZipEntryHandler handler)
- {
- if (handler == null)
- throw new IllegalArgumentException("Null handler");
-
- if (getRoot().equals(handler) == false)
- checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
- if(ei == null)
- return 0;
-
- if(ei.entry == null) {
- return getZipSource().getLastModified();
- }
-
- return ei.entry.getTime();
- }
-
- /**
- * Returns the size for a given handler
- *
- * @param handler a handler
- * @return size in bytes
- */
- long getSize(ZipEntryHandler handler)
- {
- if (handler == null)
- throw new IllegalArgumentException("Null handler");
-
- if(getRoot().equals(handler))
- return getZipSource().getSize();
-
- checkIfModified();
-
- EntryInfo ei = entries.get(handler.getLocalPathName());
- if(ei == null || ei.entry == null)
- return 0;
-
- return ei.entry.getSize();
- }
-
- /**
- * Returns true if entry exists for a given handler
- *
- * @param handler a handler
- * @return true if entry exists
- */
- boolean exists(ZipEntryHandler handler)
- {
- if (handler == null)
- throw new IllegalArgumentException("Null handler");
-
- if (getRoot().equals(handler))
- return getZipSource().exists();
-
- checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
- return ei != null;
- }
-
- /**
- * Returns true if handler represents a non-directory entry
- *
- * @param handler the handler
- * @return true if not a directory
- */
- boolean isLeaf(ZipEntryHandler handler)
- {
- if (handler == null)
- throw new IllegalArgumentException("Null handler");
-
- if (getRoot().equals(handler) == false)
- checkIfModified();
-
- EntryInfo ei = entries.get(handler.getLocalPathName());
- if (ei == null || ei.entry == null)
- return false;
-
- return ei.entry.isDirectory() == false;
- }
-
- /**
- * Is the handler archive.
- *
- * @param handler the handler
- * @return true if archive, false otherwise
- */
- boolean isArchive(ZipEntryHandler handler)
- {
- return getRoot().equals(handler);
- }
-
- /**
- * Is archive.
- *
- * @param handler the handler
- * @return true if archive
- */
- static boolean isArchive(VirtualFileHandler handler)
- {
- if (handler instanceof ZipEntryHandler && "".equals(handler.getLocalPathName()))
- {
- return true;
- }
-
- if (handler instanceof DelegatingHandler && ((DelegatingHandler) handler).getDelegate() instanceof ZipEntryHandler)
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Get parent.
- *
- * @param handler the handler to check
- * @return parent handler
- * @throws IOException for any error
- */
- static VirtualFileHandler getParent(VirtualFileHandler handler) throws IOException
- {
- VirtualFileHandler parent = handler.getParent();
- if (parent == null)
- {
- VirtualFileHandler peer = handler.getVFSContext().getRootPeer();
- if (peer != null)
- parent = peer.getParent();
- }
- return parent;
- }
-
- /**
- * Is nested.
- *
- * @param handler the handler
- * @return true if nested
- * @throws IOException for any error
- */
- static boolean isNested(VirtualFileHandler handler) throws IOException
- {
- VirtualFileHandler parent = getParent(handler);
- while (parent != null)
- {
- if(isArchive(parent))
- return true;
-
- parent = getParent(parent);
- }
- return false;
- }
-
- /**
- * Contents of the file represented by a given handler
- *
- * @param handler a handler
- * @return InputStream with entry's content
- * @throws IOException for any error
- */
- InputStream openStream(ZipEntryHandler handler) throws IOException
- {
- if (handler == null)
- throw new IllegalArgumentException("Null handler");
-
- if (getRoot().equals(handler))
- return getZipSource().getRootAsStream();
-
- checkIfModified();
-
- EntryInfo ei = entries.get(handler.getLocalPathName());
-
- if (ei == null)
- {
- String uriStr;
- try
- {
- uriStr = handler.toURI().toString();
- }
- catch(Exception ex)
- {
- throw new RuntimeException("ASSERTION ERROR - uri generation failed for ZipEntryHandler: " + handler, ex);
- }
- throw new FileNotFoundException(uriStr);
- }
-
- if(ei.entry == null)
- return new ByteArrayInputStream(NO_BYTES);
-
- return getZipSource().openStream(ei.entry);
- }
-
- /**
- * Add a child to a given parent
- *
- * @param parent a parent
- * @param child a child
- */
- void addChild(AbstractVirtualFileHandler parent, AbstractVirtualFileHandler child)
- {
- if (parent == null)
- throw new IllegalArgumentException("Null parent");
-
- if (child == null)
- throw new IllegalArgumentException("Null child");
-
- EntryInfo parentEntry = entries.get(parent.getLocalPathName());
- if (parentEntry != null)
- parentEntry.add(child);
- else
- throw new RuntimeException("Parent does not exist: " + parent);
- }
-
- /**
- * Properly release held resources
- */
- protected void finalize() throws Throwable
- {
- try
- {
- if (zipSource != null)
- zipSource.close();
- }
- catch (Throwable ignored)
- {
- log.debug("IGNORING: Failed to close zip source: " + zipSource, ignored);
- }
- super.finalize();
- }
-
- /**
- * Replace a current child of the given parent with another one
- *
- * @param parent a parent
- * @param original current child
- * @param replacement new child
- */
- void replaceChild(ZipEntryHandler parent, AbstractVirtualFileHandler original, VirtualFileHandler replacement)
- {
- ensureEntries();
- EntryInfo parentEntry = entries.get(parent.getLocalPathName());
- if (parentEntry != null)
- {
- DelegatingHandler newOne;
-
- if (replacement instanceof DelegatingHandler)
- {
- newOne = (DelegatingHandler) replacement;
- }
- else
- {
- newOne = new ReplacementHandler(this, parent, original.getName(), replacement);
- }
-
- synchronized(this)
- {
- parentEntry.replaceChild(original, newOne);
-
- EntryInfo ei = entries.get(original.getLocalPathName());
- ei.handler = newOne;
- ei.entry = null;
- ei.clearChildren();
- }
- }
- else
- {
- throw new RuntimeException("Parent does not exist: " + parent);
- }
- }
-
- /**
- * Get RealURL corresponding to root handler
- *
- * @return the real url
- */
- URL getRealURL()
- {
- // make sure realURL has been initialized
- // realURL is initialized when ZipSource is initialized
- getZipSource();
- return realURL;
- }
-
- /**
- * Internal data structure holding meta information of a virtual file in this context
- */
- static class EntryInfo
- {
- /** a handler */
- private AbstractVirtualFileHandler handler;
-
- /** a <tt>ZipEntry</tt> */
- private ZipEntry entry;
-
- /** a list of children */
- private Map<String, AbstractVirtualFileHandler> children;
-
- /**
- * EntryInfo constructor
- *
- * @param handler a handler
- * @param entry an entry
- */
- EntryInfo(AbstractVirtualFileHandler handler, ZipEntry entry)
- {
- this.handler = handler;
- this.entry = entry;
- }
-
- /**
- * Get children.
- *
- * @return returns a list of children for this handler (by copy)
- */
- public synchronized List<VirtualFileHandler> getChildren()
- {
- if (children == null)
- return Collections.emptyList();
-
- return new ArrayList<VirtualFileHandler>(children.values());
- }
-
- /**
- * Replace a child.
- *
- * @param original existing child
- * @param replacement new child
- */
- public synchronized void replaceChild(AbstractVirtualFileHandler original, AbstractVirtualFileHandler replacement)
- {
- if (children != null)
- {
- final String name = original.getName();
- if (children.containsKey(name)) {
- children.put(name, replacement);
- }
- }
- }
-
- /**
- * Clear the list of children
- */
- public synchronized void clearChildren()
- {
- if (children != null)
- children.clear();
- }
-
- /**
- * Add a child. If a child with the same name exists already, first remove it.
- *
- * @param child a child
- */
- public synchronized void add(AbstractVirtualFileHandler child)
- {
- if (children == null)
- {
- children = new LinkedHashMap<String, AbstractVirtualFileHandler>();
- }
- children.put(child.getName(), child);
- }
- }
-
- /**
- * Make sure url protocol is <em>vfszip</em>.
- * Also remove any '!' from URL
- *
- * @param rootURL the root url
- * @return fixed url
- * @throws MalformedURLException for any error
- */
- private static URL fixUrl(URL rootURL) throws MalformedURLException
- {
- String urlStr = rootURL.toExternalForm();
- int pos = urlStr.indexOf("!");
- if (pos != -1)
- {
- String tmp = urlStr.substring(0, pos);
- if (pos < urlStr.length()-1)
- tmp += urlStr.substring(pos+1);
- urlStr = tmp;
- }
- if ("vfszip".equals(rootURL.getProtocol()) == false)
- {
- pos = urlStr.indexOf(":/");
- if (pos != -1)
- urlStr = urlStr.substring(pos);
-
- return new URL("vfszip" + urlStr);
- }
- return rootURL;
- }
-
- /**
- * Break to path + name
- *
- * @param pathName the path name
- * @return path tokens
- */
- public static String [] splitParentChild(String pathName)
- {
- if (pathName.startsWith("/"))
- pathName = pathName.substring(1);
-
- if(pathName.length() == 0)
- return new String [] {null, pathName};
-
- int toPos = pathName.length();
- if(pathName.charAt(pathName.length()-1) == '/')
- toPos --;
-
- int delimPos = pathName.lastIndexOf('/', toPos-1);
-
- String [] ret;
- if(delimPos == -1)
- {
- ret = new String []
- {
- "",
- pathName.substring(delimPos+1, toPos)
- };
- }
- else
- {
- ret = new String []
- {
- pathName.substring(0, delimPos),
- pathName.substring(delimPos+1, toPos)
- };
- }
- return ret;
- }
-
- /**
- * Temporary files naming scheme
- *
- * @param name the name
- * @return random name
- */
- private static String getTempFileName(String name)
- {
- int delim = name.lastIndexOf("/");
- if (delim != -1)
- name = name.substring(delim+1);
- return UUID.randomUUID().toString().substring(0, 8) + "_" + name;
- }
-
- /**
- * Use VFS's temp directory and make 'vfs-nested.tmp' sub-directory inside it for our purposes
- *
- * @return temp dir
- */
- private static String getTempDir()
- {
- File dir = new File(AbstractCopyMechanism.getTempDirectory(), "vfs-nested.tmp");
- return dir.toString();
- }
-
- /**
- * Delete the contents of a temporary directory. Delete first-level files only, don't drill down.
- */
- private static void deleteTmpDirContents()
- {
- try
- {
- File tmpDir = new File(getTempDir());
- File [] files = tmpDir.listFiles();
- if (files != null && files.length > 0)
- {
- for (File file : files)
- {
- if (file.isDirectory() == false && file.isHidden() == false)
- file.delete();
- }
- }
- }
- catch(Exception ignored)
- {
- }
- }
-
- /**
- * <tt>PriviligedAction</tt> class for checking a system property
- */
- private static class CheckForceCopy implements PrivilegedAction<Boolean>
- {
- public Boolean run()
- {
- String forceString = System.getProperty(VFSUtils.FORCE_COPY_KEY, "false");
- return Boolean.valueOf(forceString);
- }
- }
-
- static enum InitializationStatus
- {
- NOT_INITIALIZED,
- INITIALIZING,
- INITIALIZED
- }
-
- private static class RealURLInfo
- {
- String rootURL;
- String relativePath;
-
- RealURLInfo(File file) throws MalformedURLException
- {
- String url = file.toURI().toURL().toExternalForm();
- if (url.endsWith("/"))
- url = url.substring(0, url.length()-1);
- rootURL = "jar:" + url + "!/";
- }
-
- URL toURL() throws MalformedURLException
- {
- if (relativePath == null || relativePath.length() == 0)
- return new URL(rootURL);
-
- if (relativePath.startsWith("/"))
- relativePath = relativePath.substring(1);
-
- return new URL(rootURL + relativePath);
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextFactory.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,88 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import org.jboss.virtual.plugins.context.AbstractContextFactory;
-import org.jboss.virtual.spi.VFSContext;
-
-/**
- * ContextFactory that keeps track of ZipEntryContexts
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-public class ZipEntryContextFactory extends AbstractContextFactory
-{
- /** singleton */
- private static ZipEntryContextFactory instance = new ZipEntryContextFactory();
-
- /**
- * ZipEntryContextFactory registers two url protocols: <em>zip</em> and <em>vfszip</em>
- */
- public ZipEntryContextFactory()
- {
- super("zip", "vfszip"); // "jar", "vfsjar",
- }
-
- /**
- * Get a <tt>VFSContext</tt> for a given <tt>URL</tt>
- */
- public VFSContext getVFS(URI rootURI) throws IOException
- {
- return getVFS(rootURI.toURL());
- }
-
- /**
- * Create a new <tt>ZipEntryContext</tt>.
- *
- * @param rootURL the root url
- * @return new zip context
- * @throws IOException for any error
- */
- public VFSContext getVFS(URL rootURL) throws IOException
- {
- try
- {
- return new ZipEntryContext(rootURL);
- }
- catch(URISyntaxException ex)
- {
- MalformedURLException e = new MalformedURLException("Failed to convert URL to URI: " + rootURL);
- e.initCause(ex);
- throw e;
- }
- }
-
- /**
- * Get a reference to <tt>ZipEntryContextFactory</tt>.
- */
- public static ZipEntryContextFactory getInstance()
- {
- return instance;
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,268 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
-import org.jboss.virtual.plugins.context.file.FileSystemContext;
-import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler;
-import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * Handler representing an individual file (ZipEntry) within ZipEntryContext
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-public class ZipEntryHandler extends AbstractVirtualFileHandler implements StructuredVirtualFileHandler
-{
- /** The url */
- private URL url;
-
- /** isLeaf */
- private boolean isLeaf;
-
- /** has it been initialized yet */
- transient private boolean initialized;
-
- /**
- * Create a new ZipEntryHandler.
- *
- * @param context ZipEntryContext
- * @param parent parent within the same context
- * @param name name of this file within context
- * @param isLeaf true if this file should have a URL not ending with '/', false otherwise
- * @throws IOException for any error
- */
- public ZipEntryHandler(ZipEntryContext context, AbstractVirtualFileHandler parent, String name, boolean isLeaf) throws IOException
- {
- super(context, parent, name);
-
- this.isLeaf = isLeaf;
- if(parent != null)
- {
- context.addChild(parent, this);
- }
- }
-
- /**
- * Initialization method.
- */
- private synchronized void init()
- {
- if (initialized)
- return;
-
- StringBuilder vfsUrl = new StringBuilder();
- try
- {
- url = getZipEntryContext().getChildURL(getParent(), getName());
- String currentUrl = url.toString();
- int pos = currentUrl.indexOf(":/");
- vfsUrl.append("vfszip:").append(currentUrl.substring(pos+1));
-
- if (isLeaf == false && vfsUrl.charAt(vfsUrl.length()-1) != '/')
- vfsUrl.append("/");
- setVfsUrl(new URL(vfsUrl.toString()));
- }
- catch(Exception ex)
- {
- throw new RuntimeException("ASSERTION ERROR - failed to set vfsUrl: " + vfsUrl, ex );
- }
- initialized = true;
- }
-
- public URI toURI() throws URISyntaxException
- {
- init();
- return VFSUtils.toURI(url);
- }
-
- public long getLastModified() throws IOException
- {
- checkClosed();
- return getZipEntryContext().getLastModified(this);
- }
-
- public long getSize() throws IOException
- {
- checkClosed();
- return getZipEntryContext().getSize(this);
- }
-
- public boolean exists() throws IOException
- {
- checkClosed();
- return getZipEntryContext().exists(this);
- }
-
- public boolean isLeaf() throws IOException
- {
- checkClosed();
- return getZipEntryContext().isLeaf(this);
- }
-
- @Override
- public boolean isArchive() throws IOException
- {
- checkClosed();
- return getZipEntryContext().isArchive(this);
- }
-
- public boolean isHidden() throws IOException
- {
- checkClosed();
- return false;
- }
-
- public boolean isNested() throws IOException
- {
- return ZipEntryContext.isNested(this);
- }
-
- public InputStream openStream() throws IOException
- {
- checkClosed();
- return getZipEntryContext().openStream(this);
- }
-
- public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
- {
- checkClosed();
- return getZipEntryContext().getChildren(this, ignoreErrors);
- }
-
- public VirtualFileHandler getChild(String path) throws IOException
- {
- checkClosed();
- return structuredFindChild(path);
- }
-
- public boolean removeChild(String name) throws IOException
- {
- return false;
- }
-
- @Override
- public void cleanup()
- {
- getZipEntryContext().cleanup(this);
- }
-
- public boolean delete(int gracePeriod) throws IOException
- {
- checkClosed();
- boolean deleted = getZipEntryContext().delete(this, gracePeriod);
- if (deleted)
- super.delete(gracePeriod);
-
- return deleted;
- }
-
- public VirtualFileHandler createChildHandler(String name) throws IOException
- {
- return getZipEntryContext().getChild(this, name);
- }
-
- protected void internalReplaceChild(VirtualFileHandler original, VirtualFileHandler replacement)
- {
- if (original instanceof AbstractVirtualFileHandler == false)
- throw new IllegalArgumentException("Original file handler not found in this context: " + original);
-
- getZipEntryContext().replaceChild(this, (AbstractVirtualFileHandler) original, replacement);
- }
-
- /**
- * Get owner zip entry context.
- *
- * @return the owner zip entry context
- */
- private ZipEntryContext getZipEntryContext()
- {
- return ((ZipEntryContext) getLocalVFSContext());
- }
-
- protected URL toInternalVfsUrl()
- {
- init();
- return super.getVfsUrl();
- }
-
- public URL getRealURL() throws IOException, URISyntaxException
- {
- // see how far the parent contexts go
- // if there is no parent context or it is of type FileSystemContext
- // ZipEntryContext -> jar!/
- // ZipEntryContext / ZipEntryContext -> jar!/jar
- // ZipEntryConteyt / ZipEntryContext / ZipEntryContext ... -> jar!/jar
- VFSContext ctx = getLocalVFSContext();
- VirtualFileHandler peer = getLocalVFSContext().getRootPeer();
-
- if (peer == null)
- {
- URL ctxURL = getZipEntryContext().getRealURL();
- String ctxURLStr = ctxURL.toExternalForm();
- if (ctxURLStr.endsWith("!/"))
- {
- String lpath = getLocalPathName();
- if (lpath.startsWith("/"))
- lpath = lpath.substring(1);
-
- if (lpath.length() == 0)
- return ctxURL;
- else
- return new URL(ctxURLStr + lpath);
- }
- return ctxURL;
- }
-
- if (peer instanceof AbstractVirtualFileHandler
- && ((AbstractVirtualFileHandler)peer).getLocalVFSContext() instanceof FileSystemContext)
- {
- String lpath = getLocalPathName();
- if (lpath.startsWith("/") == false)
- lpath = "/" + lpath;
- return new URL("jar:file:" + ctx.getRootURI().getPath() + "!" + lpath);
- }
-
- if (peer instanceof AbstractVirtualFileHandler)
- {
- AbstractVirtualFileHandler aPeer =(AbstractVirtualFileHandler) peer;
- URL realUrl = aPeer.getLocalVFSContext().getRoot().getRealURL();
- String urlStr = realUrl.toExternalForm();
- if (urlStr.endsWith("!/"))
- return new URL(urlStr + aPeer.getLocalPathName());
- else
- return realUrl;
- }
-
- throw new RuntimeException("Operation not supported for handler: " + this);
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,271 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.jboss.virtual.VFSUtils;
-
-/**
- * ZipEntryInputStream is part of ZipFileWrapper implementation.
- *
- * It wraps the stream retrieved from ZipFile.getInputStream(entry)
- * and releases the underlying ZipFileWrapper when detecting end of use.
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- * @version $Revision: 1.0 $
- */
-public class ZipEntryInputStream extends InputStream
-{
- /** Underlying input stream */
- private InputStream delegate;
-
- /** Underlying zip source */
- private ZipFileWrapper zipWrapper;
-
- /** Is stream released */
- private volatile boolean released;
-
- /** Is stream delegate closed */
- private volatile boolean closed;
-
- /**
- * ZipEntryInputStream constructor.
- *
- * @param zipWrapper underlying zip source
- * @param is underlying input stream
- * @throws IOException for any error
- * @throws IllegalArgumentException if insput stream is null
- */
- ZipEntryInputStream(ZipFileWrapper zipWrapper, InputStream is) throws IOException
- {
- if (is == null)
- throw new IllegalArgumentException("Input stream is null");
-
- this.zipWrapper = zipWrapper;
- delegate = is;
- }
-
- /**
- * Release this stream and release zipWrapper
- *
- * @param doRelease should we release
- */
- private void streamReleased(boolean doRelease)
- {
- if (released == false && doRelease)
- {
- released = true;
- zipWrapper.release();
- }
- }
-
- /**
- * Read one byte.
- *
- * @return whatever the underlying input stream returns
- * @throws IOException for any error
- * @see java.io.InputStream#read
- */
- public int read() throws IOException
- {
- int rc = -1;
- try
- {
- rc = delegate.read();
- return rc;
- }
- finally
- {
- streamReleased(rc < 0);
- }
- }
-
- /**
- * Read a buffer of bytes.
- *
- * @param buf read buffer
- * @return whatever the underlying input stream returns
- *
- * @throws IOException for any error
- * @see java.io.InputStream#read(byte[])
- */
- public int read(byte buf[]) throws IOException
- {
- int rc = -1;
- try
- {
- rc = delegate.read(buf);
- return rc;
- }
- finally
- {
- streamReleased(rc < 0);
- }
- }
-
- /**
- * Read a buffer of bytes.
- *
- * @param buf read buffer
- * @param off position within buffer to start reading at
- * @param len maximum bytes to read
- * @return whatever the underlying input stream returns
- * @throws IOException for any error
- * @see java.io.InputStream#read(byte[],int,int)
- */
- public int read(byte buf[], int off, int len) throws IOException
- {
- int rc = -1;
- try
- {
- rc = delegate.read(buf, off, len);
- return rc;
- }
- finally
- {
- streamReleased(rc < 0);
- }
- }
-
- /**
- * @see java.io.InputStream#reset
- */
- public synchronized void reset() throws IOException
- {
- boolean ok = false;
- try
- {
- delegate.reset();
- ok = true;
- }
- finally
- {
- streamReleased(ok == false);
- }
- }
-
- /**
- * @see java.io.InputStream#mark
- */
- public synchronized void mark(int readlimit)
- {
- boolean ok = false;
- try
- {
- delegate.mark(readlimit);
- ok = true;
- }
- finally
- {
- streamReleased(ok == false);
- }
- }
-
- /**
- * @see java.io.InputStream#available
- */
- public int available() throws IOException
- {
- boolean ok = false;
- try
- {
- int ret = delegate.available();
- ok = true;
- return ret;
- }
- finally
- {
- streamReleased(ok == false);
- }
- }
-
- /**
- * @see java.io.InputStream#skip
- */
- public long skip(long n) throws IOException
- {
- boolean ok = false;
- try
- {
- long ret = delegate.skip(n);
- ok = true;
- return ret;
- }
- finally
- {
- streamReleased(ok == false);
- }
- }
-
- /**
- * Close this stream and release zipWrapper
- *
- * @see java.io.InputStream#close
- */
- public void close() throws IOException
- {
- try
- {
- streamReleased(true);
- }
- finally
- {
- if (closed == false)
- {
- closed = true;
- VFSUtils.safeClose(delegate);
- }
- }
- }
-
- /**
- * Properly release held resources
- */
- protected void finalize() throws Throwable
- {
- VFSUtils.safeClose(this);
- super.finalize();
- }
-
- /**
- * isReleased.
- *
- * @return returns true if released
- */
- boolean isReleased()
- {
- return released;
- }
-
- /**
- * isClosed.
- *
- * @return returns true if closed
- */
- boolean isClosed()
- {
- return closed;
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryTempInfo.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,59 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.File;
-
-import org.jboss.virtual.plugins.context.temp.BasicTempInfo;
-import org.jboss.virtual.spi.VirtualFileHandler;
-
-/**
- * ZipEntry temp info.
- * It resets initState of owning zip context.
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-public class ZipEntryTempInfo extends BasicTempInfo
-{
- private volatile ZipEntryContext context;
-
- public ZipEntryTempInfo(String path, File file, VirtualFileHandler handler, ZipEntryContext context)
- {
- super(path, file, handler);
- this.context = context;
- }
-
- @Override
- public void cleanup()
- {
- context.resetInitStatus();
- context = null; // release
-
- super.cleanup();
- }
-
- @Override
- public boolean isValid()
- {
- return context != null && super.isValid();
- }
-}
\ No newline at end of file
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,78 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Enumeration;
-
-import org.jboss.virtual.spi.zip.ZipEntry;
-
-/**
- * ZipEntryWrapper - for abstracted access to in-memory entry
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-class ZipEntryWrapper extends ZipBytesWrapper
-{
- private static final EmptyEnumeration emptyEnumeration = new EmptyEnumeration();
-
- /**
- * ZipStreamWrapper is not aware of actual zip source so it can not detect
- * if it's been modified, like ZipFileWrapper does.
- *
- * @param zipStream the current zip input stream
- * @param name the name
- * @param lastModified passed by zip stream provider - constant value
- * @throws java.io.IOException for any error
- */
- ZipEntryWrapper(InputStream zipStream, String name, long lastModified) throws IOException
- {
- super(zipStream, name, lastModified);
- }
-
- InputStream openStream(ZipEntry ent) throws IOException
- {
- return getRootAsStream();
- }
-
- Enumeration<? extends ZipEntry> entries() throws IOException
- {
- return emptyEnumeration;
- }
-
- /**
- * Zip stream enumeration.
- */
- private static class EmptyEnumeration implements Enumeration<ZipEntry>
- {
- public boolean hasMoreElements()
- {
- return false;
- }
-
- public ZipEntry nextElement()
- {
- return null;
- }
- }
-}
\ No newline at end of file
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileLockReaper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileLockReaper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileLockReaper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,192 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.util.Iterator;
-import java.util.Queue;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.io.IOException;
-
-import org.jboss.logging.Logger;
-
-/**
- * A monitoring object that closes ZipFiles when they haven't been used for a while
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-public class ZipFileLockReaper
-{
- /** Logger */
- private static final Logger log = Logger.getLogger(ZipFileLockReaper.class);
-
- /**
- * Time after which unused ZipFiles can be closed. This shouldn't be a large number
- * to ensure smooth releasing of file locks
- */
- private static final int PERIOD = 5000;
-
- /** Timer thread period */
- private static final int TIMER_PERIOD = 1000;
-
- /** If timer finds out there haven't been any ZipFiles open for a while it shuts down until some are (re)opened */
- private static final int TIMER_UNUSED_PERIOD = 30000;
-
- /** There is only one instance that serves all ZipFileWrappers */
- private static ZipFileLockReaper singleton;
-
- /** A list of monitored ZipFileWrappers */
- private Queue<ZipFileWrapper> monitored = new ConcurrentLinkedQueue<ZipFileWrapper>();
-
- /** The number of monitored ZipFileWrappers */
- private int monitoredCount = 0;
-
- /** Timer used for actual reaping - async closure of ZipFiles */
- private Timer timer;
-
- /** Timestamp of last unregister() call */
- private long lastUsed;
-
- /**
- * Private constructor - to force retrieval through {@link #getInstance()}
- */
- private ZipFileLockReaper()
- {
- }
-
- /** Factory method to be used to retrieve reference to ZipFileLockReaper */
- public synchronized static ZipFileLockReaper getInstance()
- {
- if (singleton == null)
- singleton = new ZipFileLockReaper();
-
- return singleton;
- }
-
- /**
- * Register a ZipFileWrapper instance with this reaper
- *
- * @param w wrapper to register
- */
- public synchronized void register(ZipFileWrapper w)
- {
- monitored.add(w);
- monitoredCount++;
- if (timer == null)
- {
- timer = new Timer("ZipFile Lock Reaper", true);
- timer.schedule(new ReaperTimerTask(), TIMER_PERIOD, TIMER_PERIOD);
- }
- if (log.isTraceEnabled())
- log.trace("Registered: " + w);
- }
-
- /**
- * Unregister a ZipFileWrapper instance from this reaper
- *
- * @param w wrapper to unregister
- */
- public synchronized void unregister(ZipFileWrapper w)
- {
- monitored.remove(w);
- monitoredCount--;
- lastUsed = System.currentTimeMillis();
- if (log.isTraceEnabled())
- log.trace("Unregistered: " + w);
- }
-
- public void deleteFile(ZipFileWrapper zipFileWrapper) throws IOException
- {
- synchronized (ZipFileLockReaper.this)
- {
- Iterator it = monitored.iterator();
- while (it.hasNext())
- {
- ZipFileWrapper w = (ZipFileWrapper) it.next();
- w.deleteFile(zipFileWrapper);
- }
- }
- }
-
- /** Timer task that does the actual reaping */
- class ReaperTimerTask extends TimerTask
- {
- public void run()
- {
- boolean trace = log.isTraceEnabled();
-
- if (trace)
- log.trace("Timer called");
-
- long now = System.currentTimeMillis();
- synchronized (ZipFileLockReaper.this)
- {
- if (monitoredCount == 0)
- {
- if (now - lastUsed > TIMER_UNUSED_PERIOD)
- {
- timer.cancel();
- timer = null;
- if (trace)
- log.trace("Cancelled the timer");
- }
- return;
- }
- }
-
- Iterator it = monitored.iterator();
- while (it.hasNext())
- {
- ZipFileWrapper w = (ZipFileWrapper) it.next();
-
- // stream leak debug
- /*
- Iterator<ZipEntryInputStream> sit = w.streams.iterator();
- while (sit.hasNext())
- {
- ZipEntryInputStream eis = sit.next();
- if (!eis.isClosed())
- {
- System.out.println("Stream not closed: " + eis.debugCount + " - " + eis);
- }
- }
- */
-
- if (w.getReferenceCount() <= 0 && now - w.getLastUsed() > PERIOD)
- {
- try
- {
- w.closeZipFile();
- if (log.isTraceEnabled())
- log.trace("Asynchronously closed an unused ZipFile: " + w);
- }
- catch(Exception ignored)
- {
- log.debug("IGNORING: Failed to close ZipFile: " + w, ignored);
- }
- }
- }
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,409 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Enumeration;
-import java.util.zip.ZipOutputStream;
-
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.spi.zip.ZipEntry;
-import org.jboss.virtual.spi.zip.ZipFile;
-import org.jboss.virtual.spi.zip.ZipUtils;
-import org.jboss.virtual.spi.zip.ZipFactory;
-
-/**
- * ZipFileWrapper - for abstracted access to zip files on disk
- *
- * It releases and reacquires the underlying ZipFile as necessary
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-class ZipFileWrapper extends ZipWrapper
-{
- /** Logger */
- private static final Logger log = Logger.getLogger(ZipFileWrapper.class);
-
- /** Is forceNoReaper enabled */
- private static boolean forceNoReaper;
-
- static
- {
- forceNoReaper = AccessController.doPrivileged(new CheckNoReaper());
-
- if (forceNoReaper)
- log.info("VFS forced no-reaper-mode is enabled.");
- }
-
- /** Underlying zip archive file */
- private File file;
-
- /** Zip inflater wrapped around file */
- private ZipFile zipFile;
-
- /** autoClean flag - true for extracted nested jars that we want removed when this wrapper is closed */
- private boolean autoClean;
-
- /** true if noReaper mode is forced on a per-instance basis */
- private boolean noReaperOverride;
-
- // used for debugging stream leaks
- //ConcurrentLinkedQueue<ZipEntryInputStream> streams = new ConcurrentLinkedQueue<ZipEntryInputStream>();
-
- /**
- * ZipFileWrapper
- *
- * @param archive file to the archive
- * @param autoClean should archive be deleted after use
- * @param noReaperOverride flag to specify if reaper be used or not
- */
- ZipFileWrapper(File archive, boolean autoClean, boolean noReaperOverride)
- {
- this.noReaperOverride = noReaperOverride;
- init(archive, autoClean);
- }
-
- /**
- * ZipFileWrapper
- *
- * @param rootPathURI URI to the archive - will be passed to File constructor as-is
- * @param autoClean should archive be deleted after use
- * @param noReaperOverride flag to specify if reaper be used or not
- */
- ZipFileWrapper(URI rootPathURI, boolean autoClean, boolean noReaperOverride)
- {
- this.noReaperOverride = noReaperOverride;
- File rootFile = new File(rootPathURI);
- if(rootFile.isFile() == false)
- throw new RuntimeException("File not found: " + rootFile);
-
- init(rootFile, autoClean);
- }
-
- /**
- * Extra initialization in addition to what's in constructors
- *
- * @param archive the archive file
- * @param autoClean auto clean flag
- */
- private void init(File archive, boolean autoClean)
- {
- file = archive;
- lastModified = file.lastModified();
- this.autoClean = autoClean;
- if (autoClean)
- file.deleteOnExit();
- }
-
- /**
- * Check if archive exists
- *
- * @return true if file exists on disk
- */
- boolean exists()
- {
- return file.isFile();
- }
-
- /**
- * Get lastModified for the archive
- *
- * @return lastModified timestamp of the file on disk
- */
- long getLastModified()
- {
- return file.lastModified();
- }
-
- /**
- * Get the name of the archive
- *
- * @return name of the file on disk
- */
- String getName()
- {
- return file.getName();
- }
-
- /**
- * Get the size of the archive
- *
- * @return size of the file on disk
- */
- long getSize()
- {
- return file.length();
- }
-
- /**
- * Open a <tt>ZipFile</tt> if none currently exists. If reaper mode is active, apply for monitoring.
- *
- * @return a ZipFile
- * @throws IOException for any error
- */
- private ZipFile ensureZipFile() throws IOException
- {
- if (zipFile == null)
- {
- ZipFactory factory = ZipUtils.getFactory();
- zipFile = factory.createFile(file);
- if (forceNoReaper == false && noReaperOverride == false)
- ZipFileLockReaper.getInstance().register(this);
- }
-
- return zipFile;
- }
-
- /**
- * Close a <tt>ZipFile</tt> if currently open. If reaper mode is active, unregister from monitoring
- *
- * @throws IOException for any error
- */
- synchronized void closeZipFile() throws IOException
- {
- if (zipFile != null && getReferenceCount() <= 0)
- {
- ZipFile zf = zipFile;
- zipFile = null;
- zf.close();
- if (forceNoReaper == false && noReaperOverride == false)
- ZipFileLockReaper.getInstance().unregister(this);
- }
- }
-
- /**
- * Get the contents of the given <tt>ZipEntry</tt> as stream
- *
- * @param ent a zip entry
- * @return an InputStream that locks the file for as long as it's open
- * @throws IOException for any error
- */
- synchronized InputStream openStream(ZipEntry ent) throws IOException
- {
- // JBVFS-57 JarInputStream composition
- if (ent.isDirectory())
- return recomposeZipAsInputStream(ent.getName());
-
- ensureZipFile();
- InputStream is = zipFile.getInputStream(ent);
- if (is == null)
- throw new IOException("Entry no longer available: " + ent.getName() + " in file " + file);
-
- ZipEntryInputStream zis = new ZipEntryInputStream(this, is);
-
- // debugging code
- //streams.add(zis);
-
- incrementRef();
- return zis;
- }
-
- /**
- * Get raw bytes of this archive in its compressed form
- *
- * @return an InputStream
- * @throws FileNotFoundException if archive doesn't exist
- */
- InputStream getRootAsStream() throws FileNotFoundException
- {
- return new FileInputStream(file);
- }
-
- /**
- * Increment usage count by one and ensure <tt>ZipFile</tt> is open.
- *
- * @throws IOException
- */
- synchronized void acquire() throws IOException
- {
- ensureZipFile();
- incrementRef();
- }
-
- /**
- * Decrement usage count by one
- */
- synchronized void release() {
- super.release();
- if (forceNoReaper || noReaperOverride)
- try
- {
- closeZipFile();
- }
- catch(Exception ex)
- {
- log.warn("Failed to release file: " + file);
- }
- }
-
- /**
- * Enumerate contents of zip archive
- */
- synchronized Enumeration<? extends ZipEntry> entries() throws IOException
- {
- return ensureZipFile().entries();
- }
-
- /**
- * Close the archive, perform autoclean if requested
- */
- void close()
- {
- try
- {
- closeZipFile();
- }
- catch(Exception ignored)
- {
- log.warn("IGNORING: Failed to release file: " + file, ignored);
- }
-
- if (autoClean)
- file.delete();
- }
-
- void deleteFile(ZipFileWrapper wrapper) throws IOException
- {
- if (file.equals(wrapper.file))
- {
- closeZipFile();
- file.delete();
- }
- }
-
- /**
- * Delete the archive
- *
- * @param gracePeriod max time to wait for any locks
- * @return true if file was deleted, false otherwise
- * @throws IOException if an error occurs
- */
- boolean delete(int gracePeriod) throws IOException
- {
- boolean exists = file.isFile();
- if (exists == false)
- return false;
-
- boolean interrupted = Thread.interrupted();
- try
- {
- long endOfGrace = System.currentTimeMillis() + gracePeriod;
- do
- {
- closeZipFile();
- ZipFileLockReaper.getInstance().deleteFile(this);
- try
- {
- if (file.exists() && file.delete() == false)
- Thread.sleep(100);
- else
- return true;
- }
- catch (InterruptedException e)
- {
- interrupted = true;
- return file.exists() == false || file.delete();
- }
- }
- while(System.currentTimeMillis() < endOfGrace);
- }
- finally
- {
- if (interrupted)
- Thread.currentThread().interrupt();
- }
-
- return file.delete();
- }
-
- protected synchronized void recomposeZip(OutputStream baos, String path) throws IOException
- {
- ZipOutputStream zout = new ZipOutputStream(baos);
- zout.setMethod(ZipOutputStream.STORED);
-
- ensureZipFile();
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while(entries.hasMoreElements())
- {
- ZipEntry oldEntry = entries.nextElement();
- if (oldEntry.getName().startsWith(path))
- {
- String newName = oldEntry.getName().substring(path.length());
- if(newName.length() == 0)
- continue;
-
- java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(newName);
- newEntry.setComment(oldEntry.getComment());
- newEntry.setTime(oldEntry.getTime());
- newEntry.setSize(oldEntry.getSize());
- newEntry.setCrc(oldEntry.getCrc());
- zout.putNextEntry(newEntry);
- if (oldEntry.isDirectory() == false)
- {
- InputStream is = zipFile.getInputStream(oldEntry);
- try
- {
- VFSUtils.copyStream(is, zout);
- is.close();
- }
- finally
- {
- VFSUtils.safeClose(is);
- }
- }
- }
- }
- zout.close();
- }
-
- /**
- * toString
- *
- * @return String description of this archive
- */
- public String toString()
- {
- return super.toString() + " - " + file.getAbsolutePath();
- }
-
- /**
- * PriviligedAction used to read a system property
- */
- private static class CheckNoReaper implements PrivilegedAction<Boolean>
- {
- public Boolean run()
- {
- String forceString = System.getProperty(VFSUtils.FORCE_NO_REAPER_KEY, "false");
- return Boolean.valueOf(forceString);
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,249 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.zip.ZipOutputStream;
-
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.spi.zip.ZipEntry;
-import org.jboss.virtual.spi.zip.ZipEntryProvider;
-import org.jboss.virtual.spi.zip.ZipFactory;
-import org.jboss.virtual.spi.zip.ZipUtils;
-
-/**
- * ZipStreamWrapper - for abstracted access to in-memory zip file
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-class ZipStreamWrapper extends ZipBytesWrapper
-{
- /** Logger */
- private static final Logger log = Logger.getLogger(ZipStreamWrapper.class);
-
- /** Is optimizeForMemory turned on */
- private static boolean optimizeForMemory;
-
- static
- {
- optimizeForMemory = AccessController.doPrivileged(new CheckOptimizeForMemory());
-
- if (optimizeForMemory)
- log.info("VFS optimizeForMemory is enabled.");
- }
-
- /** zip archive - as individual inflated in-memory files */
- private Map<String, InMemoryFile> inMemoryFiles = new LinkedHashMap<String, InMemoryFile>();
-
- /** size of the zip file composed back from inMemoryFiles */
- private int size;
-
- /**
- * ZipStreamWrapper is not aware of actual zip source so it can not detect
- * if it's been modified, like ZipFileWrapper does.
- *
- * @param zipStream the current zip stream
- * @param name the name
- * @param lastModified passed by zip stream provider - constant value
- * @throws IOException for any error
- */
- ZipStreamWrapper(InputStream zipStream, String name, long lastModified) throws IOException
- {
- super(zipStream, name, lastModified);
-
- ZipFactory factory = ZipUtils.getFactory();
- ZipEntryProvider zis = factory.createProvider(super.getRootAsStream());
- try
- {
- ZipEntry ent = zis.getNextEntry();
- while (ent != null)
- {
- byte [] fileBytes;
- if (ent.isDirectory() == false)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStreamAndClose(zis.currentStream(), baos);
- fileBytes = baos.toByteArray();
- ent.setSize(fileBytes.length);
- }
- else
- {
- fileBytes = new byte[0];
- }
-
- inMemoryFiles.put(ent.getName(), new InMemoryFile(ent, fileBytes));
- ent = zis.getNextEntry();
- }
- zis.close();
- }
- finally
- {
- VFSUtils.safeClose(zis);
- }
-
- if (optimizeForMemory) {
- initZipSize();
-
- // we don't need memory buffer any more
- super.close();
- }
- }
-
- InputStream openStream(ZipEntry ent) throws IOException
- {
- // JBVFS-57 JarInputStream composition
- if (ent.isDirectory())
- return recomposeZipAsInputStream(ent.getName());
-
- InMemoryFile memFile = inMemoryFiles.get(ent.getName());
-
- if (memFile == null)
- throw new FileNotFoundException("Failed to find nested jar entry: " + ent.getName() + " in zip stream: " + toString());
-
- return new ByteArrayInputStream(memFile.fileBytes);
- }
-
- Enumeration<? extends ZipEntry> entries() throws IOException
- {
- return new ZipStreamEnumeration();
- }
-
- InputStream getRootAsStream() throws FileNotFoundException
- {
- if (optimizeForMemory)
- return recomposeZipAsInputStream();
- else
- return super.getRootAsStream();
- }
-
- long getSize()
- {
- if (optimizeForMemory)
- return size;
- else
- return super.getSize();
- }
-
- void close() {
- inMemoryFiles = null;
- super.close();
- }
-
- private void initZipSize() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- recomposeZip(baos);
- this.size = baos.size();
- }
-
- private void recomposeZip(ByteArrayOutputStream baos) throws IOException
- {
- recomposeZip(baos, "");
- }
-
- protected void recomposeZip(OutputStream baos, String path) throws IOException
- {
- ZipOutputStream zout = new ZipOutputStream(baos);
- zout.setMethod(ZipOutputStream.STORED);
-
- Iterator<InMemoryFile> it = inMemoryFiles.values().iterator();
- while(it.hasNext())
- {
- InMemoryFile memFile = it.next();
- ZipEntry oldEntry = memFile.entry;
- if (oldEntry.getName().startsWith(path))
- {
- String newName = oldEntry.getName().substring(path.length());
- if(newName.length() == 0)
- continue;
-
- java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(newName);
- newEntry.setComment(oldEntry.getComment());
- newEntry.setTime(oldEntry.getTime());
- newEntry.setSize(oldEntry.getSize());
- newEntry.setCrc(oldEntry.getCrc());
- zout.putNextEntry(newEntry);
- if (oldEntry.isDirectory() == false)
- zout.write(memFile.fileBytes);
- }
- }
- zout.close();
- }
-
- private InputStream recomposeZipAsInputStream() throws FileNotFoundException
- {
- return recomposeZipAsInputStream("");
- }
-
- static class InMemoryFile
- {
- ZipEntry entry;
- byte [] fileBytes;
-
- public InMemoryFile(ZipEntry entry, byte[] fileBytes)
- {
- this.entry = entry;
- this.fileBytes = fileBytes;
- }
- }
-
- class ZipStreamEnumeration implements Enumeration<ZipEntry>
- {
- private Iterator<InMemoryFile> it;
-
- ZipStreamEnumeration()
- {
- it = inMemoryFiles.values().iterator();
- }
-
- public boolean hasMoreElements()
- {
- return it.hasNext();
- }
-
- public ZipEntry nextElement()
- {
- return it.next().entry;
- }
- }
-
- private static class CheckOptimizeForMemory implements PrivilegedAction<Boolean>
- {
- public Boolean run()
- {
- String forceString = System.getProperty(VFSUtils.OPTIMIZE_FOR_MEMORY_KEY, "false");
- return Boolean.valueOf(forceString);
- }
- }
-}
Deleted: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,232 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.virtual.plugins.context.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Enumeration;
-
-import org.jboss.logging.Logger;
-import org.jboss.virtual.spi.zip.ZipEntry;
-
-/**
- * ZipWrapper represents abstracted access to zip archive
- *
- * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
- * @version $Revision: 1.0 $
- */
-abstract class ZipWrapper
-{
- /** the log */
- protected static final Logger log = Logger.getLogger(ZipWrapper.class);
-
- /** last known modifyTime of the zip source */
- protected long lastModified;
-
- /** timestamp of last call to getLastModified()
- * it's an expensive call - we don't do it more then once every second */
- private long lastChecked;
-
- /** last known activity */
- private long lastUsed;
-
- /** number of streams currently open on this wrapper */
- private int refCount = 0;
-
- /**
- * Returns true if underlying source's lastModified time has changed since previous call.
- *
- * @return true if modified, false othwewise
- */
- boolean hasBeenModified()
- {
- long now = System.currentTimeMillis();
- if (now - lastChecked < 1000)
- return false;
-
- lastChecked = now;
- long lm = getLastModified();
- if (lm != lastModified)
- {
- lastModified = lm;
- return true;
- }
-
- return false;
- }
-
- /**
- * get lastUsed timestamp
- *
- * @return
- */
- long getLastUsed()
- {
- return lastUsed;
- }
-
- /**
- * Returns the number of streams currently open
- *
- * @return
- */
- int getReferenceCount()
- {
- return refCount;
- }
-
- /**
- * Increment usage count by one
- */
- void incrementRef()
- {
- refCount++;
- lastUsed = System.currentTimeMillis();
- }
-
- /**
- * Decrement usage count by one
- */
- synchronized void release()
- {
- refCount--;
- if (refCount <= 0)
- {
- lastUsed = System.currentTimeMillis();
- }
- }
-
- /**
- * Acquire lock.
- *
- * @throws IOException for any error
- */
- abstract void acquire() throws IOException;
-
- /**
- * Get lastModified of this archive
- *
- * @return lastModified timestamp
- */
- abstract long getLastModified();
-
- /**
- * Get the name of this archive
- *
- * @return name
- */
- abstract String getName();
-
- /**
- * Check if archive exists
- *
- * @return true if archive exists
- */
- abstract boolean exists();
-
- /**
- * Get the size of the archive
- *
- * @return size in bytes
- */
- abstract long getSize();
-
- /**
- * Enumerate contents of this archive
- *
- * @return enumeration of ZipEntries
- * @throws IOException for any error
- */
- abstract Enumeration<? extends ZipEntry> entries() throws IOException;
-
- /**
- * Get the contents of a given entry as stream
- *
- * @param ent zip entry
- * @return InputStream with entry's contents
- * @throws IOException for any error
- */
- abstract InputStream openStream(ZipEntry ent) throws IOException;
-
- /**
- * Get raw bytes of this archive in its compressed form
- *
- * @return InputStream containing raw archive
- * @throws FileNotFoundException if archive doesn't exist
- */
- abstract InputStream getRootAsStream() throws FileNotFoundException;
-
- /**
- * Close this archive
- */
- abstract void close();
-
- /**
- * Delete this archive
- *
- * @param gracePeriod maximum time to wait for any locks
- * @return true if file was deleted, false otherwise
- * @throws IOException for any error
- */
- abstract boolean delete(int gracePeriod) throws IOException;
-
- /**
- * Recompose an input stream as having <em>path</em> entry for its root.
- * All entries' names have to be shifted accordingly.
- *
- * @param path root path
- * @return InputStream containing a new ZIP archive
- * @throws FileNotFoundException for any error that prevented recomposition
- */
- protected InputStream recomposeZipAsInputStream(String path) throws FileNotFoundException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try
- {
- recomposeZip(baos, path);
- return new ByteArrayInputStream(baos.toByteArray());
- }
- catch (IOException ex)
- {
- FileNotFoundException e = new FileNotFoundException("Failed to recompose inflated nested archive " + getName());
- e.initCause(ex);
- throw e;
- }
- }
-
- /**
- * Recompose an input streamas having <em>path</em> entry for its root, and write it to a given OutputStream.
- * All entries' names have to be shifted accordingly.
- *
- * @param os OutputStream that will contain newly create archive
- * @param path root path
- * @throws IOException for any error
- */
- protected void recomposeZip(OutputStream os, String path) throws IOException
- {
- // do nothing
- }
-}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -23,7 +23,6 @@
import java.io.IOException;
-import org.jboss.virtual.plugins.context.jar.NestedJarHandler;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
@@ -43,7 +42,7 @@
protected boolean isAlreadyModified(VirtualFileHandler handler) throws IOException
{
// this is already a copy
- return handler instanceof NestedJarHandler;
+ return false;
}
protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -39,10 +39,9 @@
import org.jboss.logging.Logger;
import org.jboss.virtual.plugins.context.file.FileSystemContextFactory;
-import org.jboss.virtual.plugins.context.jar.JarContextFactory;
import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory;
import org.jboss.virtual.plugins.context.VfsArchiveBrowserFactory;
+import org.jboss.virtual.plugins.context.jzip.ZipContextFactory;
import org.jboss.virtual.VFSUtils;
import org.jboss.util.file.ArchiveBrowser;
@@ -247,13 +246,13 @@
// No jar protocol, use the default
if (factoryByProtocol.containsKey("jar") == false)
- registerFactory(new JarContextFactory());
+ registerFactory(ZipContextFactory.getInstance());
if (factoryByProtocol.containsKey("vfsmemory") == false)
registerFactory(MemoryContextFactory.getInstance());
if (factoryByProtocol.containsKey("vfszip") == false)
- registerFactory(ZipEntryContextFactory.getInstance());
+ registerFactory(ZipContextFactory.getInstance());
initialized = true;
}
Deleted: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/JarOAContextFactory.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/JarOAContextFactory.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/support/JarOAContextFactory.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -1,45 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.virtual.support;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URL;
-
-import org.jboss.virtual.plugins.context.jar.JarContextFactory;
-import org.jboss.virtual.spi.VFSContext;
-
-/**
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class JarOAContextFactory extends JarContextFactory
-{
- public VFSContext getVFS(URL root) throws IOException
- {
- return super.getVFS(OptionsAwareURI.toURL(root));
- }
-
- public VFSContext getVFS(URI root) throws IOException
- {
- return getVFS(OptionsAwareURI.toURI(root).toURL());
- }
-}
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/AbstractVFSTest.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -28,7 +28,6 @@
import junit.framework.AssertionFailedError;
import org.jboss.test.BaseTestCase;
import org.jboss.test.virtual.support.FileOAContextFactory;
-import org.jboss.test.virtual.support.JarOAContextFactory;
import org.jboss.test.virtual.support.OptionsAwareURI;
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
@@ -44,7 +43,6 @@
public abstract class AbstractVFSTest extends BaseTestCase
{
private static final VFSContextFactory fileFactory = new FileOAContextFactory();
- private static final VFSContextFactory jarFactory = new JarOAContextFactory();
private boolean forceCopy;
private boolean forceNoReaper;
@@ -99,7 +97,6 @@
*/
VFSContextFactoryLocator.registerFactory(fileFactory);
- VFSContextFactoryLocator.registerFactory(jarFactory);
getLog().info("Force copy: " + forceCopy);
if (forceCopy)
@@ -111,7 +108,6 @@
protected void tearDown() throws Exception
{
- VFSContextFactoryLocator.unregisterFactory(jarFactory);
VFSContextFactoryLocator.unregisterFactory(fileFactory);
if (forceCopy)
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -41,10 +41,8 @@
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
-import java.util.zip.ZipInputStream;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -58,10 +56,8 @@
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VisitorAttributes;
import org.jboss.virtual.plugins.context.file.FileSystemContext;
-import org.jboss.virtual.plugins.context.jar.NestedJarFromStream;
import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter;
import org.jboss.virtual.spi.LinkInfo;
-import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VFSContextFactory;
import org.jboss.virtual.spi.VFSContextFactoryLocator;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -119,64 +115,6 @@
}
/**
- * Test that NestedJarFromStream can provide access to nested jar content
- * @throws Exception
- */
- public void testNestedJarFromStream()
- throws Exception
- {
- URL outer = getResource("/vfs/test/outer.jar");
- String path = outer.getPath();
- File outerJar = new File(path);
- assertTrue(outerJar.getAbsolutePath()+" exists", outerJar.exists());
- JarFile jf = new JarFile(outerJar);
-
- URL rootURL = outerJar.getParentFile().toURI().toURL();
- VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURL);
- VFSContext context = factory.getVFS(rootURL);
-
- JarEntry jar1 = jf.getJarEntry("jar1.jar");
- URL jar1URL = new URL(outerJar.toURI().toURL(), "jar1.jar");
- VFSContextFactory pf1 = VFSContextFactoryLocator.getFactory(jar1URL);
- VFSContext parent1 = pf1.getVFS(jar1URL);
-
- ZipInputStream jis1 = new ZipInputStream(jf.getInputStream(jar1));
- NestedJarFromStream njfs = new NestedJarFromStream(context, parent1.getRoot(), jis1, jar1URL, jf, jar1, "jar1.jar");
- VirtualFileHandler e1 = njfs.getChild("org/jboss/test/vfs/support/jar1/ClassInJar1.class");
- assertNotNull(e1);
- log.info("org/jboss/test/vfs/support/CommonClass.class: "+e1);
- VirtualFileHandler mfe1 = njfs.getChild("META-INF/MANIFEST.MF");
- assertNotNull("jar1!/META-INF/MANIFEST.MF", mfe1);
- InputStream mfIS = mfe1.openStream();
- Manifest mf = new Manifest(mfIS);
- Attributes mainAttrs = mf.getMainAttributes();
- String title1 = mainAttrs.getValue(Attributes.Name.SPECIFICATION_TITLE);
- assertEquals("jar1", title1);
- mfIS.close();
- njfs.close();
-
- JarEntry jar2 = jf.getJarEntry("jar2.jar");
- URL jar2URL = new URL(outerJar.toURI().toURL(), "jar2.jar");
- VFSContextFactory pf2 = VFSContextFactoryLocator.getFactory(jar2URL);
- VFSContext parent2 = pf2.getVFS(jar2URL);
-
- ZipInputStream jis2 = new ZipInputStream(jf.getInputStream(jar2));
- NestedJarFromStream njfs2 = new NestedJarFromStream(context, parent2.getRoot(), jis2, jar2URL, jf, jar2, "jar2.jar");
- VirtualFileHandler e2 = njfs2.getChild("org/jboss/test/vfs/support/jar2/ClassInJar2.class");
- assertNotNull(e2);
- log.info("org/jboss/test/vfs/support/CommonClass.class: "+e2);
- VirtualFileHandler mfe2 = njfs2.getChild("META-INF/MANIFEST.MF");
- assertNotNull("jar2!/META-INF/MANIFEST.MF", mfe2);
- InputStream mf2IS = mfe2.openStream();
- Manifest mf2 = new Manifest(mf2IS);
- Attributes mainAttrs2 = mf2.getMainAttributes();
- String title2 = mainAttrs2.getValue(Attributes.Name.SPECIFICATION_TITLE);
- assertEquals("jar2", title2);
- mf2IS.close();
- njfs2.close();
- }
-
- /**
* Test reading the contents of nested jar entries.
* @throws Exception
*/
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -36,8 +36,6 @@
import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.context.file.FileSystemContext;
-import org.jboss.virtual.plugins.context.jar.JarContext;
-import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -48,9 +46,9 @@
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class JARVFSContextUnitTestCase extends AbstractVFSContextTest
+public abstract class JARVFSContextUnitTestCase extends AbstractVFSContextTest
{
- public JARVFSContextUnitTestCase(String name)
+ protected JARVFSContextUnitTestCase(String name)
{
super(name);
}
@@ -62,12 +60,7 @@
return new TestSuite(JARVFSContextUnitTestCase.class);
}
- protected VFSContext getVFSContext(String name) throws Exception
- {
- URL url = getResource("/vfs/context/jar/" + name + ".jar");
- url = JarUtils.createJarURL(url);
- return new JarContext(url);
- }
+ protected abstract VFSContext getVFSContext(String name) throws Exception;
protected VFSContext getParentVFSContext() throws Exception
{
@@ -82,12 +75,7 @@
* @return new vfs context
* @throws Exception for any error
*/
- protected VFSContext createVSFContext(URL url) throws Exception
- {
- if (url.toExternalForm().startsWith("jar") == false)
- url = JarUtils.createJarURL(url);
- return new JarContext(url);
- }
+ protected abstract VFSContext createVSFContext(URL url) throws Exception;
protected String getSuffix()
{
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/JARVirtualFileHandlerUnitTestCase.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -29,7 +29,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.jboss.virtual.plugins.context.jar.JarContext;
import org.jboss.virtual.plugins.context.jar.JarUtils;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -40,9 +39,9 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class JARVirtualFileHandlerUnitTestCase extends AbstractVirtualFileHandlerTest
+public abstract class JARVirtualFileHandlerUnitTestCase extends AbstractVirtualFileHandlerTest
{
- public JARVirtualFileHandlerUnitTestCase(String name)
+ protected JARVirtualFileHandlerUnitTestCase(String name)
{
super(name);
}
@@ -75,12 +74,7 @@
return jarFile.getJarEntry(path);
}
- protected VFSContext getVFSContext(String name) throws Exception
- {
- URL url = getRootResource(name);
- url = JarUtils.createJarURL(url);
- return new JarContext(url);
- }
+ protected abstract VFSContext getVFSContext(String name) throws Exception;
protected String getRootName(String name) throws Exception
{
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -61,8 +61,6 @@
suite.addTest(JarFileURLTestCase.suite());
suite.addTest(JARCacheUnitTestCase.suite());
suite.addTest(CopyJARCacheUnitTestCase.suite());
- suite.addTest(JARVFSContextUnitTestCase.suite());
- suite.addTest(JARVirtualFileHandlerUnitTestCase.suite());
suite.addTest(JARSerializationUnitTestCase.suite());
suite.addTest(CopyJARSerializationUnitTestCase.suite());
suite.addTest(JAREntryTestCase.suite());
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -21,7 +21,6 @@
*/
package org.jboss.test.virtual.test;
-import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Collections;
@@ -29,9 +28,7 @@
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.jar.JarContextFactory;
import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VFSContextFactory;
import org.jboss.virtual.spi.cache.CacheStatistics;
import org.jboss.virtual.spi.cache.VFSCache;
import org.jboss.virtual.spi.cache.VFSCacheFactory;
@@ -194,58 +191,6 @@
}
}
- /**
- * Test jar path.
- *
- * @throws Exception for any error
- */
- public void testJarPath() throws Exception
- {
- // to circumvent another bug in VFS
- Map<String, VFSContextFactory> factoryByProtocol = getFactoryByProtocol();
- VFSContextFactory oldFactory = factoryByProtocol.put("jar", new JarContextFactory());
-
- VFSCache cache = createCache();
- cache.start();
- try
- {
- VFSCacheFactory.setInstance(cache);
- try
- {
- configureCache(cache);
-
- URL url = getResource("/vfs/test/jar1.jar");
- URL manifestURL = new URL("jar:" + url.toExternalForm() + "!/META-INF/MANIFEST.MF");
-
- // first we ask for a jar:file: resource
-
- VirtualFile manifest = VFS.getRoot(manifestURL);
-
- assertNotNull(manifest);
-
- // then we ask for a file: resource
-
- VirtualFile jar = VFS.getRoot(url);
-
- assertNotNull(jar);
- }
- catch(IOException e)
- {
- fail("failed to get the proper files: " + e.getMessage());
- }
- finally
- {
- VFSCacheFactory.setInstance(null);
- }
- }
- finally
- {
- factoryByProtocol.put("jar", oldFactory);
-
- stopCache(cache);
- }
- }
-
private class WrapperVFSCache implements VFSCache
{
private VFSCache delegate;
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryHandlerUnitTestCase.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -30,7 +30,7 @@
import junit.framework.Test;
import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
+import org.jboss.virtual.plugins.context.jzip.ZipEntryContext;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
Modified: projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2009-06-23 15:17:14 UTC (rev 90527)
+++ projects/vfs/branches/dml-zip-rework/src/test/java/org/jboss/test/virtual/test/ZipEntryVFSContextUnitTestCase.java 2009-06-23 15:20:01 UTC (rev 90528)
@@ -36,7 +36,7 @@
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
+import org.jboss.virtual.plugins.context.jzip.ZipEntryContext;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
@@ -87,7 +87,7 @@
OutputStream os = new FileOutputStream(tmpJar);
VFSUtils.copyStreamAndClose(is, os);
- ZipEntryContext context = new ZipEntryContext(tmpJar.toURI().toURL());
+ VFSContext context = new ZipEntryContext(tmpJar.toURI().toURL());
assertTrue("context.getRoot().exists()", context.getRoot().exists());
boolean isDeleted = context.getRoot().delete(1000);
@@ -189,7 +189,7 @@
// nested root test
url = getResource("/vfs/test/");
- ZipEntryContext zctx = new ZipEntryContext(new URL("vfszip:" + url.getPath() + "/level1.zip/level2.zip/level3.zip"));
+ VFSContext zctx = new ZipEntryContext(new URL("vfszip:" + url.getPath() + "/level1.zip/level2.zip/level3.zip"));
VirtualFileHandler handler = zctx.getRoot();
assertEquals("Nested root Real URL", jarURL, handler.getRealURL().toExternalForm());
More information about the jboss-cvs-commits
mailing list