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.


   public void stopRenderer() throws IOException {


       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.");
           // Do the rendering: get the image for this page
RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList

           // 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);

Reply via email to