harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r493040 [6/11] - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java: java/net/ org/apache/harmony/luni/util/
Date Fri, 05 Jan 2007 14:44:06 GMT
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelector.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelector.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelector.java Fri Jan  5 06:44:04 2007
@@ -36,96 +36,95 @@
  */
 public abstract class ProxySelector {
 
-	private static ProxySelector defaultSelector = new ProxySelectorImpl();
-
-	/*
-	 * "getProxySelector" permission. getDefault method requires this
-	 * permission.
-	 */
-	private final static NetPermission getProxySelectorPermission = new NetPermission(
-			"getProxySelector");
-
-	/*
-	 * "setProxySelector" permission. setDefault method requires this
-	 * permission.
-	 */
-	private final static NetPermission setProxySelectorPermission = new NetPermission(
-			"setProxySelector");
-
-	/**
-	 * Constructor method.
-	 */
-	public ProxySelector() {
-
-	}
-
-	/**
-	 * Gets system default <code>ProxySelector</code>.
-	 * 
-	 * @return system default <code>ProxySelector</code>.
-	 * @throws SecurtiyException
-	 *             If a security manager is installed and it doesn't have
-	 *             <code>NetPermission("getProxySelector")</code>.
-	 */
-	public static ProxySelector getDefault() {
-		SecurityManager sm = System.getSecurityManager();
-		if (null != sm) {
-			sm.checkPermission(getProxySelectorPermission);
-		}
-		return defaultSelector;
-	}
-
-	/**
-	 * Sets system default <code>ProxySelector</code>. Unsets system default
-	 * <code>ProxySelector</code> if <code>selector</code> is null.
-	 * 
-	 * @throws SecurtiyException
-	 *             If a security manager is installed and it doesn't have
-	 *             <code>NetPermission("setProxySelector")</code>.
-	 */
-	public static void setDefault(ProxySelector selector) {
-		SecurityManager sm = System.getSecurityManager();
-		if (null != sm) {
-			sm.checkPermission(setProxySelectorPermission);
-		}
-		defaultSelector = selector;
-	}
-
-	/**
-	 * Gets applicable proxies based on the accessing protocol of
-	 * <code>uri</code>. The format of URI is defined as below:
-	 * <li>http URI stands for http connection.</li>
-	 * <li>https URI stands for https connection.</li>
-	 * <li>ftp URI stands for ftp connection.</li>
-	 * <li>socket:://ip:port URI stands for tcp client sockets connection.</li>
-	 * 
-	 * @param uri
-	 *            the destination <code>URI</code> object.
-	 * @return a list contains all applicable proxies. If no proxy is available,
-	 *         returns a list only contains one element
-	 *         <code>Proxy.NO_PROXY</code>.
-	 * @throws IllegalArgumentException
-	 *             If any argument is null.
-	 */
-	public abstract List<Proxy> select(URI uri);
-
-	/**
-	 * If the connection can not be established to the proxy server, this method
-	 * will be called. An implementation may adjust proxy the sequence of
-	 * proxies returned by <code>select(String, String)</code>.
-	 * 
-	 * @param uri
-	 *            the <code>URI</code> that the connection fails to connect
-	 *            to.
-	 * @param sa
-	 *            <code>SocketAddress</code> of the proxy.
-	 * @param ioe
-	 *            The <code>IOException</code> which is thrown during
-	 *            connection establishment.
-	 * @throws IllegalArgumentException
-	 *             If any argument is null.
-	 */
-	public abstract void connectFailed(URI uri, SocketAddress sa,
-			IOException ioe);
+    private static ProxySelector defaultSelector = new ProxySelectorImpl();
 
+    /*
+     * "getProxySelector" permission. getDefault method requires this
+     * permission.
+     */
+    private final static NetPermission getProxySelectorPermission = new NetPermission(
+            "getProxySelector"); //$NON-NLS-1$
+
+    /*
+     * "setProxySelector" permission. setDefault method requires this
+     * permission.
+     */
+    private final static NetPermission setProxySelectorPermission = new NetPermission(
+            "setProxySelector"); //$NON-NLS-1$
+
+    /**
+     * Constructor method.
+     */
+    public ProxySelector() {
+        super();
+    }
+
+    /**
+     * Gets system default <code>ProxySelector</code>.
+     * 
+     * @return system default <code>ProxySelector</code>.
+     * @throws SecurtiyException
+     *             If a security manager is installed and it doesn't have
+     *             <code>NetPermission("getProxySelector")</code>.
+     */
+    public static ProxySelector getDefault() {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(getProxySelectorPermission);
+        }
+        return defaultSelector;
+    }
+
+    /**
+     * Sets system default <code>ProxySelector</code>. Unsets system default
+     * <code>ProxySelector</code> if <code>selector</code> is null.
+     * 
+     * @throws SecurtiyException
+     *             If a security manager is installed and it doesn't have
+     *             <code>NetPermission("setProxySelector")</code>.
+     */
+    public static void setDefault(ProxySelector selector) {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(setProxySelectorPermission);
+        }
+        defaultSelector = selector;
+    }
+
+    /**
+     * Gets applicable proxies based on the accessing protocol of
+     * <code>uri</code>. The format of URI is defined as below:
+     * <li>http URI stands for http connection.</li>
+     * <li>https URI stands for https connection.</li>
+     * <li>ftp URI stands for ftp connection.</li>
+     * <li>socket:://ip:port URI stands for tcp client sockets connection.</li>
+     * 
+     * @param uri
+     *            the destination <code>URI</code> object.
+     * @return a list contains all applicable proxies. If no proxy is available,
+     *         returns a list only contains one element
+     *         <code>Proxy.NO_PROXY</code>.
+     * @throws IllegalArgumentException
+     *             If any argument is null.
+     */
+    public abstract List<Proxy> select(URI uri);
+
+    /**
+     * If the connection can not be established to the proxy server, this method
+     * will be called. An implementation may adjust proxy the sequence of
+     * proxies returned by <code>select(String, String)</code>.
+     * 
+     * @param uri
+     *            the <code>URI</code> that the connection fails to connect
+     *            to.
+     * @param sa
+     *            <code>SocketAddress</code> of the proxy.
+     * @param ioe
+     *            The <code>IOException</code> which is thrown during
+     *            connection establishment.
+     * @throws IllegalArgumentException
+     *             If any argument is null.
+     */
+    public abstract void connectFailed(URI uri, SocketAddress sa,
+            IOException ioe);
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java Fri Jan  5 06:44:04 2007
@@ -28,266 +28,264 @@
  */
 class ProxySelectorImpl extends ProxySelector {
 
-	private static final int HTTP_PROXY_PORT = 80;
+    private static final int HTTP_PROXY_PORT = 80;
 
-	private static final int HTTPS_PROXY_PORT = 443;
+    private static final int HTTPS_PROXY_PORT = 443;
 
-	private static final int FTP_PROXY_PORT = 80;
+    private static final int FTP_PROXY_PORT = 80;
 
-	private static final int SOCKS_PROXY_PORT = 1080;
+    private static final int SOCKS_PROXY_PORT = 1080;
 
-	public ProxySelectorImpl() {
-		super();
-	}
+    public ProxySelectorImpl() {
+        super();
+    }
 
-	@Override
+    @Override
     public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
-		if (null == uri || null == sa || null == ioe) {
+        if (null == uri || null == sa || null == ioe) {
             // "KA001=Argument must not be null"
-			throw new IllegalArgumentException(Msg.getString("KA001")); //$NON-NLS-1$
-		}
-	}
+            throw new IllegalArgumentException(Msg.getString("KA001")); //$NON-NLS-1$
+        }
+    }
 
-	@Override
+    @Override
     public List<Proxy> select(URI uri) {
-		// argument check
-		if (null == uri) {
-            // "KA001=Argument must not be null"
+        // argument check
+        if (null == uri) {
+            // KA001=Argument must not be null
             throw new IllegalArgumentException(Msg.getString("KA001")); //$NON-NLS-1$
-		}
-		// check scheme
-		String scheme = uri.getScheme();
-		if (null == scheme) {
-			throw new IllegalArgumentException();
-		}
-        
-		String host = uri.getHost();
-		Proxy proxy = Proxy.NO_PROXY;
-
-		if ("http".equals(scheme)) { //$NON-NLS-1$
-			proxy = selectHttpProxy(host);
-		} else if ("https".equals(scheme)) { //$NON-NLS-1$
-			proxy = selectHttpsProxy();
-		} else if ("ftp".equals(scheme)) { //$NON-NLS-1$
-			proxy = selectFtpProxy(host);
-		} else if ("socket".equals(scheme)) { //$NON-NLS-1$
-			proxy = selectSocksProxy();
-		}
-		List<Proxy> proxyList = new ArrayList<Proxy>(1);
-		proxyList.add(proxy);
-		return proxyList;
-	}
-
-	/*
-	 * Gets proxy for http request. 1. gets from "http.proxyHost", then gets
-	 * port from "http.proxyPort", or from "proxyPort" if "http.proxyPort" is
-	 * unavailable. 2. gets from "proxyHost" if 1 is unavailable,then get port
-	 * from "proxyPort", or from "http.proxyPort" if "proxyPort" is unavailable.
-	 * 3. gets from "socksProxyHost" if 2 is unavailable.
-	 */
-
-	private Proxy selectHttpProxy(String uriHost) {
-		String host; 
-		String port = null;
-		Proxy.Type type = Proxy.Type.DIRECT;
-
-		String nonProxyHosts = getSystemProperty("http.nonProxyHosts"); //$NON-NLS-1$
-		// if host is in non proxy host list, returns Proxy.NO_PROXY
-		if (isNonProxyHost(uriHost, nonProxyHosts)) {
-			return Proxy.NO_PROXY;
-		}
-		
-		host = getSystemProperty("http.proxyHost"); //$NON-NLS-1$
-		if (null != host) {
-			// case 1: http.proxyHost is set, use exact http proxy
-			type = Proxy.Type.HTTP;
-			port = getSystemPropertyOrAlternative("http.proxyPort", //$NON-NLS-1$
-					"proxyPort", String.valueOf(HTTP_PROXY_PORT)); //$NON-NLS-1$
-		} else if((host = getSystemProperty("proxyHost", null)) !=  null) {
-			// case 2: proxyHost is set, use exact http proxy
-			type = Proxy.Type.HTTP;
-			port = getSystemPropertyOrAlternative("proxyPort", //$NON-NLS-1$
-					"http.proxyPort", String.valueOf(HTTP_PROXY_PORT)); //$NON-NLS-1$
-			
-		}else if((host = getSystemProperty("socksProxyHost"))!=null){
-			// case 3: use socks proxy instead
-			type = Proxy.Type.SOCKS;
-			port = getSystemProperty(
-					"socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
-		}
-		int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
-				: HTTP_PROXY_PORT;
-		return createProxy(type, host, port, defaultPort);
-	}
-
-	/*
-	 * Gets proxy for https request.
-	 */
-	private Proxy selectHttpsProxy() {
-		String host ; 
-		String port = null;
-		Proxy.Type type = Proxy.Type.DIRECT;
-		
-		host = getSystemProperty("https.proxyHost");
-		if (null != host) {
-			// case 1: use exact https proxy
-			type = Proxy.Type.HTTP;
-			port = getSystemProperty(
-					"https.proxyPort", String.valueOf(HTTPS_PROXY_PORT)); //$NON-NLS-1$
-		} else {
-			host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
-			if (null != host) {
-				// case 2: use socks proxy instead
-				type = Proxy.Type.SOCKS;
-				port = getSystemProperty(
-						"socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
-			}
-		}
-		int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
-				: HTTPS_PROXY_PORT;
-		return createProxy(type, host, port, defaultPort);
-	}
-
-	/*
-	 * Gets proxy for ftp request.
-	 */
-
-	private Proxy selectFtpProxy(String uriHost) {
-		String host;
-		String port = null;
-		Proxy.Type type = Proxy.Type.DIRECT;
-		String nonProxyHosts = getSystemProperty("ftp.nonProxyHosts"); //$NON-NLS-1$
-		// if host is in non proxy host list, returns Proxy.NO_PROXY
-		if (isNonProxyHost(uriHost, nonProxyHosts)) {
-			return Proxy.NO_PROXY;
-		}
-		
-		host = getSystemProperty("ftp.proxyHost");
-		if (null != host) {
-			// case 1: use exact ftp proxy
-			type = Proxy.Type.HTTP;
-			port = getSystemProperty(
-					"ftp.proxyPort", String.valueOf(FTP_PROXY_PORT)); //$NON-NLS-1$
-		} else {
-			host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
-			if (null != host) {
-				// case 2: use socks proxy instead
-				type = Proxy.Type.SOCKS;
-				port = getSystemProperty(
-						"socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
-			}
-		}
-		int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
-				: FTP_PROXY_PORT;
-		return createProxy(type, host, port, defaultPort);
-	}
-
-	/*
-	 * Gets proxy for socks request.
-	 */
-	private Proxy selectSocksProxy() {
-		String host;
-		String port = null;
-		Proxy.Type type = Proxy.Type.DIRECT;
-		
-		host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
-		if (null != host) {
-			type = Proxy.Type.SOCKS;
-			port = getSystemProperty(
-					"socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
-		}
-		return createProxy(type, host, port, SOCKS_PROXY_PORT);
-	}
-
-	/*
-	 * checks whether the host needs proxy. return true if it doesn't need a
-	 * proxy.
-	 */
-	private boolean isNonProxyHost(String host, String nonProxyHosts) {
-		// nonProxyHosts is not set
-		if (null == nonProxyHosts) {
-			return false;
-		}
-		// Construct regex expression of nonProxyHosts
-		int length = nonProxyHosts.length();
-		char ch;
-		StringBuilder buf = new StringBuilder(length);
-		for (int i = 0; i < nonProxyHosts.length(); i++) {
-			ch = nonProxyHosts.charAt(i);
-			switch (ch) {
-			case '.':
-				buf.append("\\.");
-				break;
-			case '*':
-				buf.append(".*");
-				break;
-			default:
-				buf.append(ch);
-			}
-		}
-		String nonProxyHostsReg = buf.toString();
-		// check whether the host is the nonProxyHosts.
-		return host.matches(nonProxyHostsReg);
-	}
-
-	/*
-	 * Create Proxy by "type","host" and "port".
-	 */
-	private Proxy createProxy(Proxy.Type type, String host, String port,
-			int defaultPort) {
-		Proxy proxy;
-		if (type == Proxy.Type.DIRECT) {
-			proxy = Proxy.NO_PROXY;
-		} else {
-			int iPort;
-			try {
-				iPort = Integer.valueOf(port).intValue();
-			} catch (NumberFormatException e) {
-				iPort = defaultPort;
-			}
-			proxy = new Proxy(type, InetSocketAddress.createUnresolved(host,
-					iPort));
-		}
-		return proxy;
-	}
-
-	/*
-	 * gets system property, privileged operation. If the value of the property
-	 * is null or empty String, it returns defaultValue.
-	 */
-	private String getSystemProperty(final String property) {
-		return getSystemProperty(property, null);
-	}
-
-	/*
-	 * gets system property, privileged operation. If the value of the property
-	 * is null or empty String, it returns defaultValue.
-	 */
-	private String getSystemProperty(final String property,
-			final String defaultVaule) {
-		String value = AccessController.doPrivileged(
-                new PriviAction<String>(property));
-        if (null == value || "".equals(value)) {
+        }
+        // check scheme
+        String scheme = uri.getScheme();
+        if (null == scheme) {
+            throw new IllegalArgumentException();
+        }
+
+        String host = uri.getHost();
+        Proxy proxy = Proxy.NO_PROXY;
+
+        if ("http".equals(scheme)) { //$NON-NLS-1$
+            proxy = selectHttpProxy(host);
+        } else if ("https".equals(scheme)) { //$NON-NLS-1$
+            proxy = selectHttpsProxy();
+        } else if ("ftp".equals(scheme)) { //$NON-NLS-1$
+            proxy = selectFtpProxy(host);
+        } else if ("socket".equals(scheme)) { //$NON-NLS-1$
+            proxy = selectSocksProxy();
+        }
+        List<Proxy> proxyList = new ArrayList<Proxy>(1);
+        proxyList.add(proxy);
+        return proxyList;
+    }
+
+    /*
+     * Gets proxy for http request. 1. gets from "http.proxyHost", then gets
+     * port from "http.proxyPort", or from "proxyPort" if "http.proxyPort" is
+     * unavailable. 2. gets from "proxyHost" if 1 is unavailable,then get port
+     * from "proxyPort", or from "http.proxyPort" if "proxyPort" is unavailable.
+     * 3. gets from "socksProxyHost" if 2 is unavailable.
+     */
+
+    private Proxy selectHttpProxy(String uriHost) {
+        String host;
+        String port = null;
+        Proxy.Type type = Proxy.Type.DIRECT;
+
+        String nonProxyHosts = getSystemProperty("http.nonProxyHosts"); //$NON-NLS-1$
+        // if host is in non proxy host list, returns Proxy.NO_PROXY
+        if (isNonProxyHost(uriHost, nonProxyHosts)) {
+            return Proxy.NO_PROXY;
+        }
+
+        host = getSystemProperty("http.proxyHost"); //$NON-NLS-1$
+        if (null != host) {
+            // case 1: http.proxyHost is set, use exact http proxy
+            type = Proxy.Type.HTTP;
+            port = getSystemPropertyOrAlternative("http.proxyPort", //$NON-NLS-1$
+                    "proxyPort", String.valueOf(HTTP_PROXY_PORT)); //$NON-NLS-1$
+        } else if ((host = getSystemProperty("proxyHost", null)) != null) { //$NON-NLS-1$
+            // case 2: proxyHost is set, use exact http proxy
+            type = Proxy.Type.HTTP;
+            port = getSystemPropertyOrAlternative("proxyPort", //$NON-NLS-1$
+                    "http.proxyPort", String.valueOf(HTTP_PROXY_PORT)); //$NON-NLS-1$
+
+        } else if ((host = getSystemProperty("socksProxyHost")) != null) { //$NON-NLS-1$
+            // case 3: use socks proxy instead
+            type = Proxy.Type.SOCKS;
+            port = getSystemProperty(
+                    "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
+        }
+        int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
+                : HTTP_PROXY_PORT;
+        return createProxy(type, host, port, defaultPort);
+    }
+
+    /*
+     * Gets proxy for https request.
+     */
+    private Proxy selectHttpsProxy() {
+        String host;
+        String port = null;
+        Proxy.Type type = Proxy.Type.DIRECT;
+
+        host = getSystemProperty("https.proxyHost"); //$NON-NLS-1$
+        if (null != host) {
+            // case 1: use exact https proxy
+            type = Proxy.Type.HTTP;
+            port = getSystemProperty(
+                    "https.proxyPort", String.valueOf(HTTPS_PROXY_PORT)); //$NON-NLS-1$
+        } else {
+            host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
+            if (null != host) {
+                // case 2: use socks proxy instead
+                type = Proxy.Type.SOCKS;
+                port = getSystemProperty(
+                        "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
+            }
+        }
+        int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
+                : HTTPS_PROXY_PORT;
+        return createProxy(type, host, port, defaultPort);
+    }
+
+    /*
+     * Gets proxy for ftp request.
+     */
+    private Proxy selectFtpProxy(String uriHost) {
+        String host;
+        String port = null;
+        Proxy.Type type = Proxy.Type.DIRECT;
+        String nonProxyHosts = getSystemProperty("ftp.nonProxyHosts"); //$NON-NLS-1$
+        // if host is in non proxy host list, returns Proxy.NO_PROXY
+        if (isNonProxyHost(uriHost, nonProxyHosts)) {
+            return Proxy.NO_PROXY;
+        }
+
+        host = getSystemProperty("ftp.proxyHost"); //$NON-NLS-1$
+        if (null != host) {
+            // case 1: use exact ftp proxy
+            type = Proxy.Type.HTTP;
+            port = getSystemProperty(
+                    "ftp.proxyPort", String.valueOf(FTP_PROXY_PORT)); //$NON-NLS-1$
+        } else {
+            host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
+            if (null != host) {
+                // case 2: use socks proxy instead
+                type = Proxy.Type.SOCKS;
+                port = getSystemProperty(
+                        "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
+            }
+        }
+        int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
+                : FTP_PROXY_PORT;
+        return createProxy(type, host, port, defaultPort);
+    }
+
+    /*
+     * Gets proxy for socks request.
+     */
+    private Proxy selectSocksProxy() {
+        String host;
+        String port = null;
+        Proxy.Type type = Proxy.Type.DIRECT;
+
+        host = getSystemProperty("socksProxyHost"); //$NON-NLS-1$
+        if (null != host) {
+            type = Proxy.Type.SOCKS;
+            port = getSystemProperty(
+                    "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT)); //$NON-NLS-1$
+        }
+        return createProxy(type, host, port, SOCKS_PROXY_PORT);
+    }
+
+    /*
+     * checks whether the host needs proxy. return true if it doesn't need a
+     * proxy.
+     */
+    private boolean isNonProxyHost(String host, String nonProxyHosts) {
+        // nonProxyHosts is not set
+        if (null == nonProxyHosts) {
+            return false;
+        }
+        // Construct regex expression of nonProxyHosts
+        int length = nonProxyHosts.length();
+        char ch;
+        StringBuilder buf = new StringBuilder(length);
+        for (int i = 0; i < nonProxyHosts.length(); i++) {
+            ch = nonProxyHosts.charAt(i);
+            switch (ch) {
+                case '.':
+                    buf.append("\\."); //$NON-NLS-1$
+                    break;
+                case '*':
+                    buf.append(".*"); //$NON-NLS-1$
+                    break;
+                default:
+                    buf.append(ch);
+            }
+        }
+        String nonProxyHostsReg = buf.toString();
+        // check whether the host is the nonProxyHosts.
+        return host.matches(nonProxyHostsReg);
+    }
+
+    /*
+     * Create Proxy by "type","host" and "port".
+     */
+    private Proxy createProxy(Proxy.Type type, String host, String port,
+            int defaultPort) {
+        Proxy proxy;
+        if (type == Proxy.Type.DIRECT) {
+            proxy = Proxy.NO_PROXY;
+        } else {
+            int iPort;
+            try {
+                iPort = Integer.valueOf(port).intValue();
+            } catch (NumberFormatException e) {
+                iPort = defaultPort;
+            }
+            proxy = new Proxy(type, InetSocketAddress.createUnresolved(host,
+                    iPort));
+        }
+        return proxy;
+    }
+
+    /*
+     * gets system property, privileged operation. If the value of the property
+     * is null or empty String, it returns defaultValue.
+     */
+    private String getSystemProperty(final String property) {
+        return getSystemProperty(property, null);
+    }
+
+    /*
+     * gets system property, privileged operation. If the value of the property
+     * is null or empty String, it returns defaultValue.
+     */
+    private String getSystemProperty(final String property,
+            final String defaultVaule) {
+        String value = AccessController.doPrivileged(new PriviAction<String>(
+                property));
+        if (null == value || "".equals(value)) { //$NON-NLS-1$
             value = defaultVaule;
         }
         return value;
-	}
-
-	/*
-	 * gets system property, privileged operation. If the value of "key"
-	 * property is null, then retrieve value from "alternative" property.
-	 * Finally, if the value is null or empty String, it returns defaultValue.
-	 */
-	private String getSystemPropertyOrAlternative(final String key,
-			final String alternativeKey, final String defaultValue) {
-		String value = getSystemProperty(key);
-		if (value == null) {
-			value = getSystemProperty(alternativeKey);
-			if (null == value) {
-				value = defaultValue;
-			}
-		}
-		return value;
-	}
+    }
 
+    /*
+     * gets system property, privileged operation. If the value of "key"
+     * property is null, then retrieve value from "alternative" property.
+     * Finally, if the value is null or empty String, it returns defaultValue.
+     */
+    private String getSystemPropertyOrAlternative(final String key,
+            final String alternativeKey, final String defaultValue) {
+        String value = getSystemProperty(key);
+        if (value == null) {
+            value = getSystemProperty(alternativeKey);
+            if (null == value) {
+                value = defaultValue;
+            }
+        }
+        return value;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java Fri Jan  5 06:44:04 2007
@@ -20,127 +20,135 @@
 import java.util.Map;
 
 /**
- * ResponseCache implements URLConnection caches. 
- * System default cache can be registered by invoking ResponseCache.<code>setDefault</code>(ResponseCache),
- * and can be retrieved by invoking ResponseCache.<code>getDefault</code>.  
- * If URLConnection#useCaches is set, <code>URLConnection</code> class will use <code>ResponseCache</code>
- * to store and get resources. Whether the resource is cached depends on <code>ResponseCache</code> implementation.
- * If a request resource is cached, protocol handler will fecth it from the cache. If the protocol handler fails 
- * to get resource from the cache, it turns to get the resource from its original location.
- *
+ * ResponseCache implements URLConnection caches. System default cache can be
+ * registered by invoking ResponseCache.<code>setDefault</code>(ResponseCache),
+ * and can be retrieved by invoking ResponseCache.<code>getDefault</code>.
+ * If URLConnection#useCaches is set, <code>URLConnection</code> class will
+ * use <code>ResponseCache</code> to store and get resources. Whether the
+ * resource is cached depends on <code>ResponseCache</code> implementation. If
+ * a request resource is cached, protocol handler will fecth it from the cache.
+ * If the protocol handler fails to get resource from the cache, it turns to get
+ * the resource from its original location.
  */
 public abstract class ResponseCache {
-	
-	/*
-	 *  _defaultResponseCache is used to store default response cache. 
-	 */
-	private static ResponseCache _defaultResponseCache = null;
-	
-	/*
-	 * "getResponseCache" permission. getDefault method requires this permission. 
-	 */
-	private static NetPermission getResponseCachepermission = new NetPermission("getResponseCache");
-	
-	/*
-	 * "setResponseCache" permission. setDefault method requires this permission. 
-	 */
-	private static NetPermission setResponseCachepermission = new NetPermission("setResponseCache");
-	
-	/*
-	 * check getResponseCache permission.
-	 * getDefault method requires "getResponseCache" permission
-	 * if a security manager is installed. 
-	 */
-	private static void checkGetResponseCachePermission(){
-		SecurityManager sm = System.getSecurityManager();
-		if(null != sm){
-			sm.checkPermission(getResponseCachepermission);
-		}
-	}
-	/*
-	 * check setResponseCache permission.
-	 * setDefault method requires "setResponseCache" permission
-	 * if a security manager is installed. 
-	 */
-	private static void checkSetResponseCachePermission(){
-		SecurityManager sm = System.getSecurityManager();
-		if(null != sm){
-			sm.checkPermission(setResponseCachepermission);
-		}
-	}
-	
-	/**
-	 * Constructor method.
-	 */
-	public ResponseCache() {
-		super();
-	}
-
-	/**
-	 * Gets system default response cache.
-	 * @return default <code>ResponseCache</code>.
-	 * @throws SecurityException
-	 *             If a security manager is installed
-	 *             and it doesn't have <code>NetPermission</code>("getResponseCache").	 
-	 */
-	public static ResponseCache getDefault() {
-		checkGetResponseCachePermission();
-		return _defaultResponseCache;
-	}
-
-	/**
-	 * Sets the system default response cache when responseCache is not null.
-	 * Otherwise, the method unsets the system default response cache.
-	 * This setting may be ignored by some non-standard protocols.  
-	 * @param responseCache
-	 *            Set default <code>ResponseCache</code>. 
-	 *            If responseCache is null, it unsets the cache.
-	 * @throws SecurityException
-	 *             If a security manager is installed
-	 *             and it doesn't have <code>NetPermission</code>("setResponseCache").
-	 */
-	public static void setDefault(ResponseCache responseCache) {
-		checkSetResponseCachePermission();
-		_defaultResponseCache = responseCache;
-	}
-
-	
-	/**
-	 * Gets the cached response according to requesting uri,method and headers. 
-	 * @param uri
-	 *            A <code>URL</code>  represents requesting uri.
-	 * @param rqstMethod
-	 *            A <code>String</code> represents requesting method.
-	 * @param rqstHeaders
-	 *            A <code>Map</code> from request header field names 
-	 *            to lists of field values represents requesting headers.
-	 * @return A <code>CacheResponse</code> object if the request is available in the cache.
-	 *         Otherwise, this method returns null.
-	 * @throws IOException
-	 *              If an I/O error is encountered.
-	 * @throws IllegalArgumentException
-	 *             If any one of the parameters is null
-	 */
-	public abstract CacheResponse get(URI uri, String rqstMethod,
-            Map<String,List<String>> rqstHeaders) throws IOException;
-
-	/**
-	 * Protocol handler calls this method after retrieving resources.
-	 * The <code>ResponseCache</code> decides whether the resource should be cached.
-	 * If the resource needs to be cached, this method will return a <code>CacheRequest</code>
-	 * with a <code>WriteableByteChannel</code>, and then, protocol handler will use this 
-	 * channel to write the resource data into the cache. Otherwise, if the resource doesn't 
-	 * need to be cached, it returns null.
-	 *     
-	 * @param uri
-	 * @param conn
-	 * @return a <code>CacheRequest</code> which contains <code>WriteableByteChannel</code>
-	 *         if the resource is cached. Otherwise, it returns null. 
-	 * @throws IOException
-	 *             If an I/O error is encountered.
-	 * @throws IllegalArgumentException
-	 *             If any one of the parameters is null.
-	 */
-	public abstract CacheRequest put(URI uri, URLConnection conn)
-			throws IOException;
+
+    /*
+     * _defaultResponseCache is used to store default response cache.
+     */
+    private static ResponseCache _defaultResponseCache = null;
+
+    /*
+     * "getResponseCache" permission. getDefault method requires this
+     * permission.
+     */
+    private static NetPermission getResponseCachepermission = new NetPermission(
+            "getResponseCache"); //$NON-NLS-1$
+
+    /*
+     * "setResponseCache" permission. setDefault method requires this
+     * permission.
+     */
+    private static NetPermission setResponseCachepermission = new NetPermission(
+            "setResponseCache"); //$NON-NLS-1$
+
+    /*
+     * check getResponseCache permission. getDefault method requires
+     * "getResponseCache" permission if a security manager is installed.
+     */
+    private static void checkGetResponseCachePermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(getResponseCachepermission);
+        }
+    }
+
+    /*
+     * check setResponseCache permission. setDefault method requires
+     * "setResponseCache" permission if a security manager is installed.
+     */
+    private static void checkSetResponseCachePermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(setResponseCachepermission);
+        }
+    }
+
+    /**
+     * Constructor method.
+     */
+    public ResponseCache() {
+        super();
+    }
+
+    /**
+     * Gets system default response cache.
+     * 
+     * @return default <code>ResponseCache</code>.
+     * @throws SecurityException
+     *             If a security manager is installed and it doesn't have
+     *             <code>NetPermission</code>("getResponseCache").
+     */
+    public static ResponseCache getDefault() {
+        checkGetResponseCachePermission();
+        return _defaultResponseCache;
+    }
+
+    /**
+     * Sets the system default response cache when responseCache is not null.
+     * Otherwise, the method unsets the system default response cache. This
+     * setting may be ignored by some non-standard protocols.
+     * 
+     * @param responseCache
+     *            Set default <code>ResponseCache</code>. If responseCache is
+     *            null, it unsets the cache.
+     * @throws SecurityException
+     *             If a security manager is installed and it doesn't have
+     *             <code>NetPermission</code>("setResponseCache").
+     */
+    public static void setDefault(ResponseCache responseCache) {
+        checkSetResponseCachePermission();
+        _defaultResponseCache = responseCache;
+    }
+
+    /**
+     * Gets the cached response according to requesting uri,method and headers.
+     * 
+     * @param uri
+     *            A <code>URL</code> represents requesting uri.
+     * @param rqstMethod
+     *            A <code>String</code> represents requesting method.
+     * @param rqstHeaders
+     *            A <code>Map</code> from request header field names to lists
+     *            of field values represents requesting headers.
+     * @return A <code>CacheResponse</code> object if the request is available
+     *         in the cache. Otherwise, this method returns null.
+     * @throws IOException
+     *             If an I/O error is encountered.
+     * @throws IllegalArgumentException
+     *             If any one of the parameters is null
+     */
+    public abstract CacheResponse get(URI uri, String rqstMethod,
+            Map<String, List<String>> rqstHeaders) throws IOException;
+
+    /**
+     * Protocol handler calls this method after retrieving resources. The
+     * <code>ResponseCache</code> decides whether the resource should be
+     * cached. If the resource needs to be cached, this method will return a
+     * <code>CacheRequest</code> with a <code>WriteableByteChannel</code>,
+     * and then, protocol handler will use this channel to write the resource
+     * data into the cache. Otherwise, if the resource doesn't need to be
+     * cached, it returns null.
+     * 
+     * @param uri
+     * @param conn
+     * @return a <code>CacheRequest</code> which contains
+     *         <code>WriteableByteChannel</code> if the resource is cached.
+     *         Otherwise, it returns null.
+     * @throws IOException
+     *             If an I/O error is encountered.
+     * @throws IllegalArgumentException
+     *             If any one of the parameters is null.
+     */
+    public abstract CacheRequest put(URI uri, URLConnection conn)
+            throws IOException;
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java Fri Jan  5 06:44:04 2007
@@ -22,73 +22,74 @@
 import javax.net.ssl.SSLPeerUnverifiedException;
 
 /**
- * A secure cache response, which is orignally retrieved through secure ways. 
+ * A secure cache response, which is orignally retrieved through secure ways.
  */
 public abstract class SecureCacheResponse extends CacheResponse {
-	/**
-	 * Constructor method
-	 */
-	public SecureCacheResponse() {
-		super();
-	}
+    /**
+     * Constructor method
+     */
+    public SecureCacheResponse() {
+        super();
+    }
 
-	/**
-	 * <p>
-	 * Gets the cipher suite string on the connection 
-	 * which is originally used to retrieve the network resource.
-	 * </p>
-	 * @return the cipher suite string
-	 */
-	public abstract String getCipherSuite();
+    /**
+     * Gets the cipher suite string on the connection which is originally used
+     * to retrieve the network resource.
+     * 
+     * @return the cipher suite string
+     */
+    public abstract String getCipherSuite();
 
-	/**
-	 * <p>
-	 * Gets local certificate chain. When the original connection retrieved the resource data,
-	 * certificate chain was sent to the server during handshaking process. This method only 
-	 * takes effect when certificate-based cipher suite is enabled.
-	 * </p> 
-	 * @return the certificate chain that was sent to the server. The certificate chain is represented 
-	 * as a <code>List</code> of <code>Certificate</code>. If no certificate chain was sent, 
-	 * the method returns null.
-	 */
-	public abstract List<Certificate> getLocalCertificateChain();
+    /**
+     * Gets local certificate chain. When the original connection retrieved the
+     * resource data, certificate chain was sent to the server during
+     * handshaking process. This method only takes effect when certificate-based
+     * cipher suite is enabled.
+     * 
+     * @return the certificate chain that was sent to the server. The
+     *         certificate chain is represented as a <code>List</code> of
+     *         <code>Certificate</code>. If no certificate chain was sent,
+     *         the method returns null.
+     */
+    public abstract List<Certificate> getLocalCertificateChain();
 
-	/**
-	 * <p>
-	 * Gets server's certificate chain from cache. As part of defining the session,
-	 * the certificate chain was established when the original connection retrieved network resource.
-	 * This method can only be invoked when certificated-based cypher suites is enable. 
-	 * Otherwise, it throws an <code>SSLPeerUnverifiedException</code>.
-	 * </p>
-	 * @return The server's certificate chain, which is represented as a <code>List</code> of <code>Certificate</code>.
-	 * @throws SSLPeerUnverifiedException
-	 *             If the peer is unverified.
-	 */
-	public abstract List<Certificate> getServerCertificateChain()
-			throws SSLPeerUnverifiedException;
+    /**
+     * Gets server's certificate chain from cache. As part of defining the
+     * session, the certificate chain was established when the original
+     * connection retrieved network resource. This method can only be invoked
+     * when certificated-based cypher suites is enable. Otherwise, it throws an
+     * <code>SSLPeerUnverifiedException</code>.
+     * 
+     * @return The server's certificate chain, which is represented as a
+     *         <code>List</code> of <code>Certificate</code>.
+     * @throws SSLPeerUnverifiedException
+     *             If the peer is unverified.
+     */
+    public abstract List<Certificate> getServerCertificateChain()
+            throws SSLPeerUnverifiedException;
 
-	/**
-	 * <p>
-	 * Gets the server's <code>Principle</code>. When the original connection 
-	 * retrieved network resource, the principle was established when defining 
-	 * the session. 
-	 * </p>
-	 * @return an <code>Principal</code> represents the server's principal. 
-	 * @throws SSLPeerUnverifiedException
-	 *             If the peer is unverified.
-	 */
-	public abstract Principal getPeerPrincipal()
-			throws SSLPeerUnverifiedException;
+    /**
+     * Gets the server's <code>Principle</code>. When the original connection
+     * retrieved network resource, the principle was established when defining
+     * the session.
+     * 
+     * @return an <code>Principal</code> represents the server's principal.
+     * @throws SSLPeerUnverifiedException
+     *             If the peer is unverified.
+     */
+    public abstract Principal getPeerPrincipal()
+            throws SSLPeerUnverifiedException;
 
-	/**
-	 * <p>
-	 * Gets the <code>Principle</code> that the original connection sent to the server. 
-	 * When the original connection fetched the network resource, the <code>Principle</code> 
-	 * was sent to the server during handshaking process.
-	 * </p>
-	 * @return the <code>principal</code> sent to the server. 
-	 *         Returns an <code>X500Principal</code> for X509-based cipher suites.
-	 *         If no principal was sent, it returns null.
-	 */
-	public abstract Principal getLocalPrincipal();
+    /**
+     * Gets the <code>Principle</code> that the original connection sent to
+     * the server. When the original connection fetched the network resource,
+     * the <code>Principle</code> was sent to the server during handshaking
+     * process.
+     * 
+     * 
+     * @return the <code>principal</code> sent to the server. Returns an
+     *         <code>X500Principal</code> for X509-based cipher suites. If no
+     *         principal was sent, it returns null.
+     */
+    public abstract Principal getLocalPrincipal();
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java Fri Jan  5 06:44:04 2007
@@ -17,7 +17,6 @@
 
 package java.net;
 
-
 import java.io.IOException;
 import java.nio.channels.ServerSocketChannel;
 
@@ -35,203 +34,202 @@
  */
 public class ServerSocket {
 
-	SocketImpl impl;
+    SocketImpl impl;
+
+    static SocketImplFactory factory;
 
-	static SocketImplFactory factory;
+    private volatile boolean isCreated;
 
-	private volatile boolean isCreated;
+    private boolean isBound;
 
-	private boolean isBound;
+    private boolean isClosed;
 
-	private boolean isClosed;
-	
-	/**
-	 * Construct a ServerSocket, which is not bound to any port. The default
-	 * number of pending connections may be backlogged.
-	 * 
-	 * @see Socket
-	 */
-	public ServerSocket() throws IOException {
-		impl = factory != null ? factory.createSocketImpl()
-                :SocketImplProvider.getServerSocketImpl();
-	}
+    /**
+     * Construct a ServerSocket, which is not bound to any port. The default
+     * number of pending connections may be backlogged.
+     * 
+     * @see Socket
+     */
+    public ServerSocket() throws IOException {
+        impl = factory != null ? factory.createSocketImpl()
+                : SocketImplProvider.getServerSocketImpl();
+    }
 
-    protected ServerSocket(SocketImpl impl){
+    protected ServerSocket(SocketImpl impl) {
         this.impl = impl;
     }
 
-	/**
-	 * Construct a ServerSocket, bound to the nominated port on the default
-	 * localhost. The default number of pending connections may be backlogged.
-	 * 
-	 * @param aport
-	 *            the port number to listen for connection requests on
-	 * @see Socket
-	 */
-	public ServerSocket(int aport) throws IOException {
-		this(aport, defaultBacklog(), InetAddress.ANY);
-	}
-
-	/**
-	 * Construct a ServerSocket, bound to the nominated port on the default
-	 * localhost. The number of pending connections that may be backlogged is a
-	 * specified.
-	 * 
-	 * @param aport
-	 *            the port number to listen for connection requests on
-	 * @param backlog
-	 *            the number of pending connection requests, before requests are
-	 *            rejected
-	 * @see Socket
-	 */
-	public ServerSocket(int aport, int backlog) throws IOException {
-		this(aport, backlog, InetAddress.ANY);
-	}
-
-	/**
-	 * Construct a ServerSocket, bound to the nominated local host/port. The
-	 * number of pending connections that may be backlogged is a specified.
-	 * 
-	 * @param aport
-	 *            the port number to listen for connection requests on
-	 * @param localAddr
-	 *            the local machine address to bind on
-	 * @param backlog
-	 *            the number of pending connection requests, before requests are
-	 *            rejected
-	 * @see Socket
-	 */
-	public ServerSocket(int aport, int backlog, InetAddress localAddr)
-			throws IOException {
-		super();
-		checkListen(aport);
-		impl = factory != null ? factory.createSocketImpl()
+    /**
+     * Construct a ServerSocket, bound to the nominated port on the default
+     * localhost. The default number of pending connections may be backlogged.
+     * 
+     * @param aport
+     *            the port number to listen for connection requests on
+     * @see Socket
+     */
+    public ServerSocket(int aport) throws IOException {
+        this(aport, defaultBacklog(), InetAddress.ANY);
+    }
+
+    /**
+     * Construct a ServerSocket, bound to the nominated port on the default
+     * localhost. The number of pending connections that may be backlogged is a
+     * specified.
+     * 
+     * @param aport
+     *            the port number to listen for connection requests on
+     * @param backlog
+     *            the number of pending connection requests, before requests are
+     *            rejected
+     * @see Socket
+     */
+    public ServerSocket(int aport, int backlog) throws IOException {
+        this(aport, backlog, InetAddress.ANY);
+    }
+
+    /**
+     * Construct a ServerSocket, bound to the nominated local host/port. The
+     * number of pending connections that may be backlogged is a specified.
+     * 
+     * @param aport
+     *            the port number to listen for connection requests on
+     * @param localAddr
+     *            the local machine address to bind on
+     * @param backlog
+     *            the number of pending connection requests, before requests are
+     *            rejected
+     * @see Socket
+     */
+    public ServerSocket(int aport, int backlog, InetAddress localAddr)
+            throws IOException {
+        super();
+        checkListen(aport);
+        impl = factory != null ? factory.createSocketImpl()
                 : SocketImplProvider.getServerSocketImpl();
-		InetAddress addr = localAddr == null ? InetAddress.ANY : localAddr;
+        InetAddress addr = localAddr == null ? InetAddress.ANY : localAddr;
 
-		synchronized (this) {
-			impl.create(true);
-			isCreated = true;
-			try {
-				impl.bind(addr, aport);
-				isBound = true;
-				impl.listen(backlog > 0 ? backlog : defaultBacklog());
-			} catch (IOException e) {
-				close();
-				throw e;
-			}
-		}
-	}
-
-	/**
-	 * Retrieve the first connection request and answer the 'host' socket that
-	 * will conduct further communications with the requesting 'client' socket.
-	 * 
-	 * @return Socket the 'host' socket
-	 * @exception IOException
-	 *                if an error occurs while instantiating the 'host' socket
-	 */
-	public Socket accept() throws IOException {
-		checkClosedAndCreate(false);
-		if (!isBound()) {
-            throw new SocketException(Msg.getString("K031f"));
-        }
-
-		Socket aSocket = new Socket();
-		try {
-			synchronized (this) {
-				implAccept(aSocket);
-			}
-			SecurityManager security = System.getSecurityManager();
-			if (security != null) {
+        synchronized (this) {
+            impl.create(true);
+            isCreated = true;
+            try {
+                impl.bind(addr, aport);
+                isBound = true;
+                impl.listen(backlog > 0 ? backlog : defaultBacklog());
+            } catch (IOException e) {
+                close();
+                throw e;
+            }
+        }
+    }
+
+    /**
+     * Retrieve the first connection request and answer the 'host' socket that
+     * will conduct further communications with the requesting 'client' socket.
+     * 
+     * @return Socket the 'host' socket
+     * @exception IOException
+     *                if an error occurs while instantiating the 'host' socket
+     */
+    public Socket accept() throws IOException {
+        checkClosedAndCreate(false);
+        if (!isBound()) {
+            throw new SocketException(Msg.getString("K031f")); //$NON-NLS-1$
+        }
+
+        Socket aSocket = new Socket();
+        try {
+            synchronized (this) {
+                implAccept(aSocket);
+            }
+            SecurityManager security = System.getSecurityManager();
+            if (security != null) {
                 security.checkAccept(aSocket.getInetAddress().getHostAddress(),
-						aSocket.getPort());
-			}
-		} catch (SecurityException e) {
-			aSocket.close();
-			throw e;
-		} catch (IOException e) {
-			aSocket.close();
-			throw e;
-		}
-		return aSocket;
-	}
-
-	/**
-	 * Check whether the server may listen for connection requests on
-	 * <code>aport</code>. Throw an exception if the port is outside the
-	 * valid range or does not satisfy the security policy.
-	 * 
-	 * @param aPort
-	 *            the candidate port to listen on
-	 */
-	void checkListen(int aPort) {
-		if (aPort < 0 || aPort > 65535) {
+                        aSocket.getPort());
+            }
+        } catch (SecurityException e) {
+            aSocket.close();
+            throw e;
+        } catch (IOException e) {
+            aSocket.close();
+            throw e;
+        }
+        return aSocket;
+    }
+
+    /**
+     * Check whether the server may listen for connection requests on
+     * <code>aport</code>. Throw an exception if the port is outside the
+     * valid range or does not satisfy the security policy.
+     * 
+     * @param aPort
+     *            the candidate port to listen on
+     */
+    void checkListen(int aPort) {
+        if (aPort < 0 || aPort > 65535) {
             throw new IllegalArgumentException(Msg.getString("K0325", aPort)); //$NON-NLS-1$
         }
-		SecurityManager security = System.getSecurityManager();
-		if (security != null) {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
             security.checkListen(aPort);
         }
-	}
+    }
+
+    /**
+     * Close this server socket. Any attempt to connect to this socket
+     * thereafter will fail.
+     */
+    public void close() throws IOException {
+        isClosed = true;
+        impl.close();
+    }
+
+    /**
+     * Answer the default number of pending connections on a server socket.
+     * 
+     * @return int the default number of pending connection requests
+     */
+    static int defaultBacklog() {
+        return 50;
+    }
 
-	/**
-	 * Close this server socket. Any attempt to connect to this socket
-	 * thereafter will fail.
-	 */
-	public void close() throws IOException {
-		isClosed = true;
-		impl.close();
-	}
-
-	/**
-	 * Answer the default number of pending connections on a server socket.
-	 * 
-	 * @return int the default number of pending connection requests
-	 */
-	static int defaultBacklog() {
-		return 50;
-	}
-
-	/**
-	 * Answer the local IP address for this server socket. Return null if the
-	 * socket is not bound. This is useful on multihomed hosts.
-	 * 
-	 * @return InetAddress the local address
-	 */
-	public InetAddress getInetAddress() {
-		if (!isBound()) {
+    /**
+     * Answer the local IP address for this server socket. Return null if the
+     * socket is not bound. This is useful on multihomed hosts.
+     * 
+     * @return InetAddress the local address
+     */
+    public InetAddress getInetAddress() {
+        if (!isBound()) {
             return null;
         }
-		return impl.getInetAddress();
-	}
+        return impl.getInetAddress();
+    }
 
-	/**
-	 * Answer the local port for this server socket. Return -1 if the socket is
-	 * not bound.
-	 * 
-	 * @return int the local port the server is listening on
-	 */
-	public int getLocalPort() {
-		if (!isBound()) {
+    /**
+     * Answer the local port for this server socket. Return -1 if the socket is
+     * not bound.
+     * 
+     * @return int the local port the server is listening on
+     */
+    public int getLocalPort() {
+        if (!isBound()) {
             return -1;
         }
-		return impl.getLocalPort();
-	}
+        return impl.getLocalPort();
+    }
 
-	/**
-	 * Answer the time-out period of this server socket. This is the time the
-	 * server will wait listening for connections, before exiting.
-	 * 
-	 * @return int the listening timeout
-	 * @exception SocketException
-	 *                thrown if option cannot be retrieved
-	 */
-	public synchronized int getSoTimeout() throws IOException {
+    /**
+     * Answer the time-out period of this server socket. This is the time the
+     * server will wait listening for connections, before exiting.
+     * 
+     * @return int the listening timeout
+     * @exception SocketException
+     *                thrown if option cannot be retrieved
+     */
+    public synchronized int getSoTimeout() throws IOException {
         if (!isCreated) {
             synchronized (this) {
                 if (!isCreated) {
-
                     try {
                         impl.create(true);
                     } catch (SocketException e) {
@@ -243,281 +241,277 @@
                 }
             }
         }
-		return ((Integer) impl.getOption(SocketOptions.SO_TIMEOUT)).intValue();
-	}
+        return ((Integer) impl.getOption(SocketOptions.SO_TIMEOUT)).intValue();
+    }
 
-	/**
-	 * Invoke the server socket implementation to accept a connection on the
-	 * newly created <code>aSocket</code>.
-	 * 
-	 * @param aSocket
-	 *            the concrete socketImpl to accept the connection request on
-	 * @exception IOException
-	 *                thrown if connection cannot be accepted
-	 */
-	protected final void implAccept(Socket aSocket) throws IOException {
-		impl.accept(aSocket.impl);
-		aSocket.accepted();
-	}
-
-	/**
-	 * Set the server socket implementation factory. This method may only be
-	 * invoked with sufficient security and only once during the application
-	 * lifetime.
-	 * 
-	 * @param aFactory
-	 *            the streaming socket factory to be used for further socket
-	 *            instantiations
-	 * @exception IOException
-	 *                thrown if the factory is already set
-	 */
-	public static synchronized void setSocketFactory(SocketImplFactory aFactory)
-			throws IOException {
-		SecurityManager security = System.getSecurityManager();
-		if (security != null) {
+    /**
+     * Invoke the server socket implementation to accept a connection on the
+     * newly created <code>aSocket</code>.
+     * 
+     * @param aSocket
+     *            the concrete socketImpl to accept the connection request on
+     * @exception IOException
+     *                thrown if connection cannot be accepted
+     */
+    protected final void implAccept(Socket aSocket) throws IOException {
+        impl.accept(aSocket.impl);
+        aSocket.accepted();
+    }
+
+    /**
+     * Set the server socket implementation factory. This method may only be
+     * invoked with sufficient security and only once during the application
+     * lifetime.
+     * 
+     * @param aFactory
+     *            the streaming socket factory to be used for further socket
+     *            instantiations
+     * @exception IOException
+     *                thrown if the factory is already set
+     */
+    public static synchronized void setSocketFactory(SocketImplFactory aFactory)
+            throws IOException {
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
             security.checkSetFactory();
         }
-		if (factory == null) {
-            factory = aFactory;
-        } else {
+        if (factory != null) {
             throw new SocketException(Msg.getString("K0042")); //$NON-NLS-1$
         }
-	}
+        factory = aFactory;
+    }
+
+    /**
+     * Set the listen time-out period for this server socket.
+     * 
+     * @param timeout
+     *            the time to wait for a connection request
+     * @exception SocketException
+     *                thrown if an error occurs during setting the option
+     */
+    public synchronized void setSoTimeout(int timeout) throws SocketException {
+        checkClosedAndCreate(true);
+        if (timeout < 0) {
+            throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
+        }
+        impl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
+    }
 
-	/**
-	 * Set the listen time-out period for this server socket.
-	 * 
-	 * @param timeout
-	 *            the time to wait for a connection request
-	 * @exception SocketException
-	 *                thrown if an error occurs during setting the option
-	 */
-	public synchronized void setSoTimeout(int timeout) throws SocketException {
-		checkClosedAndCreate(true);
-		if (timeout >= 0) {
-			impl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
-		} else {
-			throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Answers a string containing a concise, human-readable description of the
-	 * server socket. The <code>port</code> field is reported a zero, as there
-	 * is no connection formed to the server.
-	 * 
-	 * @return String the description
-	 */
-	@Override
+    /**
+     * Answers a string containing a concise, human-readable description of the
+     * server socket. The <code>port</code> field is reported a zero, as there
+     * is no connection formed to the server.
+     * 
+     * @return String the description
+     */
+    @Override
     public String toString() {
         StringBuffer result = new StringBuffer(64);
         result.append("ServerSocket["); //$NON-NLS-1$
         if (!isBound()) {
             return result.append("unbound]").toString(); //$NON-NLS-1$
         }
-        return result
-                .append("addr="). //$NON-NLS-1$
-                append(getInetAddress().getHostName())
-                .append("/").append(getInetAddress().getHostAddress()).append(",port=0,localport="). //$NON-NLS-1$
-                append(getLocalPort()).append("]"). //$NON-NLS-1$
-                toString();
-    }
-
-	/**
-	 * Bind the ServerSocket to the nominated local host/port. The default
-	 * number of pending connections may be backlogged.
-	 * 
-	 * @param localAddr
-	 *            the local machine address and port to bind on
-	 * 
-	 * @exception IllegalArgumentException
-	 *                if the SocketAddress is not supported
-	 * @exception IOException
-	 *                if the socket is already bound, or a problem occurs during
-	 *                the bind
-	 */
-	public void bind(SocketAddress localAddr) throws IOException {
-		bind(localAddr, defaultBacklog());
-	}
-
-	/**
-	 * Bind the ServerSocket to the nominated local host/port. The number of
-	 * pending connections that may be backlogged is a specified.
-	 * 
-	 * @param localAddr
-	 *            the local machine address and port to bind on
-	 * @param backlog
-	 *            the number of pending connection requests, before requests are
-	 *            rejected
-	 * 
-	 * @exception IllegalArgumentException
-	 *                if the SocketAddress is not supported
-	 * @exception IOException
-	 *                if the socket is already bound, or a problem occurs during
-	 *                the bind
-	 */
-	public void bind(SocketAddress localAddr, int backlog) throws IOException {
-		checkClosedAndCreate(true);
-		if (isBound()) {
+        return result.append("addr=") //$NON-NLS-1$
+                .append(getInetAddress().getHostName()).append("/") //$NON-NLS-1$
+                .append(getInetAddress().getHostAddress()).append(
+                        ",port=0,localport=") //$NON-NLS-1$
+                .append(getLocalPort()).append("]") //$NON-NLS-1$
+                .toString();
+    }
+
+    /**
+     * Bind the ServerSocket to the nominated local host/port. The default
+     * number of pending connections may be backlogged.
+     * 
+     * @param localAddr
+     *            the local machine address and port to bind on
+     * 
+     * @exception IllegalArgumentException
+     *                if the SocketAddress is not supported
+     * @exception IOException
+     *                if the socket is already bound, or a problem occurs during
+     *                the bind
+     */
+    public void bind(SocketAddress localAddr) throws IOException {
+        bind(localAddr, defaultBacklog());
+    }
+
+    /**
+     * Bind the ServerSocket to the nominated local host/port. The number of
+     * pending connections that may be backlogged is a specified.
+     * 
+     * @param localAddr
+     *            the local machine address and port to bind on
+     * @param backlog
+     *            the number of pending connection requests, before requests are
+     *            rejected
+     * 
+     * @exception IllegalArgumentException
+     *                if the SocketAddress is not supported
+     * @exception IOException
+     *                if the socket is already bound, or a problem occurs during
+     *                the bind
+     */
+    public void bind(SocketAddress localAddr, int backlog) throws IOException {
+        checkClosedAndCreate(true);
+        if (isBound()) {
             throw new BindException(Msg.getString("K0315")); //$NON-NLS-1$
         }
-		int port = 0;
-		InetAddress addr = InetAddress.ANY;
-		if (localAddr != null) {
-			if (!(localAddr instanceof InetSocketAddress)) {
+        int port = 0;
+        InetAddress addr = InetAddress.ANY;
+        if (localAddr != null) {
+            if (!(localAddr instanceof InetSocketAddress)) {
                 throw new IllegalArgumentException(Msg.getString(
-						"K0316", localAddr.getClass())); //$NON-NLS-1$
+                        "K0316", localAddr.getClass())); //$NON-NLS-1$
             }
-			InetSocketAddress inetAddr = (InetSocketAddress) localAddr;
-			if ((addr = inetAddr.getAddress()) == null) {
+            InetSocketAddress inetAddr = (InetSocketAddress) localAddr;
+            if ((addr = inetAddr.getAddress()) == null) {
                 throw new SocketException(Msg.getString(
-						"K0317", inetAddr.getHostName())); //$NON-NLS-1$
+                        "K0317", inetAddr.getHostName())); //$NON-NLS-1$
             }
-			port = inetAddr.getPort();
-		}
-		SecurityManager security = System.getSecurityManager();
-		if (security != null) {
+            port = inetAddr.getPort();
+        }
+        SecurityManager security = System.getSecurityManager();
+        if (security != null) {
             security.checkListen(port);
         }
 
-		synchronized (this) {
-			try {
-				impl.bind(addr, port);
-				isBound = true;
-				impl.listen(backlog > 0 ? backlog : defaultBacklog());
-			} catch (IOException e) {
-				close();
-				throw e;
-			}
-		}
-	}
-
-	/**
-	 * Answer the local SocketAddress for this server socket, or null if the
-	 * socket is not bound. This is useful on multihomed hosts.
-	 */
-	public SocketAddress getLocalSocketAddress() {
-		if (!isBound()) {
+        synchronized (this) {
+            try {
+                impl.bind(addr, port);
+                isBound = true;
+                impl.listen(backlog > 0 ? backlog : defaultBacklog());
+            } catch (IOException e) {
+                close();
+                throw e;
+            }
+        }
+    }
+
+    /**
+     * Answer the local SocketAddress for this server socket, or null if the
+     * socket is not bound. This is useful on multihomed hosts.
+     */
+    public SocketAddress getLocalSocketAddress() {
+        if (!isBound()) {
             return null;
         }
-		return new InetSocketAddress(getInetAddress(), getLocalPort());
-	}
+        return new InetSocketAddress(getInetAddress(), getLocalPort());
+    }
+
+    /**
+     * Return if the server socket is bound to a local address and port.
+     */
+    public boolean isBound() {
+        return isBound;
+    }
 
-	/**
-	 * Return if the server socket is bound to a local address and port.
-	 */
-	public boolean isBound() {
-		return isBound;
-	}
-
-	/**
-	 * Return if the server socket is closed.
-	 */
-	public boolean isClosed() {
-		return isClosed;
-	}
-
-	/**
-	 * Check if the socket is closed, and throw an exception.
-	 */
-	private void checkClosedAndCreate(boolean create) throws SocketException {
-		if (isClosed()) {
-            throw new SocketException(Msg.getString("K003d"));
+    /**
+     * Return if the server socket is closed.
+     */
+    public boolean isClosed() {
+        return isClosed;
+    }
+
+    /**
+     * Check if the socket is closed, and throw an exception.
+     */
+    private void checkClosedAndCreate(boolean create) throws SocketException {
+        if (isClosed()) {
+            throw new SocketException(Msg.getString("K003d")); //$NON-NLS-1$
         }
 
-		if (!create || isCreated) {
+        if (!create || isCreated) {
             return;
         }
 
-		synchronized (this) {
-			if (isCreated) {
+        synchronized (this) {
+            if (isCreated) {
                 return;
             }
-			try {
-				impl.create(true);
-			} catch (SocketException e) {
-				throw e;
-			} catch (IOException e) {
-				throw new SocketException(e.toString());
-			}
-			isCreated = true;
-		}
-	}
-
-	/**
-	 * Set the SO_REUSEADDR socket option.
-	 * 
-	 * @param reuse
-	 *            the socket SO_REUSEADDR option setting
-	 */
-	public void setReuseAddress(boolean reuse) throws SocketException {
-		checkClosedAndCreate(true);
-		impl.setOption(SocketOptions.SO_REUSEADDR, reuse ? Boolean.TRUE
-				: Boolean.FALSE);
-	}
-
-	/**
-	 * Get the state of the SO_REUSEADDR socket option.
-	 */
-	public boolean getReuseAddress() throws SocketException {
-		checkClosedAndCreate(true);
-		return ((Boolean) impl.getOption(SocketOptions.SO_REUSEADDR))
-				.booleanValue();
-	}
-
-	/**
-	 * Set the socket receive buffer size.
-	 * 
-	 * @param size
-	 *            the buffer size, in bytes
-	 * 
-	 * @exception java.net.SocketException
-	 *                If an error occurs while setting the size or the size is
-	 *                invalid.
-	 */
-	public void setReceiveBufferSize(int size) throws SocketException {
-		checkClosedAndCreate(true);
-		if (size >= 1) {
-            impl.setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
-        } else {
+            try {
+                impl.create(true);
+            } catch (SocketException e) {
+                throw e;
+            } catch (IOException e) {
+                throw new SocketException(e.toString());
+            }
+            isCreated = true;
+        }
+    }
+
+    /**
+     * Set the SO_REUSEADDR socket option.
+     * 
+     * @param reuse
+     *            the socket SO_REUSEADDR option setting
+     */
+    public void setReuseAddress(boolean reuse) throws SocketException {
+        checkClosedAndCreate(true);
+        impl.setOption(SocketOptions.SO_REUSEADDR, reuse ? Boolean.TRUE
+                : Boolean.FALSE);
+    }
+
+    /**
+     * Get the state of the SO_REUSEADDR socket option.
+     */
+    public boolean getReuseAddress() throws SocketException {
+        checkClosedAndCreate(true);
+        return ((Boolean) impl.getOption(SocketOptions.SO_REUSEADDR))
+                .booleanValue();
+    }
+
+    /**
+     * Set the socket receive buffer size.
+     * 
+     * @param size
+     *            the buffer size, in bytes
+     * 
+     * @exception java.net.SocketException
+     *                If an error occurs while setting the size or the size is
+     *                invalid.
+     */
+    public void setReceiveBufferSize(int size) throws SocketException {
+        checkClosedAndCreate(true);
+        if (size < 1) {
             throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
         }
-	}
+        impl.setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
+    }
+
+    /**
+     * Answer the socket receive buffer size (SO_RCVBUF).
+     * 
+     * @return int socket receive buffer size
+     */
+    public int getReceiveBufferSize() throws SocketException {
+        checkClosedAndCreate(true);
+        return ((Integer) impl.getOption(SocketOptions.SO_RCVBUF)).intValue();
+    }
 
-	/**
-	 * Answer the socket receive buffer size (SO_RCVBUF).
-	 * 
-	 * @return int socket receive buffer size
-	 */
-	public int getReceiveBufferSize() throws SocketException {
-		checkClosedAndCreate(true);
-		return ((Integer) impl.getOption(SocketOptions.SO_RCVBUF)).intValue();
-	}
-	
-	/**
-	 * if ServerSocket is created by a ServerSocketChannel, returns the related
-	 * ServerSocketChannel
-	 * 
-	 * @return the related ServerSocketChannel if any
-	 */
-	public ServerSocketChannel getChannel(){
-		return null;
-	}
-
-    /**
-	 * sets performance preference for connectionTime,latency and bandwidth
-	 * 
-	 * @param connectionTime
-	 *            the importance of connect time
-	 * @param latency
-	 *            the importance of latency
-	 * @param bandwidth
-	 *            the importance of bandwidth
-	 */
+    /**
+     * if ServerSocket is created by a ServerSocketChannel, returns the related
+     * ServerSocketChannel
+     * 
+     * @return the related ServerSocketChannel if any
+     */
+    public ServerSocketChannel getChannel() {
+        return null;
+    }
+
+    /**
+     * sets performance preference for connectionTime,latency and bandwidth
+     * 
+     * @param connectionTime
+     *            the importance of connect time
+     * @param latency
+     *            the importance of latency
+     * @param bandwidth
+     *            the importance of bandwidth
+     */
     public void setPerformancePreferences(int connectionTime, int latency,
             int bandwidth) {
-        // Our socket implementation only provide one protocol: TCP/IP, so 
+        // Our socket implementation only provide one protocol: TCP/IP, so
         // we do nothing for this method
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java Fri Jan  5 06:44:04 2007
@@ -51,7 +51,9 @@
 
     private boolean isOutputShutdown = false;
 
-    private static class ConnectLock {}
+    private static class ConnectLock {
+    }
+
     private Object connectLock = new ConnectLock();
 
     private Proxy proxy;
@@ -101,7 +103,8 @@
      */
     public Socket(Proxy proxy) {
         if (null == proxy || Proxy.Type.HTTP == proxy.type()) {
-            throw new IllegalArgumentException("proxy is null or invalid type");
+            // KA023=Proxy is null or invalid type
+            throw new IllegalArgumentException(Msg.getString("KA023")); //$NON-NLS-1$
         }
         InetSocketAddress address = (InetSocketAddress) proxy.address();
         if (null != address) {
@@ -496,52 +499,6 @@
                 .booleanValue();
     }
 
-    // static native InetAddress getSocketLocalAddressImpl(FileDescriptor aFD,
-    // boolean preferIPv6Addresses);
-    //
-    // /**
-    // * Query the IP stack for the local port to which this socket is bound.
-    // *
-    // * @param aFD
-    // * the socket descriptor
-    // * @param preferIPv6Addresses
-    // * address preference for nodes that support both IPv4 and IPv6
-    // * @return int the local port to which the socket is bound
-    // */
-    // static native int getSocketLocalPortImpl(FileDescriptor aFD,
-    // boolean preferIPv6Addresses);
-    //
-    // /**
-    // * Query the IP stack for the nominated socket option.
-    // *
-    // * @param aFD
-    // * the socket descriptor
-    // * @param opt
-    // * the socket option type
-    // * @return the nominated socket option value
-    // *
-    // * @throws SocketException
-    // * if the option is invalid
-    // */
-    // static native Object getSocketOptionImpl(FileDescriptor aFD, int opt)
-    // throws SocketException;
-    //
-    // /**
-    // * Set the nominated socket option in the IP stack.
-    // *
-    // * @param aFD
-    // * the socket descriptor
-    // * @param opt
-    // * the option selector
-    // * @param optVal
-    // * the nominated option value
-    // *
-    // * @throws SocketException
-    // * if the option is invalid or cannot be set
-    // */
-    // static native void setSocketOptionImpl(FileDescriptor aFD, int opt,
-    // Object optVal) throws SocketException;
-
     /**
      * Set the SO_KEEPALIVE option for this socket.
      * 
@@ -574,11 +531,10 @@
         if (security != null) {
             security.checkSetFactory();
         }
-        if (factory == null) {
-            factory = fac;
-        } else {
+        if (factory != null) {
             throw new SocketException(Msg.getString("K0044")); //$NON-NLS-1$
         }
+        factory = fac;
     }
 
     /**
@@ -593,11 +549,10 @@
      */
     public synchronized void setSendBufferSize(int size) throws SocketException {
         checkClosedAndCreate(true);
-        if (size >= 1) {
-            impl.setOption(SocketOptions.SO_SNDBUF, Integer.valueOf(size));
-        } else {
+        if (size < 1) {
             throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
         }
+        impl.setOption(SocketOptions.SO_SNDBUF, Integer.valueOf(size));
     }
 
     /**
@@ -613,11 +568,10 @@
     public synchronized void setReceiveBufferSize(int size)
             throws SocketException {
         checkClosedAndCreate(true);
-        if (size >= 1) {
-            impl.setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
-        } else {
+        if (size < 1) {
             throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
         }
+        impl.setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
     }
 
     /**
@@ -634,12 +588,11 @@
      */
     public void setSoLinger(boolean on, int timeout) throws SocketException {
         checkClosedAndCreate(true);
-        if (!on || 0 <= timeout) {
-            int val = on ? (65535 < timeout ? 65535 : timeout) : -1;
-            impl.setOption(SocketOptions.SO_LINGER, Integer.valueOf(val));
-        } else {
+        if (on && timeout < 0) {
             throw new IllegalArgumentException(Msg.getString("K0045")); //$NON-NLS-1$
         }
+        int val = on ? (65535 < timeout ? 65535 : timeout) : -1;
+        impl.setOption(SocketOptions.SO_LINGER, Integer.valueOf(val));
     }
 
     /**
@@ -655,11 +608,10 @@
      */
     public synchronized void setSoTimeout(int timeout) throws SocketException {
         checkClosedAndCreate(true);
-        if (timeout >= 0) {
-            impl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
-        } else {
+        if (timeout < 0) {
             throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
         }
+        impl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
     }
 
     /**
@@ -697,6 +649,7 @@
     void startupSocket(InetAddress dstAddress, int dstPort,
             InetAddress localAddress, int localPort, boolean streaming)
             throws IOException {
+
         if (localPort < 0 || localPort > 65535) {
             throw new IllegalArgumentException(Msg.getString("K0046")); //$NON-NLS-1$
         }
@@ -969,8 +922,8 @@
             try {
                 if (!isBound()) {
                     // socket allready created at this point by earlier call or
-                    // checkClosedAndCreate
-                    // this caused us to lose socket options on create
+                    // checkClosedAndCreate this caused us to lose socket
+                    // options on create
                     // impl.create(true);
                     if (!NetUtil.usingSocks(proxy)) {
                         impl.bind(InetAddress.ANY, 0);
@@ -1125,10 +1078,7 @@
     static boolean preferIPv4Stack() {
         String result = AccessController.doPrivileged(new PriviAction<String>(
                 "java.net.preferIPv4Stack")); //$NON-NLS-1$
-        if ("true".equals(result)) { //$NON-NLS-1$
-            return true;
-        }
-        return false;
+        return "true".equals(result); //$NON-NLS-1$
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketAddress.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketAddress.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketAddress.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketAddress.java Fri Jan  5 06:44:04 2007
@@ -17,12 +17,11 @@
 
 package java.net;
 
-
 import java.io.Serializable;
 
 public abstract class SocketAddress implements Serializable {
 
-	public SocketAddress() {
-		super();
-	}
+    public SocketAddress() {
+        super();
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketException.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketException.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketException.java Fri Jan  5 06:44:04 2007
@@ -17,7 +17,6 @@
 
 package java.net;
 
-
 import java.io.IOException;
 
 /**
@@ -29,21 +28,20 @@
     private static final long serialVersionUID = -5935874303556886934L;
 
     /**
-	 * Constructs a new instance of this class with its walkback filled in.
-	 */
-	public SocketException() {
-		super();
-	}
-
-	/**
-	 * Constructs a new instance of this class with its walkback and message
-	 * filled in.
-	 * 
-	 * @param detailMessage
-	 *            String The detail message for the exception.
-	 */
-	public SocketException(String detailMessage) {
-		super(detailMessage);
-	}
+     * Constructs a new instance of this class with its walkback filled in.
+     */
+    public SocketException() {
+        super();
+    }
 
+    /**
+     * Constructs a new instance of this class with its walkback and message
+     * filled in.
+     * 
+     * @param detailMessage
+     *            String The detail message for the exception.
+     */
+    public SocketException(String detailMessage) {
+        super(detailMessage);
+    }
 }



Mime
View raw message