You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/03/12 01:55:03 UTC

svn commit: r1080829 - /commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java

Author: sebb
Date: Sat Mar 12 00:55:03 2011
New Revision: 1080829

URL: http://svn.apache.org/viewvc?rev=1080829&view=rev
Log:
Rework to use iterateArticleInfo instead of creating unnecessary List

Modified:
    commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java

Modified: commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java?rev=1080829&r1=1080828&r2=1080829&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/nntp/ExtendedNNTPOps.java Sat Mar 12 00:55:03 2011
@@ -19,7 +19,6 @@ package examples.nntp;
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.util.List;
 
 import org.apache.commons.net.PrintCommandListener;
 import org.apache.commons.net.nntp.Article;
@@ -43,16 +42,18 @@ public class ExtendedNNTPOps {
     }
 
 
-    public void demo(String host, String user, String password) {
+    private void demo(String host, String user, 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());
+            if (user != null && password != null) {
+                boolean success = client.authenticate(user, password);
+                if (success) {
+                    System.out.println("Authentication succeeded");
+                } else {
+                    System.out.println("Authentication failed, error =" + client.getReplyString());
+                }
             }
 
             // XOVER
@@ -60,12 +61,13 @@ public class ExtendedNNTPOps {
             client.selectNewsgroup("alt.test", testGroup);
             long lowArticleNumber = testGroup.getFirstArticle();
             long  highArticleNumber = lowArticleNumber + 100;
-            List<Article> articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber);
+            Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);
 
-            for (Article article : articles) {
-                System.out.println(article.getSubject());
+            if (articles != null) {
+                for (Article article : articles) {
+                    System.out.println(article.getSubject());
+                }
             }
-
             // LIST ACTIVE
             NewsgroupInfo[] fanGroups = client.listNewsgroups("alt.fan.*");
             for (int i = 0; i < fanGroups.length; ++i) {
@@ -80,13 +82,14 @@ public class ExtendedNNTPOps {
     public static void main(String[] args) {
         ExtendedNNTPOps ops;
 
-        if (args.length != 3) {
-            System.err.println("usage: ExtendedNNTPOps nntpserver username password");
+        int argc = args.length;
+        if (argc < 1) {
+            System.err.println("usage: ExtendedNNTPOps nntpserver [username password]");
             System.exit(1);
         }
 
         ops = new ExtendedNNTPOps();
-        ops.demo(args[0], args[1], args[2]);
+        ops.demo(args[0], argc >=3 ? args[1] : null, argc >=3 ? args[2] : null);
     }
 
 }