[jboss-cvs] JBossAS SVN: r94857 - projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 14 08:16:32 EDT 2009
Author: alesj
Date: 2009-10-14 08:16:31 -0400 (Wed, 14 Oct 2009)
New Revision: 94857
Added:
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/DefaultZipEntryInfo.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfo.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextInfo.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInfo.java
Removed:
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfoAdapter.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
Modified:
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/CertificateReaderInputStream.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
Log:
Remove hacks for reading certs.
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/CertificateReaderInputStream.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/CertificateReaderInputStream.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/CertificateReaderInputStream.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.zip.ZipEntry;
/**
* ZipEntryInputStream is part of ZipFileWrapper implementation.
@@ -39,8 +38,8 @@
*/
class CertificateReaderInputStream extends InputStream
{
- /** ZipEntry */
- private ZipEntry entry;
+ /** ZipEntryInfo */
+ private ZipEntryInfo info;
/** Underlying zip source */
private ZipFileWrapper zipWrapper;
@@ -54,18 +53,18 @@
/**
* ZipEntryInputStream constructor.
*
- * @param entry zip entry
+ * @param info zip entry info
* @param zipWrapper underlying zip source
* @param is underlying input stream
* @throws java.io.IOException for any error
* @throws IllegalArgumentException if insput stream is null
*/
- CertificateReaderInputStream(ZipEntry entry, ZipFileWrapper zipWrapper, InputStream is) throws IOException
+ CertificateReaderInputStream(ZipEntryInfo info, ZipFileWrapper zipWrapper, InputStream is) throws IOException
{
if (is == null)
throw new IllegalArgumentException("Input stream is null");
- this.entry = entry;
+ this.info = info;
this.zipWrapper = zipWrapper;
delegate = is;
}
@@ -83,8 +82,7 @@
try
{
- if (entry instanceof EntryInfoAdapter)
- EntryInfoAdapter.class.cast(entry).readCertificates();
+ info.readCertificates();
}
finally
{
Added: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/DefaultZipEntryInfo.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/DefaultZipEntryInfo.java (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/DefaultZipEntryInfo.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.zip.ZipEntry;
+
+/**
+ * Default ZipEntryInfo.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+class DefaultZipEntryInfo implements ZipEntryInfo
+{
+ private ZipEntry entry;
+
+ DefaultZipEntryInfo(ZipEntry entry)
+ {
+ if (entry == null)
+ throw new IllegalArgumentException("Null entry");
+ this.entry = entry;
+ }
+
+ public String getName()
+ {
+ return entry.getName();
+ }
+
+ public boolean isDirectory()
+ {
+ return entry.isDirectory();
+ }
+
+ public boolean requiresUpdate()
+ {
+ return false;
+ }
+
+ public void readCertificates()
+ {
+ }
+
+ public ZipEntry getEntry()
+ {
+ return entry;
+ }
+
+ public void setEntry(ZipEntry entry)
+ {
+ }
+}
\ No newline at end of file
Copied: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfo.java (from rev 94854, projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java)
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfo.java (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfo.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -0,0 +1,172 @@
+/*
+* 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.security.cert.Certificate;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.zip.ZipEntry;
+
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Basic zip entry info impl.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ * @author <a href="marko.strukelj at parsek.net">Marko Strukelj</a>
+ */
+class EntryInfo implements ZipEntryContextInfo
+{
+ /** a marker */
+ static final Certificate[] MARKER = new Certificate[]{};
+
+ /** a handler */
+ private AbstractVirtualFileHandler handler;
+
+ /** a <tt>ZipEntry</tt> */
+ private ZipEntry entry;
+
+ /** the certificates */
+ private Certificate[] certificates;
+
+ /** 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;
+ }
+
+ public void readCertificates()
+ {
+ if (certificates == null)
+ {
+ Certificate[] certs = null;
+ if (entry instanceof JarEntry)
+ certs = JarEntry.class.cast(entry).getCertificates();
+
+ certificates = (certs != null) ? certs : MARKER;
+ }
+ }
+
+ /**
+ * Get certificates.
+ *
+ * @return the certificates
+ */
+ public Certificate[] getCertificates()
+ {
+ return (certificates != MARKER) ? certificates : null;
+ }
+
+ public synchronized List<VirtualFileHandler> getChildren()
+ {
+ if (children == null)
+ return Collections.emptyList();
+
+ return new ArrayList<VirtualFileHandler>(children.values());
+ }
+
+ public synchronized void replaceChild(AbstractVirtualFileHandler original, AbstractVirtualFileHandler replacement)
+ {
+ if (children != null)
+ {
+ final String name = original.getName();
+ if (children.containsKey(name)) {
+ children.put(name, replacement);
+ }
+ }
+ }
+
+ public synchronized void clearChildren()
+ {
+ if (children != null)
+ children.clear();
+ }
+
+ public synchronized void add(AbstractVirtualFileHandler child)
+ {
+ if (children == null)
+ {
+ children = new LinkedHashMap<String, AbstractVirtualFileHandler>();
+ }
+ children.put(child.getName(), child);
+ }
+
+ public String getName()
+ {
+ return (entry != null) ? entry.getName() : handler.getName();
+ }
+
+ public boolean isDirectory()
+ {
+ // if entry is null, we return false
+ return (entry != null) && entry.isDirectory();
+ }
+
+ public boolean requiresUpdate()
+ {
+ return (certificates == null);
+ }
+
+ public ZipEntry getEntry()
+ {
+ return entry;
+ }
+
+ public void setEntry(ZipEntry entry)
+ {
+ this.entry = entry;
+ }
+
+ public long getTime()
+ {
+ return (entry != null) ? entry.getTime() : 0;
+ }
+
+ public long getSize()
+ {
+ return (entry != null) ? entry.getSize() : 0;
+ }
+
+ public AbstractVirtualFileHandler getHandler()
+ {
+ return handler;
+ }
+
+ public void setHandler(AbstractVirtualFileHandler handler)
+ {
+ this.handler = handler;
+ }
+}
\ No newline at end of file
Deleted: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfoAdapter.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfoAdapter.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/EntryInfoAdapter.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -1,84 +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.security.cert.Certificate;
-import java.util.jar.JarEntry;
-import java.util.zip.ZipEntry;
-
-/**
- * EntryInfo wrapper.
- * It knows how to read certificates.
- *
- * Note: this is basically a hack,
- * so we don't have to change ZipWrapper API.
- * It should be removed with next minor version.
- *
- * @author <a href="ales.justin at jboss.org">Ales Justin</a>
- */
-class EntryInfoAdapter extends ZipEntry
-{
- private ZipEntryContext.EntryInfo ei;
-
- EntryInfoAdapter(ZipEntryContext.EntryInfo ei)
- {
- super(ei.entry);
- this.ei = ei;
- }
-
- /**
- * Update entry.
- *
- * @param entry the new entry
- */
- void updateEntry(ZipEntry entry)
- {
- ei.entry = entry;
- }
-
- /**
- * Read certificates.
- */
- void readCertificates()
- {
- if (ei.certificates == null)
- {
- ZipEntry entry = ei.entry;
-
- Certificate[] certs = null;
- if (entry instanceof JarEntry)
- certs = JarEntry.class.cast(entry).getCertificates();
-
- ei.certificates = (certs != null) ? certs : ZipEntryContext.EntryInfo.MARKER;
- }
- }
-
- /**
- * Do we require an update.
- *
- * @return true if we need to update entry
- */
- boolean requiresUpdate()
- {
- return ei.certificates == null;
- }
-}
\ No newline at end of file
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -53,13 +53,13 @@
this.zisCopy = zisCopy;
}
- InputStream openStream(ZipEntry ent) throws IOException
+ InputStream openStream(ZipEntryInfo info) throws IOException
{
zisCopy.reset();
// TODO - optimize this
ZipInputStream zis = new ZipInputStream(zisCopy);
ZipEntry entry = zis.getNextEntry();
- while (entry != null && entry.getName().equals(ent.getName()) == false)
+ while (entry != null && entry.getName().equals(info.getName()) == false)
entry = zis.getNextEntry();
return zis;
}
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -38,12 +38,10 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.cert.Certificate;
-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;
@@ -138,7 +136,7 @@
private final boolean autoClean;
/** Registry of everything that zipSource contains */
- private final Map<String, EntryInfo> entries = new ConcurrentHashMap<String, EntryInfo>(16,.75f,4);
+ private final Map<String, ZipEntryContextInfo> entries = new ConcurrentHashMap<String, ZipEntryContextInfo>(16,.75f,4);
/** Have zip entries been navigated yet */
private volatile InitializationStatus initStatus = InitializationStatus.NOT_INITIALIZED;
@@ -507,14 +505,14 @@
String parentPath = split[0];
String name = split[1];
- EntryInfo ei = null;
+ ZipEntryContextInfo ei = null;
if ("".equals(name) == false)
{
ei = entries.get(parentPath);
if (ei == null)
ei = makeDummyParent(parentPath);
}
- AbstractVirtualFileHandler parent = ei != null ? ei.handler : null;
+ AbstractVirtualFileHandler parent = ei != null ? ei.getHandler() : null;
// it's a nested jar
if (ent.isDirectory() == false && JarUtils.isArchive(ent.getName()))
@@ -568,7 +566,7 @@
// ensure parent exists
dest.getParentFile().mkdirs();
- InputStream is = zipSource.openStream(ent);
+ InputStream is = zipSource.openStream(new DefaultZipEntryInfo(ent));
OutputStream os = new BufferedOutputStream(new FileOutputStream(dest));
VFSUtils.copyStreamAndClose(is, os);
}
@@ -582,7 +580,7 @@
else
{
// mount another instance of ZipEntryContext
- delegator = mountZipStream(parent, name, zipSource.openStream(ent));
+ delegator = mountZipStream(parent, name, zipSource.openStream(new DefaultZipEntryInfo(ent)));
}
entries.put(delegator.getLocalPathName(), new EntryInfo(delegator, ent));
@@ -652,7 +650,7 @@
{
if (initStatus != InitializationStatus.NOT_INITIALIZED)
{
- EntryInfo rootInfo = entries.get("");
+ ZipEntryContextInfo rootInfo = entries.get("");
entries.clear();
entries.put("", rootInfo);
@@ -731,11 +729,11 @@
String [] split = splitParentChild(parentPath);
String grandPa = split[0];
- EntryInfo eiParent = entries.get(grandPa);
+ ZipEntryContextInfo eiParent = entries.get(grandPa);
if(eiParent == null)
eiParent = makeDummyParent(grandPa);
- ZipEntryHandler handler = new ZipEntryHandler(this, eiParent.handler, split[1], false);
+ ZipEntryHandler handler = new ZipEntryHandler(this, eiParent.getHandler(), split[1], false);
EntryInfo ei = new EntryInfo(handler, null);
entries.put(parentPath, ei);
return ei;
@@ -786,7 +784,7 @@
}
else if (initStatus == InitializationStatus.INITIALIZED && getZipSource().hasBeenModified())
{
- EntryInfo rootInfo = entries.get("");
+ ZipEntryContextInfo rootInfo = entries.get("");
entries.clear();
entries.put("", rootInfo);
@@ -811,7 +809,7 @@
*/
public VirtualFileHandler getRoot()
{
- return entries.get("").handler;
+ return entries.get("").getHandler();
}
/**
@@ -834,9 +832,9 @@
else
pathName = pathName + "/" + name;
- EntryInfo ei = entries.get(pathName);
+ ZipEntryContextInfo ei = entries.get(pathName);
if(ei != null)
- return ei.handler;
+ return ei.getHandler();
return null;
}
@@ -858,11 +856,11 @@
if(parent instanceof AbstractVirtualFileHandler)
{
AbstractVirtualFileHandler parentHandler = (AbstractVirtualFileHandler) parent;
- EntryInfo parentEntry = entries.get(parentHandler.getLocalPathName());
+ ZipEntryContextInfo parentEntry = entries.get(parentHandler.getLocalPathName());
if (parentEntry != null)
{
- if (parentEntry.handler instanceof DelegatingHandler)
- return parentEntry.handler.getChildren(ignoreErrors);
+ if (parentEntry.getHandler() instanceof DelegatingHandler)
+ return parentEntry.getHandler().getChildren(ignoreErrors);
return parentEntry.getChildren();
}
@@ -910,15 +908,15 @@
if (getRoot().equals(handler) == false)
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
if(ei == null)
return 0;
- if(ei.entry == null) {
+ if(ei.getEntry() == null) {
return getZipSource().getLastModified();
}
- return ei.entry.getTime();
+ return ei.getTime();
}
/**
@@ -937,11 +935,11 @@
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
- if(ei == null || ei.entry == null)
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
+ if(ei == null || ei.getEntry() == null)
return 0;
- return ei.entry.getSize();
+ return ei.getSize();
}
/**
@@ -959,7 +957,7 @@
return getZipSource().exists();
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
return ei != null;
}
@@ -977,11 +975,11 @@
if (getRoot().equals(handler) == false)
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
- if (ei == null || ei.entry == null)
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
+ if (ei == null || ei.getEntry() == null)
return false;
- return ei.entry.isDirectory() == false;
+ return ei.isDirectory() == false;
}
/**
@@ -1072,7 +1070,7 @@
checkIfModified();
- EntryInfo ei = entries.get(handler.getLocalPathName());
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
if (ei == null)
{
@@ -1088,11 +1086,10 @@
throw new FileNotFoundException(uriStr);
}
- if(ei.entry == null)
+ if(ei.getEntry() == null)
return new ByteArrayInputStream(NO_BYTES);
- ZipEntry wrapper = new EntryInfoAdapter(ei);
- return getZipSource().openStream(wrapper);
+ return getZipSource().openStream(ei);
}
/**
@@ -1109,7 +1106,7 @@
if (child == null)
throw new IllegalArgumentException("Null child");
- EntryInfo parentEntry = entries.get(parent.getLocalPathName());
+ ZipEntryContextInfo parentEntry = entries.get(parent.getLocalPathName());
if (parentEntry != null)
parentEntry.add(child);
else
@@ -1143,7 +1140,7 @@
void replaceChild(ZipEntryHandler parent, AbstractVirtualFileHandler original, VirtualFileHandler replacement)
{
ensureEntries();
- EntryInfo parentEntry = entries.get(parent.getLocalPathName());
+ ZipEntryContextInfo parentEntry = entries.get(parent.getLocalPathName());
if (parentEntry != null)
{
DelegatingHandler newOne;
@@ -1161,9 +1158,9 @@
{
parentEntry.replaceChild(original, newOne);
- EntryInfo ei = entries.get(original.getLocalPathName());
- ei.handler = newOne;
- ei.entry = null;
+ ZipEntryContextInfo ei = entries.get(original.getLocalPathName());
+ ei.setHandler(newOne);
+ ei.setEntry(null);
ei.clearChildren();
}
}
@@ -1197,107 +1194,11 @@
*/
Certificate[] getCertificates(ZipEntryHandler handler)
{
- EntryInfo ei = entries.get(handler.getLocalPathName());
+ ZipEntryContextInfo ei = entries.get(handler.getLocalPathName());
return (ei != null) ? ei.getCertificates() : null;
}
/**
- * Internal data structure holding meta information of a virtual file in this context
- */
- static class EntryInfo
- {
- /** a marker */
- static final Certificate[] MARKER = new Certificate[]{};
-
- /** a handler */
- private AbstractVirtualFileHandler handler;
-
- /** a <tt>ZipEntry</tt> */
- ZipEntry entry;
-
- /** the certificates */
- Certificate[] certificates;
-
- /** 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 certificates.
- *
- * @return the certificates
- */
- private Certificate[] getCertificates()
- {
- return (certificates != MARKER) ? certificates : null;
- }
-
- /**
- * 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
*
Added: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextInfo.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextInfo.java (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContextInfo.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.security.cert.Certificate;
+import java.util.List;
+
+import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * ZipEntryContextInfo.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+interface ZipEntryContextInfo extends ZipEntryInfo
+{
+ /**
+ * Get time.
+ *
+ * @return get time
+ */
+ long getTime();
+
+ /**
+ * Get size.
+ *
+ * @return the size
+ */
+ long getSize();
+
+ /**
+ * Get certificates.
+ *
+ * @return the certificates.
+ */
+ Certificate[] getCertificates();
+
+ /**
+ * Get handler.
+ *
+ * @return the handler
+ */
+ AbstractVirtualFileHandler getHandler();
+
+ /**
+ * Set handler.
+ *
+ * @param handler the handler
+ */
+ void setHandler(AbstractVirtualFileHandler handler);
+
+ /**
+ * Get children.
+ *
+ * @return the children
+ */
+ List<VirtualFileHandler> getChildren();
+
+ /**
+ * Add child.
+ *
+ * @param child the child to add
+ */
+ void add(AbstractVirtualFileHandler child);
+
+ /**
+ * Clear children.
+ */
+ void clearChildren();
+
+ /**
+ * Replace child.
+ *
+ * @param original the original
+ * @param newOne the replacement
+ */
+ void replaceChild(AbstractVirtualFileHandler original, AbstractVirtualFileHandler newOne);
+}
\ No newline at end of file
Added: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInfo.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInfo.java (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInfo.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.zip.ZipEntry;
+
+/**
+ * ZipEntryInfo.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+interface ZipEntryInfo
+{
+ /**
+ * Get name.
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
+ * Is underlying entry directory.
+ *
+ * @return true if underlying entry is directory, false otherwise
+ */
+ boolean isDirectory();
+
+ /**
+ * Do we need to update the entry.
+ *
+ * @return true if update is required, false otherwise
+ */
+ boolean requiresUpdate();
+
+ /**
+ * Read the certificates.
+ */
+ void readCertificates();
+
+ /**
+ * Get entry.
+ *
+ * @return the entry
+ */
+ ZipEntry getEntry();
+
+ /**
+ * Set entry.
+ *
+ * @param entry the entry
+ */
+ void setEntry(ZipEntry entry);
+}
Deleted: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryInputStream.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -1,253 +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;
-
-/**
- * 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>
- * @version $Revision: 1.0 $
- * @deprecated this is no longer used
- */
- at Deprecated
-public class ZipEntryInputStream extends InputStream
-{
- /** Underlying input stream */
- private InputStream delegate;
-
- /** Underlying zip source */
- private ZipFileWrapper zipWrapper;
-
- /** Is stream closed */
- private 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;
- }
-
- /**
- * Close this stream and release zipWrapper
- *
- * @param doClose do we close
- */
- private void streamClosed(boolean doClose)
- {
- if (closed == false && doClose)
- {
- closed = 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
- {
- streamClosed(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
- {
- streamClosed(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
- {
- streamClosed(rc < 0);
- }
- }
-
- /**
- * @see java.io.InputStream#reset
- */
- public synchronized void reset() throws IOException
- {
- boolean ok = false;
- try
- {
- delegate.reset();
- ok = true;
- }
- finally
- {
- streamClosed(ok == false);
- }
- }
-
- /**
- * @see java.io.InputStream#mark
- */
- public synchronized void mark(int readlimit)
- {
- boolean ok = false;
- try
- {
- delegate.mark(readlimit);
- ok = true;
- }
- finally
- {
- streamClosed(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
- {
- streamClosed(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
- {
- streamClosed(ok == false);
- }
- }
-
- /**
- * Close this stream and release zipWrapper
- *
- * @see java.io.InputStream#close
- */
- public void close() throws IOException
- {
- streamClosed(true);
- super.close();
- }
-
- /**
- * Properly release held resources
- */
- protected void finalize() throws Throwable
- {
- try
- {
- close();
- }
- catch(IOException ignored)
- {
- }
- super.finalize();
- }
-
- /**
- * isClosed.
- *
- * @return returns true if closed
- */
- boolean isClosed()
- {
- return closed;
- }
-}
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -49,7 +49,7 @@
super(zipStream, name, lastModified);
}
- InputStream openStream(ZipEntry ent) throws IOException
+ InputStream openStream(ZipEntryInfo info) throws IOException
{
return getRootAsStream();
}
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -198,36 +198,32 @@
/**
* Get the contents of the given <tt>ZipEntry</tt> as stream
*
- * @param entry a zip entry
+ * @param info a zip entry info
* @return an InputStream that locks the file for as long as it's open
* @throws IOException for any error
*/
- synchronized InputStream openStream(ZipEntry entry) throws IOException
+ synchronized InputStream openStream(ZipEntryInfo info) throws IOException
{
// JBVFS-57 JarInputStream composition
- if (entry.isDirectory())
- return recomposeZipAsInputStream(entry.getName());
+ if (info.isDirectory())
+ return recomposeZipAsInputStream(info.getName());
ensureZipFile();
// make sure input stream and certs reader work on the same update
- ZipEntry update = entry;
- if (entry instanceof EntryInfoAdapter)
+ ZipEntry update = info.getEntry();
+ if (info.requiresUpdate())
{
- EntryInfoAdapter adapter = EntryInfoAdapter.class.cast(entry);
- if (adapter.requiresUpdate())
- {
- // we need to update entry, from the new zif file
- update = zipFile.getEntry(entry.getName());
- adapter.updateEntry(update);
- }
+ // we need to update entry, from the new zif file
+ update = zipFile.getEntry(info.getName());
+ info.setEntry(update);
}
InputStream is = zipFile.getInputStream(update);
if (is == null)
- throw new IOException("Entry no longer available: " + entry.getName() + " in file " + file);
+ throw new IOException("Entry no longer available: " + info.getName() + " in file " + file);
- InputStream zis = new CertificateReaderInputStream(entry, this, is);
+ InputStream zis = new CertificateReaderInputStream(info, this, is);
incrementRef();
return zis;
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -110,16 +110,16 @@
}
}
- InputStream openStream(ZipEntry ent) throws IOException
+ InputStream openStream(ZipEntryInfo info) throws IOException
{
// JBVFS-57 JarInputStream composition
- if (ent.isDirectory())
- return recomposeZipAsInputStream(ent.getName());
+ if (info.isDirectory())
+ return recomposeZipAsInputStream(info.getName());
- InMemoryFile memFile = inMemoryFiles.get(ent.getName());
+ InMemoryFile memFile = inMemoryFiles.get(info.getName());
if (memFile == null)
- throw new FileNotFoundException("Failed to find nested jar entry: " + ent.getName() + " in zip stream: " + toString());
+ throw new FileNotFoundException("Failed to find nested jar entry: " + info.getName() + " in zip stream: " + toString());
return new ByteArrayInputStream(memFile.fileBytes);
}
Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-10-14 11:55:37 UTC (rev 94856)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-10-14 12:16:31 UTC (rev 94857)
@@ -169,7 +169,7 @@
* @return InputStream with entry's contents
* @throws IOException for any error
*/
- abstract InputStream openStream(ZipEntry ent) throws IOException;
+ abstract InputStream openStream(ZipEntryInfo ent) throws IOException;
/**
* Get raw bytes of this archive in its compressed form
More information about the jboss-cvs-commits
mailing list