0

I am doing a POC for one of my performance projects. Currently I'm facing an OutOfMemoryError. First we had loaded an XML file using DOM and then attempted to transform it with XSL into a PDF. After reading one of the comments from this forum, I switched to a SAX parser but it still gives the same error.

The file is 30MB and the System Memory is 512MB.

System.out.println("FOP XMLTOPDFConverter\n");
            System.out.println("Preparing...");

            // Setup directories
/*          File baseDir = new File(".");
            File outDir = new File(baseDir, "out");
            outDir.mkdirs();*/

            // Setup input and output files
            File xmlfile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/File_0000036357.XML");
            File xsltfile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/UCB110037EventList.xsl");
            File pdffile = new File("C:/Documents and Settings/agarwgau/Desktop/300k/ResultXML2PDF.pdf");

            System.out.println("Input: XML (" + xmlfile + ")");
            System.out.println("Stylesheet: " + xsltfile);
            System.out.println("Output: PDF (" + pdffile + ")");
            System.out.println();
            System.out.println("Transforming...");

            // configure fopFactory as desired
            FopFactory fopFactory = FopFactory.newInstance();

            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
            // configure foUserAgent as desired

            // Setup output
            OutputStream out = new java.io.FileOutputStream(pdffile);
            out = new java.io.BufferedOutputStream(out);

            try {
                // Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
                        foUserAgent, out);

                // Setup XSLT
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory
                        .newTransformer(new StreamSource(xsltfile));

                // Set the value of a <param> in the stylesheet
                transformer.setParameter("versionParam", "2.0");

                // Setup input for XSLT transformation
                Source src = new StreamSource(xmlfile);

                // Resulting SAX events (the generated FO) must be piped through
                // to FOP
                Result res = new SAXResult(fop.getDefaultHandler());

                // Start XSLT transformation and FOP processing
                transformer.transform(src, res);
            } finally {
                out.close();
            }

            System.out.println("Success!");
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }

    }
Matthew Cline
  • 2,312
  • 1
  • 19
  • 36
  • 1
    What kind of OutOfMemory error is it ? "Java Heap space" ? If so, maybe you could try expanding the size of the heap using the -Xms (min heap space) and -Xmx (max heap space) VM arguments ? – Jalayn Nov 08 '11 at 10:08
  • I have increased the size till 1024 and then also it gives me Java Heap Space OOMemory . I have also implemented this –  Nov 08 '11 at 10:38
  • This will get ported across to SO proper - but in the mean time what version of the JDK are you using? You should be able to attach jconsole/visualvm to understand where the memory is leaking/expanding beyond your limits. Yes you could move bits of code around etc, but I think it's a good opportunity to use the right tools to 'measure before guessing' – Martijn Verburg Nov 08 '11 at 10:02
  • It is giving me OOOMemory Error at the time when we called " transformer.transform(src, res);" –  Nov 08 '11 at 10:04

1 Answers1

2

Maybe this will help: http://xmlgraphics.apache.org/fop/1.0/running.html#memory

soulcheck
  • 36,297
  • 6
  • 91
  • 90