xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amin Ahmad" <amin_ahma...@hotmail.com>
Subject PNG renderer not closing output streams properly.
Date Sun, 04 Dec 2005 14:35:50 GMT
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 

            // Encode PNG image
            PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);

View raw message