public byte[] generateImage(InputStream xml, InputStream xslt) throws BuilderException
        {
        
                // OUTPUT STREAM CREATION
                // we use a ByteArray because we don't want to generate any file
ByteArrayOutputStream mtiff= new ByteArrayOutputStream(); // don't need to be closed
                                                                                
                                                //don't need finally statement
if(logger.isDebugEnabled()) logger.debug("<<<Memòria màxima inici:"+Runtime.getRuntime().maxMemory()/1048576d); if(logger.isDebugEnabled()) logger.debug("<<<Memòria lliure inici:"+Runtime.getRuntime().freeMemory()/1048576d); if(logger.isDebugEnabled()) logger.debug("<<<Memòria total inici:"+Runtime.getRuntime().totalMemory()/1048576d);

                // CONFIG
                TransformerFactory transfFactory= 
TransformerFactory.newInstance();
                Transformer transformer= null;
                try
                {
                        transformer= transfFactory.newTransformer(new 
StreamSource(xslt));
                }
                catch (TransformerConfigurationException e)
                {
                        throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e);
                }
                Source src= new StreamSource(xml);

                // FOP CREATION
                // desired output format
                FopFactory fopFactory= FopFactory.newInstance();
                FOUserAgent userAgent= new FOUserAgent(fopFactory);
                
userAgent.setTargetResolution(ImageProperties.MTIFF_TARGET_RESOLUTION);

                Fop fop;
                try
                {
                        fop = fopFactory.newFop(MimeConstants.MIME_TIFF, 
userAgent, mtiff);
                }
                catch (FOPException e2)
                {
                        e2.printStackTrace();
                        throw new BuilderException("No s'ha pogut construir 
l'objecte Fop.", e2);
                }

                // RESULT OBJECT CREATION
                Result res= null;
                try
                {
                        DefaultHandler dh= fop.getDefaultHandler();
                        res= new SAXResult(dh);
                }
                catch (FOPException e1)
                {
                        throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e1);                      
                }

                // TRANSFORMATION AND TIFF GENERATION
                try
                {
                        transformer.transform(src, res);
                }
                catch (TransformerException e)
                {
                        throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e);                       
                }
if(logger.isDebugEnabled()) logger.debug(">>>Memòria màxima fi:"+Runtime.getRuntime().maxMemory()/1048576d); if(logger.isDebugEnabled()) logger.debug(">>>Memòria lliure fi:"+Runtime.getRuntime().freeMemory()/1048576d); if(logger.isDebugEnabled()) logger.debug(">>>Memòria total fi:"+Runtime.getRuntime().totalMemory()/1048576d);
                return mtiff.toByteArray();
        }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to