xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Suresh Kumar <SaiSuresh.Ku...@friendslife.co.uk>
Subject Heap Space Error
Date Tue, 04 Jun 2013 07:02:16 GMT
Hi Team,

I have encountered a bug(heap space error) during the generation of the Irmak which will use
xalan2.jar and its classes to generate it. We are sending an XML document to the class's method
as below.

We are getting an out of memory error once it reached to transforms.performTransforms(input);

For a 1.35mb file its giving heap space error, we have tried increasing heapsize to 512mb,
then also its not working.

We have tried increasing it to 768mb. Then it is working.

So can you please provide us any alternative solution for it.

import org.apache.xml.security.Init;
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.transforms.Transforms;
import org.bouncycastle.util.encoders.Base64;
import org.w3c.dom.Document;

public static String CalculatorIRmark(String inputFile, String namespace)
    throws Exception

    FileInputStream fis = null;
    StringBuffer filedata = new StringBuffer("");

    try {
      fis = new FileInputStream(inputFile);
      System.out.println("File is in process to read to create IRMark");
    } catch (FileNotFoundException e) {
      logger.error("The file " + inputFile + " could not be opened.");

    byte[] data = null;
    try {
      int bytes = fis.available();

      data = new byte[bytes];

    } catch (IOException e) {
      logger.error("Error reading file for IR Mark.");


    String transformStr = "<?xml version='1.0'?>\n<dsig:Transforms xmlns:dsig='http://www.w3.org/2000/09/xmldsig#'
xmlns:gt='http://www.govtalk.gov.uk/CM/envelope' xmlns:ir='" + namespace + "'>\n" + "<dsig:Transform
Algorithm='http://www.w3.org/TR/1999/REC-xpath-19991116'>\n" + "<dsig:XPath>\n" +
+ " and count(self::ir:IRmark)=0 \n" + " and count(../self::ir:IRmark)=0 \n" + "</dsig:XPath>\n"
+ "</dsig:Transform>\n" + "<dsig:Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments'/>\n"
+ "</dsig:Transforms>\n";

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new ByteArrayInputStream(transformStr.getBytes()));

    Transforms transforms = new Transforms(doc.getDocumentElement(), null);

    XMLSignatureInput input = new XMLSignatureInput(data);

    long heapMaxSize = Runtime.getRuntime().maxMemory();
    long availableMemory = Runtime.getRuntime().freeMemory();
      System.out.println("heapMaxSize: "+heapMaxSize+"---"+heapMaxSize/1024);
      logger.info("heapMaxSize: "+heapMaxSize+"---");
      System.out.println("Available Memory: "+availableMemory);

    XMLSignatureInput result = transforms.performTransforms(input);

    availableMemory = Runtime.getRuntime().freeMemory();
    System.out.println("Available Memory after transformations: "+availableMemory);

    MessageDigest md = MessageDigest.getInstance("SHA");
    byte[] digest = md.digest();

  //  System.out.println("md.digest()"+digest.toString());

    String strIRmark = new String(Base64.encode(digest));

    return strIRmark;
    catch(Exception e)
      System.out.println("Exception is in IRMARK generation");

      StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        logger.error("Calculate Exception: "+sw);

      return "Error In Irmark";

Thanks & Regards
Sai Suresh Kumar

Please consider the environment before printing

This e-mail may contain confidential information and/or copyright material. This e-mail and
its contents are confidential to the intended recipient only. Any unauthorised use may be

If you receive this e-mail by mistake please advise the sender immediately by using the reply
facility in your e-mail software and delete this email.

Friends Life is a business name of the following Friends Life companies:

Friends Life and Pensions Limited Company number 475201
Friends Life Limited Company number 4096141
Friends Life Marketing Limited Company number 5059179
Friends Life Investment Solutions Limited Company number 6389025
Friends Life WL Limited Company number 3116645
Friends Life Services Limited Company number 3424940 
Friends Life Company Limited  Company number 3291349 
Friends Annuities Limited Company number  6363657

Each of the above companies is authorised and regulated by the Financial Services Authority.

Friends Life Management Services Limited Company number 983330 is an appointed representative
of Friends Life Services Limited, Friends Life and Pensions Limited and Friends Life Limited
which are authorised and regulated by the Financial Services Authority.

Suntrust Limited Company number 1460956

Each company is registered in England and Wales with a registered office at Pixham End, Dorking,
Surrey RH4 1QA.

Visit www.friendslife.co.uk to see how our online services can help you

View raw message