commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1071102 - in /commons/proper/net/trunk/src/main/java/examples: cidr/ ftp/ mail/ nntp/ ntp/ telnet/ unix/ util/
Date Tue, 15 Feb 2011 23:18:47 GMT
Author: sebb
Date: Tue Feb 15 23:18:47 2011
New Revision: 1071102

URL: http://svn.apache.org/viewvc?rev=1071102&view=rev
Log:
Tidy up examples

Modified:
    commons/proper/net/trunk/src/main/java/examples/cidr/SubnetUtilsExample.java
    commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java
    commons/proper/net/trunk/src/main/java/examples/ftp/FTPSExample.java
    commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java
    commons/proper/net/trunk/src/main/java/examples/mail/POP3Mail.java
    commons/proper/net/trunk/src/main/java/examples/mail/SMTPMail.java
    commons/proper/net/trunk/src/main/java/examples/nntp/MessageThreading.java
    commons/proper/net/trunk/src/main/java/examples/nntp/NNTPUtils.java
    commons/proper/net/trunk/src/main/java/examples/nntp/PostMessage.java
    commons/proper/net/trunk/src/main/java/examples/ntp/NTPClient.java
    commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java
    commons/proper/net/trunk/src/main/java/examples/unix/finger.java
    commons/proper/net/trunk/src/main/java/examples/unix/fwhois.java
    commons/proper/net/trunk/src/main/java/examples/util/IOUtil.java

Modified: commons/proper/net/trunk/src/main/java/examples/cidr/SubnetUtilsExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/cidr/SubnetUtilsExample.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/cidr/SubnetUtilsExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/cidr/SubnetUtilsExample.java Tue Feb 15
23:18:47 2011
@@ -53,7 +53,7 @@ public class SubnetUtilsExample {
         System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(), 
                 Integer.toBinaryString(info.asInteger(info.getHighAddress())));
         
-        System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount());
+        System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount()));
         System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses()));
         
         final String prompt ="Enter an IP address (e.g. 192.168.0.10):"; 

Modified: commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ftp/FTPClientExample.java Tue Feb 15 23:18:47
2011
@@ -127,7 +127,7 @@ __main:
                 break __main;
             }
 
-            System.out.println("Remote system is " + ftp.getSystemName());
+            System.out.println("Remote system is " + ftp.getSystemType());
 
             if (binaryTransfer)
                 ftp.setFileType(FTP.BINARY_FILE_TYPE);

Modified: commons/proper/net/trunk/src/main/java/examples/ftp/FTPSExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ftp/FTPSExample.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ftp/FTPSExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ftp/FTPSExample.java Tue Feb 15 23:18:47
2011
@@ -133,7 +133,7 @@ __main:
             }
 
             
-            System.out.println("Remote system is " + ftps.getSystemName());
+            System.out.println("Remote system is " + ftps.getSystemType());
 
             if (binaryTransfer) ftps.setFileType(FTP.BINARY_FILE_TYPE);
 

Modified: commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java Tue Feb 15 23:18:47
2011
@@ -177,7 +177,9 @@ public final class TFTPExample
                 tftp.close();
                 try
                 {
-                    output.close();
+                    if (output != null) {
+                        output.close();
+                    }
                     closed = true;
                 }
                 catch (IOException e)
@@ -234,7 +236,9 @@ public final class TFTPExample
                 tftp.close();
                 try
                 {
-                    input.close();
+                    if (input != null) {
+                        input.close();
+                    }
                     closed = true;
                 }
                 catch (IOException e)

Modified: commons/proper/net/trunk/src/main/java/examples/mail/POP3Mail.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/mail/POP3Mail.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/mail/POP3Mail.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/mail/POP3Mail.java Tue Feb 15 23:18:47
2011
@@ -115,7 +115,7 @@ public final class POP3Mail
                 System.exit(1);
             }
 
-            for (message = 0; message < messages.length; message++)
+            for (message = 0; message < messages.length; message++) // messages cannot
be null here
             {
                 reader = pop3.retrieveMessageTop(messages[message].number, 0);
 

Modified: commons/proper/net/trunk/src/main/java/examples/mail/SMTPMail.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/mail/SMTPMail.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/mail/SMTPMail.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/mail/SMTPMail.java Tue Feb 15 23:18:47
2011
@@ -25,7 +25,6 @@ import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.List;
 
 import org.apache.commons.net.PrintCommandListener;
@@ -53,7 +52,6 @@ public final class SMTPMail
         Writer writer;
         SimpleSMTPHeader header;
         SMTPClient client;
-        Enumeration en;
 
         if (args.length < 1)
         {
@@ -147,7 +145,9 @@ public final class SMTPMail
                 client.completePendingCommand();
             }
 
-            fileReader.close();
+            if (fileReader != null ) {
+                fileReader.close();
+            }
 
             client.logout();
 

Modified: commons/proper/net/trunk/src/main/java/examples/nntp/MessageThreading.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/nntp/MessageThreading.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/nntp/MessageThreading.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/nntp/MessageThreading.java Tue Feb 15
23:18:47 2011
@@ -36,23 +36,24 @@ public class MessageThreading {
     
     public static void main(String[] args) throws SocketException, IOException {
         
-        if (args.length != 3)
+        if (args.length != 1 && args.length != 3)
             usage();
         
         String hostname = args[0];
-        String user = args[1];
-        String password = args[2];
         
         NNTPClient client = new NNTPClient();
         client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
         client.connect(hostname);
-//      optional authentication
-//        
-//        if(!client.authenticate(user, password)) {
-//            System.out.println("Authentication failed for user " + user + "!");
-//          //  System.exit(1);
-//        }
-//        
+        
+        if (args.length == 3) { // Optional auth       
+            String user = args[1];
+            String password = args[2];
+            if(!client.authenticate(user, password)) {
+                System.out.println("Authentication failed for user " + user + "!");
+                System.exit(1);
+            }
+        }
+
         NewsgroupInfo group = new NewsgroupInfo();
         client.selectNewsgroup("alt.test", group);
         
@@ -71,7 +72,7 @@ public class MessageThreading {
     
     
     public static void usage() {
-        System.out.println("Usage: MessageThreading <hostname> <user> <password>");
+        System.out.println("Usage: MessageThreading <hostname> [<user> <password>]");
         System.exit(0);
     }
 }

Modified: commons/proper/net/trunk/src/main/java/examples/nntp/NNTPUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/nntp/NNTPUtils.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/nntp/NNTPUtils.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/nntp/NNTPUtils.java Tue Feb 15 23:18:47
2011
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
 
-import org.apache.commons.net.io.DotTerminatedMessageReader;
 import org.apache.commons.net.nntp.Article;
 import org.apache.commons.net.nntp.NNTPClient;
 
@@ -49,8 +48,7 @@ public class NNTPUtils {
     throws IOException {
         Reader reader = null;
         List<Article> articles = new ArrayList<Article>();
-        reader =
-            (DotTerminatedMessageReader) client.retrieveArticleInfo(
+        reader = client.retrieveArticleInfo(
                     lowArticleNumber,
                     highArticleNumber);
 
@@ -62,9 +60,6 @@ public class NNTPUtils {
             // Mandatory format (from NNTP RFC 2980) is :
             // Subject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count
 
-            int count = st.countTokens();
-            int index = 0;
-
             while (st.hasMoreTokens()) {
                 String msg = st.nextToken();
                 System.out.println("Message:" + msg);

Modified: commons/proper/net/trunk/src/main/java/examples/nntp/PostMessage.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/nntp/PostMessage.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/nntp/PostMessage.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/nntp/PostMessage.java Tue Feb 15 23:18:47
2011
@@ -108,7 +108,7 @@ public final class PostMessage
             if (organization != null && organization.length() > 0)
                 header.addHeaderField("Organization", organization);
 
-            if (references != null && organization.length() > 0)
+            if (references != null && references.length() > 0)
                 header.addHeaderField("References", references);
 
             header.addHeaderField("X-Newsreader", "NetComponents");
@@ -154,7 +154,9 @@ public final class PostMessage
                 }
             }
 
-            fileReader.close();
+            if (fileReader != null) {
+                fileReader.close();
+            }
 
             client.logout();
 

Modified: commons/proper/net/trunk/src/main/java/examples/ntp/NTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ntp/NTPClient.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ntp/NTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ntp/NTPClient.java Tue Feb 15 23:18:47
2011
@@ -142,7 +142,7 @@ public final class NTPClient
 
     public static final void main(String[] args)
     {
-        if (args == null || args.length == 0) {
+        if (args.length == 0) {
             System.err.println("Usage: NTPClient <hostname-or-address-list>");
             System.exit(1);
         }

Modified: commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/telnet/TelnetClientExample.java Tue Feb
15 23:18:47 2011
@@ -20,7 +20,8 @@ package examples.telnet;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.FileOutputStream;
-import java.io.IOException;
+import java.util.StringTokenizer;
+
 import org.apache.commons.net.telnet.TelnetClient;
 import org.apache.commons.net.telnet.TelnetNotificationHandler;
 import org.apache.commons.net.telnet.SimpleOptionHandler;
@@ -28,7 +29,6 @@ import org.apache.commons.net.telnet.Ech
 import org.apache.commons.net.telnet.TerminalTypeOptionHandler;
 import org.apache.commons.net.telnet.SuppressGAOptionHandler;
 import org.apache.commons.net.telnet.InvalidTelnetOptionException;
-import java.util.StringTokenizer;
 
 
 /***
@@ -53,7 +53,7 @@ public class TelnetClientExample impleme
     /***
      * Main for the TelnetClientExample.
      ***/
-    public static void main(String[] args) throws IOException
+    public static void main(String[] args) throws Exception
     {
         FileOutputStream fout = null;
 

Modified: commons/proper/net/trunk/src/main/java/examples/unix/finger.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/unix/finger.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/unix/finger.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/unix/finger.java Tue Feb 15 23:18:47 2011
@@ -118,6 +118,7 @@ public final class finger
                 try
                 {
                     address = InetAddress.getByName(host);
+                    System.out.println("[" + address.getHostName() + "]");
                 }
                 catch (UnknownHostException e)
                 {
@@ -126,8 +127,6 @@ public final class finger
                 }
             }
 
-            System.out.println("[" + address.getHostName() + "]");
-
             try
             {
                 finger.connect(address);

Modified: commons/proper/net/trunk/src/main/java/examples/unix/fwhois.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/unix/fwhois.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/unix/fwhois.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/unix/fwhois.java Tue Feb 15 23:18:47 2011
@@ -64,6 +64,7 @@ public final class fwhois
         try
         {
             address = InetAddress.getByName(host);
+            System.out.println("[" + address.getHostName() + "]");
         }
         catch (UnknownHostException e)
         {
@@ -71,8 +72,6 @@ public final class fwhois
             System.exit(1);
         }
 
-        System.out.println("[" + address.getHostName() + "]");
-
         try
         {
             whois.connect(address);

Modified: commons/proper/net/trunk/src/main/java/examples/util/IOUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/util/IOUtil.java?rev=1071102&r1=1071101&r2=1071102&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/util/IOUtil.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/util/IOUtil.java Tue Feb 15 23:18:47 2011
@@ -46,6 +46,7 @@ public final class IOUtil
 
         reader = new Thread()
                  {
+                     @Override
                      public void run()
                      {
                          int ch;
@@ -69,6 +70,7 @@ public final class IOUtil
 
         writer = new Thread()
                  {
+                     @Override
                      public void run()
                      {
                          try



Mime
View raw message