You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Charles Canning <cc...@hotlinks.com> on 2000/03/30 00:13:14 UTC
RE: [BUGFIX] AdaptiveClassLoader chokes on resources loaded fromcompressed archives
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