directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seelmann <m...@stefan-seelmann.de>
Subject Re: parseLdifFile Run out of memory
Date Wed, 29 Jan 2014 22:53:22 GMT
On 01/29/2014 06:38 PM, eric tse wrote:

> Can you point me out any simple sample java code that demonstrate the most
> basic concept of using "iterate on the reader using reader.next()"?

LdifReader implements java.lang.Iteratable, so you can do the following
(omitting resource handling):


    File file = new File("/path/to/your/file.ldif" );
    LdifReader ldifReader = new LdifReader( file );
    Iterator<LdifEntry> iterator = ldifReader.iterator();
    while(iterator.hasNext()) {
        LdifEntry ldifEntry = iterator.next();
        System.out.println(ldifEntry);
    }
    ldifReader.close();


Or much nicer using Java 7 try-with-resource statement and foreach loop:


    try ( LdifReader ldifReader = new LdifReader( file ) )
    {
        for ( LdifEntry ldifEntry : ldifReader )
        {
            System.out.println( ldifEntry );
        }
    }


HTH,
Stefan


Mime
View raw message