cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charles Canning" <ccann...@hotlinks.com>
Subject RE: [BUGFIX] AdaptiveClassLoader chokes on resources loaded fromcompressed archives
Date Wed, 29 Mar 2000 22:13:14 GMT
Hi,

My quick and dirty bugfix goes like this

    private InputStream loadResourceFromZipfile(File file, String name)
{
        try {
            ZipFile zipfile = new ZipFile(file);
            ZipEntry entry = zipfile.getEntry(name);
            return (entry == null) ? entry :
zipfile.getInputStream(entry);
        } catch(IOException e) {
            return null;
        }
     }

but this leaves the ZIP file open all the time.... the problem is that
there is _no_ absolute way to know where all the released
ZipInputStreams are closed so that it is safe to close the ZIP file.

** This does not seem like a safe solution to me. Try this with your
environment.

/**
 * Loads resource from a zip file
 **/
private InputStream loadResourceFromZipfile(File file, String name)
{
	ZipFile zipfile = null;
      try {
		zipfile = new ZipFile(file);
            ZipEntry entry = zipfile.getEntry(name);

            if (entry != null) {
                return zipfile.getInputStream(entry);
            } else {
                return null;
            }
	}
	catch (ZipException zipEx) {
		//this exception happened on object creation
		zipFile == null;
		return null;
	}
      catch(IOException e) {
		//other exception
		return null;
      } finally {
            if ( zipfile != null ) {
                try {
                    zipfile.close();
                } catch ( IOException ignored ) {
                }
            }
        }
    }

I have not tested this code, but it might solve the problem of leaving files
opened.

Later...
...charles


Mime
View raw message