You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2004/06/07 13:05:03 UTC

DO NOT REPLY [Bug 29365] - Zip file remains open

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29365>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29365

Zip file remains open





------- Additional Comments From dperezcar@fcc.es  2004-06-07 11:05 -------
Under Cocoon 2.1.5 it seems it happens also if using pipeline "a".

Workaround:
-------------

I have made the following generator, that closes the file.  The zip file is
specified through the "source" parameter, whereas the file inside the zip throgh
the "fich" parameter.

package fcc.ima.doc;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.generation.ServiceableGenerator;
import org.apache.excalibur.xml.sax.SAXParser;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import fcc.ima.ruta.ConfigGlobal;

/**Genera a partir de un ZIP.  A diferencia de FileGenerator con protocolo jar:,
cierra el fichero tras usarlo.
 * @author dperezcar */
public class GenZip extends ServiceableGenerator {
   /** @see org.apache.cocoon.generation.Generator#generate() */
   public void generate() throws IOException, SAXException, ProcessingException {
      ZipInputStream is = null;
      String fich = parameters.getParameter("fich", "content.xml");
      is = new ZipInputStream(new BufferedInputStream(new
FileInputStream(ConfigGlobal.i().resuelveRuta(source))));
      try {
         while (true) {
            ZipEntry ze = is.getNextEntry();
            if (ze.getName().equals(fich)) {
               SAXParser parser = null;
               try {
                  parser = (SAXParser) manager.lookup( SAXParser.ROLE);
                  parser.parse(new InputSource(is), super.xmlConsumer);
                  return;
               } finally {
                  manager.release(parser);
               }
            }
         }
      } catch (ServiceException e) {
         throw new ProcessingException(e);
      } finally {
         if (is != null) {
            try {
               is.close();
            } catch (IOException e) {
            }
         }
      }
   }
}