[jdom-commits] Memory Errors in JDOM

Smith, Jonathan jsmith4 at PaineWebber.com
Thu Jul 20 07:52:32 PDT 2000


Funy thing. I had a DOM program writing a 8MB file out and then I changed it to JDOM and I am getting the following error

C:\data\projects\XMLRead>jdom > jdom_out.xml
Exception in thread "main" java.lang.OutOfMemoryError

C:\data\projects\XMLRead>

Below is a sample of the code I am using

import netscape.ldap.*;
import netscape.ldap.util.*;
import netscape.ldap.client.*;

import org.jdom.*;
import org.jdom.output.*;


import java.util.*;
import java.io.*;

/**
 * You can use this class for outputting LDAP Data into XML format.  
 * 
 * To use this class just pass this class to the LDAPRunner and it will format
 * the data from the LDAP server in XML format
 * 
 *    PLEASE TAKE NOTE THAT THIS CLASS IS USING JDOM
 *    JDOM WAS IN BETA VERSION AT THE TIME THIS CLASS
 *    WAS MADE.
 *
 * @author Johnathan Mark Smith
 * @since 7.20.2000
 */
public class LDAPJDOMXMLEntryDisplayer implements LDAPWorker
{
    
    static boolean firstime = true;
    Element root;
    
    void printHander()
    {
        root = new Element("entrys");
        firstime = false;
    }
    
    public void finalize()
    {
        Document doc = new Document(root);
        XMLOutputter outputter = new XMLOutputter();
        try
        {
            outputter.output(doc, System.out);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
    
	public void processLDAPEntry(LDAPEntry entry, String[] Attributes)
	{
	        Element XMLEntery = new Element("entry");
	        
	        if(firstime)
	        {
	            printHander();
	        }
	        
	        for ( int i = 0; i < Attributes.length; i++ )
	        {
                LDAPAttribute attr = entry.getAttribute( Attributes[i]);
                Element item = null;
                
                if ( attr != null )
                {
                    Enumeration enumVals = attr.getStringValues();
                    boolean hasVals = false;
                    while ( (enumVals != null) &&  enumVals.hasMoreElements() )
                    {
                        String val = (String)enumVals.nextElement();
                        item = new Element(Attributes[i]);
                        item.setContent(val);
                        hasVals = true;
                        XMLEntery.addChild(item);
                    }   
                }                    
            } 
            root.addChild(XMLEntery);
     }
}


Johnathan Mark Smith
Messaging & Collaboration
PaineWebber Incorporated
1000 Harbor Boulevard, 6th Floor
Weehawken, NJ 07087-6791
Phone: 201.352.1387
Fax: 201.902.5273
E-mail: jsmith4 at painewebber.com




More information about the jdom-commits mailing list