xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <...@jeremias-maerki.ch>
Subject Re: PNG renderer not closing output streams properly.
Date Tue, 06 Dec 2005 20:36:21 GMT
Thanks for spotting that one. I've just fixed it in Subversion:
http://svn.apache.org/viewcvs?rev=354537&view=rev

On 04.12.2005 15:35:50 Amin Ahmad wrote:
> 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();
>         }
>     }



Jeremias Maerki


Mime
View raw message