Hi Team FOP,

I was playing around with the PNG Renderer, and I think I noticed a problem -- when it produces multiple files (one per page) it does not appear to be explicity closing the files it creates. Java GC takes care of closing the files automatically, but, running Java 5, the final file is left open until the JVM terminates.


In the code below from PNGRenderer, on the last line of the for loop, the output stream is flushed but never closed. At the top of the loop, os is reassigned to a new output stream for the next page.

thanks,
Amin


   public void stopRenderer() throws IOException {

       super.stopRenderer();

       for (int i = 0; i < pageViewportList.size(); i++) {

           OutputStream os = getCurrentOutputStream(i);
           if (os == null) {
               log.warn("No filename information available."
                       + " Stopping early after the first page.");
               break;
           }
           // Do the rendering: get the image for this page
RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList
                   .get(i));

           // Encode this image
           log.debug("Encoding page " + (i + 1));
           renderParams = PNGEncodeParam.getDefaultEncodeParam(image);

           // Set resolution
           float pixSzMM = userAgent.getPixelUnitToMillimeter();
           // num Pixs in 1 Meter
           int numPix = (int)((1000 / pixSzMM) + 0.5);
renderParams.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'

           // Encode PNG image
           PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
           encoder.encode(image);
           os.flush();
       }
   }


Reply via email to