src/java.base/share/classes/sun/net/NetProperties.java

Print this page




  45             new PrivilegedAction<Void>() {
  46                 public Void run() {
  47                     loadDefaultProperties();
  48                     return null;
  49                 }});
  50     }
  51 
  52     private NetProperties() { };
  53 
  54 
  55     /*
  56      * Loads the default networking system properties
  57      * the file is in jre/lib/net.properties
  58      */
  59     static private void loadDefaultProperties() {
  60         String fname = System.getProperty("java.home");
  61         if (fname == null) {
  62             throw new Error("Can't find java.home ??");
  63         }
  64         try {
  65             File f = new File(fname, "lib");
  66             f = new File(f, "net.properties");
  67             fname = f.getCanonicalPath();
  68             InputStream in = new FileInputStream(fname);
  69             BufferedInputStream bin = new BufferedInputStream(in);
  70             props.load(bin);
  71             bin.close();
  72         } catch (Exception e) {
  73             // Do nothing. We couldn't find or access the file
  74             // so we won't have default properties...
  75         }
  76     }
  77 
  78     /**
  79      * Get a networking system property. If no system property was defined
  80      * returns the default value, if it exists, otherwise returns
  81      * <code>null</code>.
  82      * @param      key  the property name.
  83      * @throws  SecurityException  if a security manager exists and its
  84      *          <code>checkPropertiesAccess</code> method doesn't allow access
  85      *          to the system properties.




  45             new PrivilegedAction<Void>() {
  46                 public Void run() {
  47                     loadDefaultProperties();
  48                     return null;
  49                 }});
  50     }
  51 
  52     private NetProperties() { };
  53 
  54 
  55     /*
  56      * Loads the default networking system properties
  57      * the file is in jre/lib/net.properties
  58      */
  59     static private void loadDefaultProperties() {
  60         String fname = System.getProperty("java.home");
  61         if (fname == null) {
  62             throw new Error("Can't find java.home ??");
  63         }
  64         try {
  65             File f = new File(fname, "conf");
  66             f = new File(f, "net.properties");
  67             fname = f.getCanonicalPath();
  68             InputStream in = new FileInputStream(fname);
  69             BufferedInputStream bin = new BufferedInputStream(in);
  70             props.load(bin);
  71             bin.close();
  72         } catch (Exception e) {
  73             // Do nothing. We couldn't find or access the file
  74             // so we won't have default properties...
  75         }
  76     }
  77 
  78     /**
  79      * Get a networking system property. If no system property was defined
  80      * returns the default value, if it exists, otherwise returns
  81      * <code>null</code>.
  82      * @param      key  the property name.
  83      * @throws  SecurityException  if a security manager exists and its
  84      *          <code>checkPropertiesAccess</code> method doesn't allow access
  85      *          to the system properties.