[jboss-cvs] JBossAS SVN: r74543 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 13 12:54:04 EDT 2008
Author: alesj
Date: 2008-06-13 12:54:03 -0400 (Fri, 13 Jun 2008)
New Revision: 74543
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java
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/ZipStreamWrapper.java
Log:
OO programming.
Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java (from rev 74540, 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/ZipBytesWrapper.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java 2008-06-13 16:54:03 UTC (rev 74543)
@@ -0,0 +1,102 @@
+/*
+* 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;
+
+/**
+ * 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
+{
+ /** Raw zip archive loaded in memory */
+ private byte [] zipBytes;
+
+ /** Name */
+ private String name;
+
+ /**
+ * 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 IOException for any error
+ */
+ ZipBytesWrapper(InputStream zipStream, String name, long lastModified) throws IOException
+ {
+ // read the contents into memory buffer
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ZipEntryContext.copyStreamAndClose(zipStream, bout);
+ zipBytes = bout.toByteArray();
+
+ // TODO - delegate file meta info operations to parent?
+ this.name = name;
+ this.lastModified = lastModified;
+ }
+
+ boolean exists()
+ {
+ return true;
+ }
+
+ long getLastModified()
+ {
+ return lastModified;
+ }
+
+ String getName()
+ {
+ return name;
+ }
+
+ long getSize()
+ {
+ return zipBytes.length;
+ }
+
+ InputStream getRootAsStream() throws FileNotFoundException
+ {
+ return new ByteArrayInputStream(zipBytes);
+ }
+
+ void acquire() throws IOException
+ {
+ }
+
+ void close()
+ {
+ zipBytes = null;
+ }
+
+ public String toString()
+ {
+ return super.toString() + " - " + name;
+ }
+}
\ No newline at end of file
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 2008-06-13 16:47:42 UTC (rev 74542)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java 2008-06-13 16:54:03 UTC (rev 74543)
@@ -21,9 +21,6 @@
*/
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.util.Enumeration;
@@ -34,85 +31,34 @@
*
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
*/
-class ZipEntryWrapper extends ZipWrapper
+class ZipEntryWrapper extends ZipBytesWrapper
{
private static final EmptyEnumeration emptyEnumeration = new EmptyEnumeration();
- /** Raw zip archive loaded in memory */
- private byte [] zipBytes;
-
- /** Name */
- private String name;
-
/**
* ZipStreamWrapper is not aware of actual zip source so it can not detect
* if it's been modified, like ZipFileWrapper does.
*
- * @param zipStream
+ * @param zipStream the current zip input stream
+ * @param name the name
* @param lastModified passed by zip stream provider - constant value
- * @throws java.io.IOException
+ * @throws java.io.IOException for any error
*/
ZipEntryWrapper(InputStream zipStream, String name, long lastModified) throws IOException
{
- // read the contents into memory buffer
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ZipEntryContext.copyStreamAndClose(zipStream, bout);
- zipBytes = bout.toByteArray();
-
- // TODO - delegate file meta info operations to parent?
- this.name = name;
- this.lastModified = lastModified;
+ super(zipStream, name, lastModified);
}
- boolean exists()
- {
- return true;
- }
-
- long getLastModified()
- {
- return lastModified;
- }
-
- String getName()
- {
- return name;
- }
-
- long getSize()
- {
- return zipBytes.length;
- }
-
InputStream openStream(ZipEntry ent) throws IOException
{
return getRootAsStream();
}
- InputStream getRootAsStream() throws FileNotFoundException
- {
- return new ByteArrayInputStream(zipBytes);
- }
-
- void acquire() throws IOException
- {
- }
-
Enumeration<? extends ZipEntry> entries() throws IOException
{
return emptyEnumeration;
}
- void close()
- {
- zipBytes = null;
- }
-
- public String toString()
- {
- return super.toString() + " - " + name;
- }
-
/**
* Zip stream enumeration.
*/
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 2008-06-13 16:47:42 UTC (rev 74542)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2008-06-13 16:54:03 UTC (rev 74543)
@@ -32,57 +32,25 @@
* @author <a href="strukelj at parsek.net">Marko Strukelj</a>
* @version $Revision: 1.0 $
*/
-class ZipStreamWrapper extends ZipWrapper
+class ZipStreamWrapper extends ZipBytesWrapper
{
- /** Raw zip archive loaded in memory */
- private byte [] zipBytes;
-
- /** Name */
- private String name;
-
/**
* ZipStreamWrapper is not aware of actual zip source so it can not detect
* if it's been modified, like ZipFileWrapper does.
*
- * @param zipStream
+ * @param zipStream the current zip stream
+ * @param name the name
* @param lastModified passed by zip stream provider - constant value
- * @throws IOException
+ * @throws IOException for any error
*/
ZipStreamWrapper(InputStream zipStream, String name, long lastModified) throws IOException
{
- // read the contents into memory buffer
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- ZipEntryContext.copyStreamAndClose(zipStream, bout);
- zipBytes = bout.toByteArray();
-
- // TODO - delegate file meta info operations to parent?
- this.name = name;
- this.lastModified = lastModified;
+ super(zipStream, name, lastModified);
}
- boolean exists()
- {
- return true;
- }
-
- long getLastModified()
- {
- return lastModified;
- }
-
- String getName()
- {
- return name;
- }
-
- long getSize()
- {
- return zipBytes.length;
- }
-
InputStream openStream(ZipEntry ent) throws IOException
{
- ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes));
+ ZipInputStream zis = new ZipInputStream(getRootAsStream());
// first find the entry
ZipEntry entry = zis.getNextEntry();
@@ -93,37 +61,17 @@
entry = zis.getNextEntry();
}
if(entry == null)
- throw new IOException("Failed to find nested jar entry: " + ent.getName() + " in zip stream: " + this.name);
+ throw new IOException("Failed to find nested jar entry: " + ent.getName() + " in zip stream: " + toString());
-
// then read it
- return new SizeLimitedInputStream(zis, (int) ent.getSize());
+ return new SizeLimitedInputStream(zis, ent.getSize());
}
- InputStream getRootAsStream() throws FileNotFoundException
- {
- return new ByteArrayInputStream(zipBytes);
- }
-
- void acquire() throws IOException
- {
- }
-
Enumeration<? extends ZipEntry> entries() throws IOException
{
- return new ZipStreamEnumeration(new ZipInputStream(new ByteArrayInputStream(zipBytes)));
+ return new ZipStreamEnumeration(new ZipInputStream(getRootAsStream()));
}
- void close()
- {
- zipBytes = null;
- }
-
- public String toString()
- {
- return super.toString() + " - " + name;
- }
-
/**
* Zip stream enumeration.
*/
More information about the jboss-cvs-commits
mailing list