You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2022/01/17 10:46:24 UTC

[commons-daemon] 05/05: Remove comments from code for Java 1.4, 1.5 & 1.6 now Java 7 is the min

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git

commit 93060f7de65fd0faadf2fa8db22ed9125485f7fc
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 17 10:43:56 2022 +0000

    Remove comments from code for Java 1.4, 1.5 & 1.6 now Java 7 is the min
---
 src/samples/ProcrunService.java    | 92 +++++++++++++++++++-------------------
 src/samples/SimpleApplication.java | 12 ++---
 src/samples/SimpleDaemon.java      | 12 ++---
 3 files changed, 57 insertions(+), 59 deletions(-)

diff --git a/src/samples/ProcrunService.java b/src/samples/ProcrunService.java
index 4e2d972..13de4a0 100644
--- a/src/samples/ProcrunService.java
+++ b/src/samples/ProcrunService.java
@@ -3,15 +3,15 @@ import java.io.IOException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-//import java.util.Enumeration;
+import java.util.Enumeration;
 import java.util.Iterator;
-//import java.util.List;
-//import java.util.Map;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.TreeSet;
-//import java.net.InterfaceAddress;
-//import java.net.NetworkInterface;
-//import java.net.SocketException;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
 
 
 /*
@@ -92,13 +92,12 @@ public class ProcrunService implements Runnable {
             log("Using context ClassLoader : " + cl.toString());
         log("Program environment: ");
 
-// Java 1.5+ code
-//        Map        em = System.getenv();
-//        TreeSet    es = new TreeSet(em.keySet());
-//        for (Iterator i = es.iterator(); i.hasNext();) {
-//            String n = (String)i.next();
-//            log(n + " ->  " + em.get(n));
-//        }
+        Map<String,String> em = System.getenv();
+        TreeSet<String> es = new TreeSet<>(em.keySet());
+        for (Iterator<String> i = es.iterator(); i.hasNext();) {
+            String n = i.next();
+            log(n + " ->  " + em.get(n));
+        }
 
         log("System properties: ");
         Properties ps = System.getProperties();
@@ -108,40 +107,39 @@ public class ProcrunService implements Runnable {
             log(n + " ->  " + ps.get(n));
         }
 
-// Java 1.6+ code
-//        log("Network interfaces: ");
-//        log("LVPMU (L)oopback (V)irtual (P)ointToPoint (M)multicastSupport (U)p");
-//        try {
-//            for (Enumeration e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
-//                NetworkInterface n = (NetworkInterface)e.nextElement();
-//                char [] flags = { '-', '-', '-', '-', '-'};
-//                if (n.isLoopback())
-//                    flags[0] = 'x';
-//                if (n.isVirtual())
-//                    flags[1] = 'x';
-//                if (n.isPointToPoint())
-//                    flags[2] = 'x';
-//                if (n.supportsMulticast())
-//                    flags[3] = 'x';
-//                if (n.isUp())
-//                    flags[4] = 'x';
-//                String neti = new String(flags) + "   " + n.getName() + "\t";
-//                for (Enumeration i = n.getSubInterfaces(); i.hasMoreElements();) {
-//                    NetworkInterface s = (NetworkInterface)i.nextElement();
-//                    neti += " [" + s.getName() + "]";
-//                }
-//                log(neti + " -> " + n.getDisplayName());
-//                List i = n.getInterfaceAddresses();
-//                if (!i.isEmpty()) {
-//                    for (int x = 0; x < i.size(); x++) {
-//                        InterfaceAddress a = (InterfaceAddress)i.get(x);
-//                        log("        " + a.toString());
-//                    }
-//                }
-//            }
-//        } catch (SocketException e) {
-//            // Ignore
-//        }
+        log("Network interfaces: ");
+        log("LVPMU (L)oopback (V)irtual (P)ointToPoint (M)multicastSupport (U)p");
+        try {
+            for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
+                NetworkInterface n = e.nextElement();
+                char [] flags = { '-', '-', '-', '-', '-'};
+                if (n.isLoopback())
+                    flags[0] = 'x';
+                if (n.isVirtual())
+                    flags[1] = 'x';
+                if (n.isPointToPoint())
+                    flags[2] = 'x';
+                if (n.supportsMulticast())
+                    flags[3] = 'x';
+                if (n.isUp())
+                    flags[4] = 'x';
+                String neti = new String(flags) + "   " + n.getName() + "\t";
+                for (Enumeration<NetworkInterface> i = n.getSubInterfaces(); i.hasMoreElements();) {
+                    NetworkInterface s = i.nextElement();
+                    neti += " [" + s.getName() + "]";
+                }
+                log(neti + " -> " + n.getDisplayName());
+                List<InterfaceAddress> i = n.getInterfaceAddresses();
+                if (!i.isEmpty()) {
+                    for (int x = 0; x < i.size(); x++) {
+                        InterfaceAddress a = i.get(x);
+                        log("        " + a.toString());
+                    }
+                }
+            }
+        } catch (SocketException e) {
+            // Ignore
+        }
     }
 
     /**
diff --git a/src/samples/SimpleApplication.java b/src/samples/SimpleApplication.java
index 71d7680..057dbc6 100644
--- a/src/samples/SimpleApplication.java
+++ b/src/samples/SimpleApplication.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
-//import java.io.UnsupportedEncodingException;
+import java.io.UnsupportedEncodingException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.text.SimpleDateFormat;
@@ -259,11 +259,11 @@ public class SimpleApplication implements Runnable {
 
         public void handle(InputStream in, OutputStream os) {
             PrintStream out=null;
-//            try {
-//                out=new PrintStream(os, true, "US-ASCII"); // Java 1.4+
-//            } catch (UnsupportedEncodingException ex) {
-                out=new PrintStream(os, true);
-//            }
+            try {
+                out=new PrintStream(os, true, "US-ASCII");
+            } catch (UnsupportedEncodingException ex) {
+              out=new PrintStream(os, true);
+            }
 
             while(true) {
                 try {
diff --git a/src/samples/SimpleDaemon.java b/src/samples/SimpleDaemon.java
index 9b4965c..2727e4f 100644
--- a/src/samples/SimpleDaemon.java
+++ b/src/samples/SimpleDaemon.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
-//import java.io.UnsupportedEncodingException;
+import java.io.UnsupportedEncodingException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.text.SimpleDateFormat;
@@ -241,11 +241,11 @@ public class SimpleDaemon implements Daemon, Runnable {
 
         public void handle(InputStream in, OutputStream os) {
             PrintStream out=null;
-//            try {
-//                out=new PrintStream(os, true, "US-ASCII"); // Java 1.4+
-//            } catch (UnsupportedEncodingException ex) {
-                out=new PrintStream(os, true);
-//            }
+            try {
+                out=new PrintStream(os, true, "US-ASCII");
+            } catch (UnsupportedEncodingException ex) {
+              out=new PrintStream(os, true);
+            }
 
             while(true) {
                 try {