import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
 * Demonstrates how to do control the batchsize when using list()
 *
 * usage: java Batchsize
 */
class Batchsize {
    public static void main(String[] args) {

	// Set up environment for creating initial context
	Hashtable env = new Hashtable(11);
	env.put(Context.INITIAL_CONTEXT_FACTORY, 
	    "com.sun.jndi.ldap.LdapCtxFactory");
	env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

	// Set the batch size to 10
	env.put("java.naming.batchsize", "10");

	try {
	    // Create initial context
	    DirContext ctx = new InitialDirContext(env);

	    // Perform list
	    NamingEnumeration answer = ctx.list("ou=People"); 
		
	    // Print the answer
	    while (answer.hasMore()) {
		System.out.println(((NameClassPair)answer.next()).getName());
	    }
	} catch (NamingException e) {
	    e.printStackTrace();
	}
    }
}
