FileDocCategorySizeDatePackage
ExtendedNNTPOps.javaAPI DocApache Commons NET 1.4.1 API2710Sat Dec 03 10:05:48 GMT 2005examples.nntp

ExtendedNNTPOps

public class ExtendedNNTPOps extends Object
Simple class showing some of the extended commands (AUTH, XOVER, LIST ACTIVE)
author
Rory Winston

Fields Summary
org.apache.commons.net.nntp.NNTPClient
client
Constructors Summary
public ExtendedNNTPOps()

		client = new NNTPClient();
		client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
	
Methods Summary
public voiddemo(java.lang.String host, java.lang.String user, java.lang.String password)

		try {
			client.connect(host);

			// AUTHINFO USER/AUTHINFO PASS
			boolean success = client.authenticate(user, password);
			if (success) {
				System.out.println("Authentication succeeded");
			} else {
				System.out.println("Authentication failed, error =" + client.getReplyString());
			}

			// XOVER
			NewsgroupInfo testGroup = new NewsgroupInfo();
			client.selectNewsgroup("alt.test", testGroup);
			int lowArticleNumber = testGroup.getFirstArticle();
			int highArticleNumber = lowArticleNumber + 100;
			Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber);

			for (int i = 0; i < articles.length; ++i) {
				System.out.println(articles[i].getSubject());
			}

			// LIST ACTIVE
			NewsgroupInfo[] fanGroups = client.listNewsgroups("alt.fan.*");
			for (int i = 0; i < fanGroups.length; ++i) {
				System.out.println(fanGroups[i].getNewsgroup());
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	
public static voidmain(java.lang.String[] args)

		ExtendedNNTPOps ops;

		if (args.length != 3) {
			System.err.println("usage: ExtendedNNTPOps nntpserver username password");
			System.exit(1);
		}

		ops = new ExtendedNNTPOps();
		ops.demo(args[0], args[1], args[2]);