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



--
----------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to