cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@us.ibm.com
Subject Re: [BUGFIX] AdaptiveClassLoader chokes on resources loaded from compressed archives
Date Wed, 29 Mar 2000 22:06:23 GMT


Following is the code that Costin put into Tomcat to solve this same
problem:

    /**
     * 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) {
                // workaround - the better solution is to not close the
                // zipfile !!!!
                byte[] data=
loadBytesFromStream(zipfile.getInputStream(entry),
                                                 (int) entry.getSize());
                if(data != null) {
                    InputStream istream = new ByteArrayInputStream(data);
                    return istream;
                }
            }
        } catch(IOException e) {
        } finally {
            // if we close the zipfile bad things will happen - we can't
read the stream
            // on some VMs
            if ( zipfile != null ) {
                try {
                    zipfile.close();
                } catch ( IOException ignored ) {
                }
            }
        }
        // default case
        return null;
    }

- Sam Ruby



Mime
View raw message