[jboss-cvs] JBossAS SVN: r77882 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 3 19:42:39 EDT 2008
Author: mstruk
Date: 2008-09-03 19:42:39 -0400 (Wed, 03 Sep 2008)
New Revision: 77882
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
Log:
JBVFS-57 JarInputStream generation for directory entries
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-09-03 23:42:02 UTC (rev 77881)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2008-09-03 23:42:39 UTC (rev 77882)
@@ -112,6 +112,10 @@
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)
@@ -128,24 +132,9 @@
InputStream getRootAsStream() throws FileNotFoundException
{
if (optimizeForMemory)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try
- {
- recomposeZip(baos);
- return new ByteArrayInputStream(baos.toByteArray());
- }
- catch (IOException ex)
- {
- FileNotFoundException e = new FileNotFoundException("Failed to recompose inflated nested archive " + getName());
- e.initCause(ex);
- throw e;
- }
- }
+ return recomposeZipAsInputStream();
else
- {
return super.getRootAsStream();
- }
}
long getSize()
@@ -169,6 +158,11 @@
private void recomposeZip(ByteArrayOutputStream baos) throws IOException
{
+ recomposeZip(baos, "");
+ }
+
+ private void recomposeZip(ByteArrayOutputStream baos, String path) throws IOException
+ {
ZipOutputStream zout = new ZipOutputStream(baos);
zout.setMethod(ZipOutputStream.STORED);
@@ -176,12 +170,36 @@
while(it.hasNext())
{
InMemoryFile memFile = it.next();
- zout.putNextEntry(memFile.entry);
- zout.write(memFile.fileBytes);
+ if (memFile.entry.getName().startsWith(path))
+ {
+ zout.putNextEntry(memFile.entry);
+ zout.write(memFile.fileBytes);
+ }
}
zout.close();
}
+ private InputStream recomposeZipAsInputStream() throws FileNotFoundException
+ {
+ return recomposeZipAsInputStream("");
+ }
+
+ private 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;
+ }
+ }
+
static class InMemoryFile
{
ZipEntry entry;
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2008-09-03 23:42:02 UTC (rev 77881)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARVFSContextUnitTestCase.java 2008-09-03 23:42:39 UTC (rev 77882)
@@ -200,8 +200,8 @@
testInnerEntryOverURL(urlString, "/complex.jar/child", false);
testInnerEntryOverURL(urlString, "/complex.jar/subfolder/subchild", false);
// test folder
- testInnerEntryOverURL(urlString, "/complex.jar/subfolder", true);
- testInnerEntryOverURL(urlString, "/complex.jar/subfolder/subsubfolder", true);
+ testInnerEntryOverURL(urlString, "/complex.jar/subfolder", false);
+ testInnerEntryOverURL(urlString, "/complex.jar/subfolder/subsubfolder", false);
// 3 level zips
url = getResource("/vfs/test/level1.zip");
urlString = url.toExternalForm();
More information about the jboss-cvs-commits
mailing list