[jboss-cvs] JBossAS SVN: r90212 - in projects/vfs/trunk: src/main/java/org/jboss/virtual/plugins/context/zip and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 15 16:10:11 EDT 2009
Author: alesj
Date: 2009-06-15 16:10:11 -0400 (Mon, 15 Jun 2009)
New Revision: 90212
Modified:
projects/vfs/trunk/pom.xml
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/ZipStreamWrapper.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/jdk/JDKZipProvider.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java
Log:
Add ZEP::close.
Modified: projects/vfs/trunk/pom.xml
===================================================================
--- projects/vfs/trunk/pom.xml 2009-06-15 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/pom.xml 2009-06-15 20:10:11 UTC (rev 90212)
@@ -94,6 +94,20 @@
</configuration>
</plugin>
</plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-idea-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
</build>
<reporting>
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 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-06-15 20:10:11 UTC (rev 90212)
@@ -391,61 +391,75 @@
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ZipFactory factory = ZipUtils.getFactory();
+ ZipEntry entry;
+ String longestNameMatch = null;
// first we need to find best/longest name
ZipEntryProvider zis = factory.createProvider(bais);
- ZipEntry entry;
- String longestNameMatch = null;
- while((entry = zis.getNextEntry()) != null)
+ try
{
- String entryName = entry.getName();
- String match = entryName;
- if (entry.isDirectory())
- match = match.substring(0, match.length() - 1);
+ while((entry = zis.getNextEntry()) != null)
+ {
+ String entryName = entry.getName();
+ String match = entryName;
+ if (entry.isDirectory())
+ match = match.substring(0, match.length() - 1);
- if (relative.startsWith(match))
- {
- if (match.equals(relative))
+ if (relative.startsWith(match))
{
- if (entry.isDirectory())
+ if (match.equals(relative))
{
- this.rootEntryPath = relative;
- return new ZipDirWrapper(zis.currentStream(), entryName, System.currentTimeMillis(), bais);
+ if (entry.isDirectory())
+ {
+ this.rootEntryPath = relative;
+ return new ZipDirWrapper(zis.currentStream(), entryName, System.currentTimeMillis(), bais);
+ }
+ else if (JarUtils.isArchive(match) == false)
+ {
+ return new ZipEntryWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
+ }
+ else
+ {
+ return new ZipStreamWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
+ }
}
- else if (JarUtils.isArchive(match) == false)
+
+ if (longestNameMatch == null || longestNameMatch.length() < entryName.length())
{
- return new ZipEntryWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
+ longestNameMatch = entryName; // keep entry name
}
- else
- {
- return new ZipStreamWrapper(zis.currentStream(), entryName, System.currentTimeMillis());
- }
}
-
- if (longestNameMatch == null || longestNameMatch.length() < entryName.length())
- {
- longestNameMatch = entryName; // keep entry name
- }
}
+ if (longestNameMatch == null)
+ throw new IllegalArgumentException("Cannot find entry: " + is + ", " + relative);
}
- if (longestNameMatch == null)
- throw new IllegalArgumentException("Cannot find entry: " + is + ", " + relative);
+ finally
+ {
+ zis.close();
+ }
// do recursion on relative
bais.reset();
zis = factory.createProvider(bais);
- while((entry = zis.getNextEntry()) != null)
+ try
{
- String entryName = entry.getName();
- if (entryName.equals(longestNameMatch))
+ while((entry = zis.getNextEntry()) != null)
{
- if (urlInfo != null)
- urlInfo.relativePath = longestNameMatch;
+ String entryName = entry.getName();
+ if (entryName.equals(longestNameMatch))
+ {
+ if (urlInfo != null)
+ urlInfo.relativePath = longestNameMatch;
- relative = relative.substring(longestNameMatch.length() + 1);
- return findEntry(zis.currentStream(), relative, null);
+ relative = relative.substring(longestNameMatch.length() + 1);
+ return findEntry(zis.currentStream(), relative, null);
+ }
}
}
+ finally
+ {
+ zis.close();
+ }
throw new IllegalArgumentException("No such entry: " + is + ", " + relative);
}
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 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipStreamWrapper.java 2009-06-15 20:10:11 UTC (rev 90212)
@@ -85,25 +85,32 @@
ZipFactory factory = ZipUtils.getFactory();
ZipEntryProvider zis = factory.createProvider(super.getRootAsStream());
- ZipEntry ent = zis.getNextEntry();
- while (ent != null)
+ try
{
- byte [] fileBytes;
- if (ent.isDirectory() == false)
+ ZipEntry ent = zis.getNextEntry();
+ while (ent != null)
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- VFSUtils.copyStream(zis.currentStream(), baos);
- fileBytes = baos.toByteArray();
- ent.setSize(fileBytes.length);
+ byte [] fileBytes;
+ if (ent.isDirectory() == false)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ VFSUtils.copyStreamAndClose(zis.currentStream(), baos);
+ fileBytes = baos.toByteArray();
+ ent.setSize(fileBytes.length);
+ }
+ else
+ {
+ fileBytes = new byte[0];
+ }
+
+ inMemoryFiles.put(ent.getName(), new InMemoryFile(ent, fileBytes));
+ ent = zis.getNextEntry();
}
- else
- {
- fileBytes = new byte[0];
- }
-
- inMemoryFiles.put(ent.getName(), new InMemoryFile(ent, fileBytes));
- ent = zis.getNextEntry();
}
+ finally
+ {
+ zis.close();
+ }
if (optimizeForMemory) {
initZipSize();
Modified: 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 2009-06-15 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/ZipEntryProvider.java 2009-06-15 20:10:11 UTC (rev 90212)
@@ -34,4 +34,6 @@
ZipEntry getNextEntry() throws IOException;
InputStream currentStream() throws IOException;
+
+ void close() throws IOException;
}
\ No newline at end of file
Modified: 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 2009-06-15 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jdk/JDKZipProvider.java 2009-06-15 20:10:11 UTC (rev 90212)
@@ -51,6 +51,74 @@
public InputStream currentStream()
{
- return zis;
+ return new IgnoreCloseInputStream(zis);
}
+
+ public void close() throws IOException
+ {
+ zis.close();
+ }
+
+ private static class IgnoreCloseInputStream extends InputStream
+ {
+ private InputStream delegate;
+
+ private IgnoreCloseInputStream(InputStream zis)
+ {
+ this.delegate = zis;
+ }
+
+ public int read() throws IOException
+ {
+ return delegate.read();
+ }
+
+ @Override
+ public boolean markSupported()
+ {
+ return delegate.markSupported();
+ }
+
+ @Override
+ public void reset() throws IOException
+ {
+ delegate.reset();
+ }
+
+ @Override
+ public void mark(int readlimit)
+ {
+ delegate.mark(readlimit);
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ // no-op
+ }
+
+ @Override
+ public int available() throws IOException
+ {
+ return delegate.available();
+ }
+
+ @Override
+ public long skip(long n) throws IOException
+ {
+ return delegate.skip(n);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ return delegate.read(b, off, len);
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException
+ {
+ return delegate.read(b);
+ }
+ }
}
\ No newline at end of file
Modified: 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 2009-06-15 19:20:56 UTC (rev 90211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/zip/jzipfile/JZipFileZipEntryProvider.java 2009-06-15 20:10:11 UTC (rev 90212)
@@ -73,4 +73,9 @@
final org.jboss.jzipfile.ZipEntry current = this.current;
return current == null ? null : Zip.openEntry(tempFile, current);
}
+
+ public void close() throws IOException
+ {
+ current = null;
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list