[jboss-cvs] JBossAS SVN: r90199 - in projects/vfs/trunk: src/main/java/org/jboss/virtual/plugins/context/zip and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 15 12:24:55 EDT 2009
Author: alesj
Date: 2009-06-15 12:24:55 -0400 (Mon, 15 Jun 2009)
New Revision: 90199
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntry.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntryProvider.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFactory.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFile.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipEntry.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFactory.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFile.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipProvider.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntry.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFactory.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFile.java
Modified:
projects/vfs/trunk/pom.xml
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
Log:
[JBVFS-114]; abstract zip reading.
Modified: projects/vfs/trunk/pom.xml
===================================================================
--- projects/vfs/trunk/pom.xml 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/pom.xml 2009-06-15 16:24:55 UTC (rev 90199)
@@ -29,6 +29,8 @@
</organization>
<properties>
+ <version.jboss.jzipfile>1.0.0-SNAPSHOT</version.jboss.jzipfile>
+ <version.jboss.truezip>6.6</version.jboss.truezip>
<version.jboss.common.core>2.2.13.GA</version.jboss.common.core>
<version.jboss.logging>2.0.5.GA</version.jboss.logging>
<version.jboss.test>1.1.0.GA</version.jboss.test>
@@ -111,6 +113,16 @@
<dependencies>
<dependency>
+ <groupId>org.jboss.jzipfile</groupId>
+ <artifactId>jzipfile</artifactId>
+ <version>${version.jboss.jzipfile}</version>
+ </dependency>
+ <dependency>
+ <groupId>de.schlichtherle.io</groupId>
+ <artifactId>truezip</artifactId>
+ <version>${version.jboss.truezip}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-common-core</artifactId>
<version>${version.jboss.common.core}</version>
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -21,13 +21,16 @@
*/
package org.jboss.virtual.plugins.context.zip;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ByteArrayInputStream;
import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+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
*
@@ -57,11 +60,13 @@
{
zisCopy.reset();
// TODO - optimize this
- ZipInputStream zis = new ZipInputStream(zisCopy);
+ 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;
+
+ return zis.currentStream();
}
Enumeration<? extends ZipEntry> entries() throws IOException
@@ -75,12 +80,13 @@
*/
private class DirEnumeration implements Enumeration<ZipEntry>
{
- private ZipInputStream zis;
+ private ZipEntryProvider zis;
private ZipEntry entry;
- private DirEnumeration()
+ private DirEnumeration() throws IOException
{
- this.zis = new ZipInputStream(zisCopy);
+ ZipFactory factory = ZipUtils.getFactory();
+ this.zis = factory.createProvider(zisCopy);
}
public boolean hasMoreElements()
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -37,20 +37,18 @@
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.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
import org.jboss.logging.Logger;
import org.jboss.virtual.VFSUtils;
@@ -64,8 +62,12 @@
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.VFSContextConstraints;
+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}
@@ -388,8 +390,10 @@
VFSUtils.copyStreamAndClose(is, baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ZipFactory factory = ZipUtils.getFactory();
+
// first we need to find best/longest name
- ZipInputStream zis = new ZipInputStream(bais);
+ ZipEntryProvider zis = factory.createProvider(bais);
ZipEntry entry;
String longestNameMatch = null;
while((entry = zis.getNextEntry()) != null)
@@ -406,15 +410,15 @@
if (entry.isDirectory())
{
this.rootEntryPath = relative;
- return new ZipDirWrapper(zis, entryName, System.currentTimeMillis(), bais);
+ return new ZipDirWrapper(zis.currentStream(), entryName, System.currentTimeMillis(), bais);
}
else if (JarUtils.isArchive(match) == false)
{
- return new ZipEntryWrapper(zis, entryName, System.currentTimeMillis());
+ return new ZipEntryWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
}
else
{
- return new ZipStreamWrapper(zis, entryName, System.currentTimeMillis());
+ return new ZipStreamWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
}
}
@@ -429,7 +433,7 @@
// do recursion on relative
bais.reset();
- zis = new ZipInputStream(bais);
+ zis = factory.createProvider(bais);
while((entry = zis.getNextEntry()) != null)
{
String entryName = entry.getName();
@@ -439,7 +443,7 @@
urlInfo.relativePath = longestNameMatch;
relative = relative.substring(longestNameMatch.length() + 1);
- return findEntry(zis, relative, null);
+ return findEntry(zis.currentStream(), relative, null);
}
}
throw new IllegalArgumentException("No such entry: " + is + ", " + relative);
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -24,8 +24,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
-import java.util.zip.ZipEntry;
+import org.jboss.virtual.spi.zip.ZipEntry;
+
/**
* ZipEntryWrapper - for abstracted access to in-memory entry
*
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -31,12 +31,14 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
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
@@ -172,7 +174,8 @@
{
if (zipFile == null)
{
- zipFile = new ZipFile(file);
+ ZipFactory factory = ZipUtils.getFactory();
+ zipFile = factory.createFile(file);
if (forceNoReaper == false && noReaperOverride == false)
ZipFileLockReaper.getInstance().register(this);
}
@@ -358,7 +361,7 @@
if(newName.length() == 0)
continue;
- ZipEntry newEntry = new ZipEntry(newName);
+ java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(newName);
newEntry.setComment(oldEntry.getComment());
newEntry.setTime(oldEntry.getTime());
newEntry.setSize(oldEntry.getSize());
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -21,9 +21,6 @@
*/
package org.jboss.virtual.plugins.context.zip;
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VFSUtils;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
@@ -36,10 +33,15 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
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
*
@@ -81,7 +83,8 @@
{
super(zipStream, name, lastModified);
- ZipInputStream zis = new ZipInputStream(super.getRootAsStream());
+ ZipFactory factory = ZipUtils.getFactory();
+ ZipEntryProvider zis = factory.createProvider(super.getRootAsStream());
ZipEntry ent = zis.getNextEntry();
while (ent != null)
{
@@ -89,7 +92,7 @@
if (ent.isDirectory() == false)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStream(zis, baos);
+ VFSUtils.copyStream(zis.currentStream(), baos);
fileBytes = baos.toByteArray();
ent.setSize(fileBytes.length);
}
@@ -177,7 +180,7 @@
if(newName.length() == 0)
continue;
- ZipEntry newEntry = new ZipEntry(newName);
+ java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(newName);
newEntry.setComment(oldEntry.getComment());
newEntry.setTime(oldEntry.getTime());
newEntry.setSize(oldEntry.getSize());
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-06-15 15:39:37 UTC (rev 90198)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -28,9 +28,9 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
-import java.util.zip.ZipEntry;
import org.jboss.logging.Logger;
+import org.jboss.virtual.spi.zip.ZipEntry;
/**
* ZipWrapper represents abstracted access to zip archive
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntry.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntry.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,52 @@
+/*
+ * 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.spi.zip;
+
+/**
+ * Zip entry abstraction.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ZipEntry
+{
+ String getName();
+
+ boolean isDirectory();
+
+ long getTime();
+
+ void setTime(long time);
+
+ long getSize();
+
+ void setSize(long size);
+
+ String getComment();
+
+ void setComment(String comment);
+
+ long getCrc();
+
+ void setCrc(long crc);
+
+ Object unwrap();
+}
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntryProvider.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntryProvider.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntryProvider.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,37 @@
+/*
+ * 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.spi.zip;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Zip entry provider abstraction.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ZipEntryProvider
+{
+ ZipEntry getNextEntry() throws IOException;
+
+ InputStream currentStream() throws IOException;
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFactory.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFactory.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,38 @@
+/*
+ * 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.spi.zip;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Zip factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ZipFactory
+{
+ ZipEntryProvider createProvider(InputStream is) throws IOException;
+
+ ZipFile createFile(File file) throws IOException;
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFile.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipFile.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,40 @@
+/*
+ * 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.spi.zip;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * Zip file abstraction.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ZipFile
+{
+ InputStream getInputStream(ZipEntry entry) throws IOException;
+
+ void close() throws IOException;
+
+ Enumeration<? extends ZipEntry> entries();
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipUtils.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipUtils.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,40 @@
+/*
+ * 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.spi.zip;
+
+import org.jboss.virtual.spi.zip.jdk.JDKZipFactory;
+
+/**
+ * Zip utils.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ZipUtils
+{
+ //private static ZipFactory factory = new JZipFileZipFactory();
+ private static ZipFactory factory = new JDKZipFactory();
+
+ public static ZipFactory getFactory()
+ {
+ return factory;
+ }
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipEntry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipEntry.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipEntry.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,95 @@
+/*
+ * 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.spi.zip.jdk;
+
+import org.jboss.virtual.spi.zip.ZipEntry;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JDKZipEntry implements ZipEntry
+{
+ private java.util.zip.ZipEntry entry;
+
+ public JDKZipEntry(java.util.zip.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 long getTime()
+ {
+ return entry.getTime();
+ }
+
+ public void setTime(long time)
+ {
+ entry.setTime(time);
+ }
+
+ public long getSize()
+ {
+ return entry.getSize();
+ }
+
+ public void setSize(long size)
+ {
+ entry.setSize(size);
+ }
+
+ public String getComment()
+ {
+ return entry.getComment();
+ }
+
+ public void setComment(String comment)
+ {
+ entry.setComment(comment);
+ }
+
+ public long getCrc()
+ {
+ return entry.getCrc();
+ }
+
+ public void setCrc(long crc)
+ {
+ entry.setCrc(crc);
+ }
+
+ public Object unwrap()
+ {
+ return entry;
+ }
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFactory.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFactory.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,48 @@
+/*
+ * 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.spi.zip.jdk;
+
+import java.io.InputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipInputStream;
+
+import org.jboss.virtual.spi.zip.ZipFactory;
+import org.jboss.virtual.spi.zip.ZipEntryProvider;
+import org.jboss.virtual.spi.zip.ZipFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JDKZipFactory implements ZipFactory
+{
+ public ZipEntryProvider createProvider(InputStream is)
+ {
+ ZipInputStream zis = new ZipInputStream(is);
+ return new JDKZipProvider(zis);
+ }
+
+ public ZipFile createFile(File file) throws IOException
+ {
+ return new JDKZipFile(new java.util.zip.ZipFile(file));
+ }
+}
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFile.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipFile.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,74 @@
+/*
+ * 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.spi.zip.jdk;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+
+import org.jboss.virtual.spi.zip.ZipEntry;
+import org.jboss.virtual.spi.zip.ZipFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JDKZipFile implements ZipFile
+{
+ private java.util.zip.ZipFile file;
+
+ public JDKZipFile(java.util.zip.ZipFile file)
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+
+ this.file = file;
+ }
+
+ public InputStream getInputStream(ZipEntry entry) throws IOException
+ {
+ Object unwrap = entry.unwrap();
+ return file.getInputStream(java.util.zip.ZipEntry.class.cast(unwrap));
+ }
+
+ public void close() throws IOException
+ {
+ file.close();
+ }
+
+ public Enumeration<? extends ZipEntry> entries()
+ {
+ final Enumeration<? extends java.util.zip.ZipEntry> entries = file.entries();
+ return new Enumeration<ZipEntry>()
+ {
+ public boolean hasMoreElements()
+ {
+ return entries.hasMoreElements();
+ }
+
+ public ZipEntry nextElement()
+ {
+ java.util.zip.ZipEntry entry = entries.nextElement();
+ return entry != null ? new JDKZipEntry(entry) : null;
+ }
+ };
+ }
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipProvider.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipProvider.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipProvider.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,56 @@
+/*
+ * 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.spi.zip.jdk;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipInputStream;
+
+import org.jboss.virtual.spi.zip.ZipEntry;
+import org.jboss.virtual.spi.zip.ZipEntryProvider;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JDKZipProvider implements ZipEntryProvider
+{
+ private ZipInputStream zis;
+
+ public JDKZipProvider(ZipInputStream zis)
+ {
+ if (zis == null)
+ throw new IllegalArgumentException("Null Zip input stream.");
+
+ this.zis = zis;
+ }
+
+ public ZipEntry getNextEntry() throws IOException
+ {
+ java.util.zip.ZipEntry entry = zis.getNextEntry();
+ return entry != null ? new JDKZipEntry(entry) : null;
+ }
+
+ public InputStream currentStream()
+ {
+ return zis;
+ }
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntry.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntry.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,90 @@
+/*
+ * 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.spi.zip.jzipfile;
+
+import org.jboss.virtual.spi.zip.ZipEntry;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JZipFileZipEntry implements ZipEntry
+{
+ private org.jboss.jzipfile.ZipEntry entry;
+
+ public JZipFileZipEntry(org.jboss.jzipfile.ZipEntry entry)
+ {
+ if (entry == null)
+ throw new IllegalArgumentException("Null entry");
+ this.entry = entry;
+ }
+
+ public String getName()
+ {
+ return entry.getName();
+ }
+
+ public boolean isDirectory()
+ {
+ return false; // TODO
+ }
+
+ public long getTime()
+ {
+ return entry.getModificationTime();
+ }
+
+ public void setTime(long time)
+ {
+ }
+
+ public long getSize()
+ {
+ return entry.getSize();
+ }
+
+ public void setSize(long size)
+ {
+ }
+
+ public String getComment()
+ {
+ return entry.getComment();
+ }
+
+ public void setComment(String comment)
+ {
+ }
+
+ public long getCrc()
+ {
+ return entry.getCrc32();
+ }
+
+ public void setCrc(long crc)
+ {
+ }
+
+ public Object unwrap()
+ {
+ return entry;
+ }
+}
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,74 @@
+/*
+ * 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.spi.zip.jzipfile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.jzipfile.Zip;
+import org.jboss.jzipfile.ZipCatalog;
+import org.jboss.virtual.spi.zip.ZipEntry;
+import org.jboss.virtual.spi.zip.ZipEntryProvider;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JZipFileZipEntryProvider implements ZipEntryProvider
+{
+ private InputStream copy;
+ private List<org.jboss.jzipfile.ZipEntry> entries;
+ private int index;
+ private int size;
+
+ public JZipFileZipEntryProvider(InputStream is) throws IOException
+ {
+ if (is == null)
+ throw new IllegalArgumentException("Null input stream");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStreamAndClose(is, baos);
+ copy = new ByteArrayInputStream(baos.toByteArray());
+
+ ZipCatalog catalog = Zip.readCatalog(is);
+ entries = new ArrayList<org.jboss.jzipfile.ZipEntry>(catalog.allEntries());
+ size = entries.size();
+ }
+
+ public ZipEntry getNextEntry() throws IOException
+ {
+ if (index >= size)
+ return null;
+
+ org.jboss.jzipfile.ZipEntry entry = entries.get(index++);
+ return new JZipFileZipEntry(entry);
+ }
+
+ public InputStream currentStream() throws IOException
+ {
+ return Zip.openEntry(copy, entries.get(index));
+ }
+}
\ No newline at end of file
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFactory.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFactory.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,46 @@
+/*
+ * 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.spi.zip.jzipfile;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.virtual.spi.zip.ZipEntryProvider;
+import org.jboss.virtual.spi.zip.ZipFactory;
+import org.jboss.virtual.spi.zip.ZipFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JZipFileZipFactory implements ZipFactory
+{
+ public ZipEntryProvider createProvider(InputStream is) throws IOException
+ {
+ return new JZipFileZipEntryProvider(is);
+ }
+
+ public ZipFile createFile(File file) throws IOException
+ {
+ return new JZipFileZipFile(file);
+ }
+}
Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFile.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipFile.java 2009-06-15 16:24:55 UTC (rev 90199)
@@ -0,0 +1,80 @@
+/*
+ * 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.spi.zip.jzipfile;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+import org.jboss.jzipfile.Zip;
+import org.jboss.jzipfile.ZipCatalog;
+import org.jboss.virtual.spi.zip.ZipEntry;
+import org.jboss.virtual.spi.zip.ZipFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JZipFileZipFile implements ZipFile
+{
+ private File file;
+ private ZipCatalog catalog;
+
+ public JZipFileZipFile(File file) throws IOException
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+ this.file = file;
+ catalog = Zip.readCatalog(file);
+ }
+
+ public InputStream getInputStream(ZipEntry entry) throws IOException
+ {
+ Object unwrap = entry.unwrap();
+ return Zip.openEntry(file, org.jboss.jzipfile.ZipEntry.class.cast(unwrap));
+ }
+
+ public void close() throws IOException
+ {
+ }
+
+ public Enumeration<? extends ZipEntry> entries()
+ {
+ Collection<org.jboss.jzipfile.ZipEntry> entries = catalog.allEntries();
+ final Iterator<org.jboss.jzipfile.ZipEntry> iterator = entries.iterator();
+ return new Enumeration<ZipEntry>()
+ {
+ public boolean hasMoreElements()
+ {
+ return iterator.hasNext();
+ }
+
+ public ZipEntry nextElement()
+ {
+ org.jboss.jzipfile.ZipEntry entry = iterator.next();
+ return entry != null ? new JZipFileZipEntry(entry) : null;
+ }
+ };
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list