< prev index next >

src/java.base/unix/classes/sun/net/sdp/SdpProvider.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.sdp;
  27 
  28 import sun.net.NetHooks;
  29 import java.net.InetAddress;
  30 import java.net.Inet4Address;
  31 import java.net.UnknownHostException;
  32 import java.util.*;
  33 import java.io.File;
  34 import java.io.FileDescriptor;
  35 import java.io.IOException;
  36 import java.io.PrintStream;
  37 import java.security.AccessController;
  38 
  39 import sun.net.sdp.SdpSupport;
  40 import sun.security.action.GetPropertyAction;
  41 
  42 /**
  43  * A NetHooks provider that converts sockets from the TCP to SDP protocol prior
  44  * to binding or connecting.
  45  */
  46 
  47 public class SdpProvider extends NetHooks.Provider {
  48     // maximum port
  49     private static final int MAX_PORT = 65535;
  50 
  51     // indicates if SDP is enabled and the rules for when the protocol is used
  52     private final boolean enabled;
  53     private final List<Rule> rules;
  54 
  55     // logging for debug purposes
  56     private PrintStream log;
  57 
  58     public SdpProvider() {
  59         // if this property is not defined then there is nothing to do.
  60         String file = AccessController.doPrivileged(
  61             new GetPropertyAction("com.sun.sdp.conf"));
  62         if (file == null) {
  63             this.enabled = false;
  64             this.rules = null;
  65             return;
  66         }
  67 
  68         // load configuration file
  69         List<Rule> list = null;
  70         if (file != null) {
  71             try {
  72                 list = loadRulesFromFile(file);
  73             } catch (IOException e) {
  74                 fail("Error reading %s: %s", file, e.getMessage());
  75             }
  76         }
  77 
  78         // check if debugging is enabled
  79         PrintStream out = null;
  80         String logfile = AccessController.doPrivileged(
  81             new GetPropertyAction("com.sun.sdp.debug"));
  82         if (logfile != null) {
  83             out = System.out;
  84             if (logfile.length() > 0) {
  85                 try {
  86                     out = new PrintStream(logfile);
  87                 } catch (IOException ignore) { }
  88             }
  89         }
  90 
  91         this.enabled = !list.isEmpty();
  92         this.rules = list;
  93         this.log = out;
  94     }
  95 
  96     // supported actions
  97     private static enum Action {
  98         BIND,
  99         CONNECT;
 100     }
 101 




  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.sdp;
  27 
  28 import sun.net.NetHooks;
  29 import java.net.InetAddress;
  30 import java.net.Inet4Address;
  31 import java.net.UnknownHostException;
  32 import java.util.*;
  33 import java.io.File;
  34 import java.io.FileDescriptor;
  35 import java.io.IOException;
  36 import java.io.PrintStream;

  37 
  38 import sun.net.sdp.SdpSupport;
  39 import sun.security.action.GetPropertyAction;
  40 
  41 /**
  42  * A NetHooks provider that converts sockets from the TCP to SDP protocol prior
  43  * to binding or connecting.
  44  */
  45 
  46 public class SdpProvider extends NetHooks.Provider {
  47     // maximum port
  48     private static final int MAX_PORT = 65535;
  49 
  50     // indicates if SDP is enabled and the rules for when the protocol is used
  51     private final boolean enabled;
  52     private final List<Rule> rules;
  53 
  54     // logging for debug purposes
  55     private PrintStream log;
  56 
  57     public SdpProvider() {
  58         // if this property is not defined then there is nothing to do.
  59         String file = GetPropertyAction.getProperty("com.sun.sdp.conf");

  60         if (file == null) {
  61             this.enabled = false;
  62             this.rules = null;
  63             return;
  64         }
  65 
  66         // load configuration file
  67         List<Rule> list = null;
  68         if (file != null) {
  69             try {
  70                 list = loadRulesFromFile(file);
  71             } catch (IOException e) {
  72                 fail("Error reading %s: %s", file, e.getMessage());
  73             }
  74         }
  75 
  76         // check if debugging is enabled
  77         PrintStream out = null;
  78         String logfile = GetPropertyAction.getProperty("com.sun.sdp.debug");

  79         if (logfile != null) {
  80             out = System.out;
  81             if (logfile.length() > 0) {
  82                 try {
  83                     out = new PrintStream(logfile);
  84                 } catch (IOException ignore) { }
  85             }
  86         }
  87 
  88         this.enabled = !list.isEmpty();
  89         this.rules = list;
  90         this.log = out;
  91     }
  92 
  93     // supported actions
  94     private static enum Action {
  95         BIND,
  96         CONNECT;
  97     }
  98 


< prev index next >