harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r493040 [1/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
Author: tellison
Date: Fri Jan  5 06:44:04 2007
New Revision: 493040

URL: http://svn.apache.org/viewvc?view=rev&rev=493040
Log:
Code review of java.net for clarity, formatting, comments, nls, etc.


Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Authenticator.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/BindException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ConnectException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandlerFactory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CookieHandler.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramPacket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImplFactory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/FileNameMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpRetryException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/JarURLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MalformedURLException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetPermission.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NoRouteToHostException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PortUnreachableException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProtocolException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelector.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketAddress.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImplFactory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketOptions.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketTimeoutException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URIEncoderDecoder.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URISyntaxException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandlerFactory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/UnknownHostException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/UnknownServiceException.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/ExternalMessages.properties

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Authenticator.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Authenticator.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Authenticator.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Authenticator.java Fri Jan  5 06:44:04 2007
@@ -31,304 +31,301 @@
  */
 public abstract class Authenticator {
 
-	// the default authenticator that needs to be set
-	private static Authenticator thisAuthenticator;
+    // the default authenticator that needs to be set
+    private static Authenticator thisAuthenticator;
 
-	private static final NetPermission requestPasswordAuthenticationPermission = new NetPermission(
-			"requestPasswordAuthentication"); //$NON-NLS-1$
+    private static final NetPermission requestPasswordAuthenticationPermission = new NetPermission(
+            "requestPasswordAuthentication"); //$NON-NLS-1$
 
-	private static final NetPermission setDefaultAuthenticatorPermission = new NetPermission(
-			"setDefaultAuthenticator"); //$NON-NLS-1$
+    private static final NetPermission setDefaultAuthenticatorPermission = new NetPermission(
+            "setDefaultAuthenticator"); //$NON-NLS-1$
 
-	// the requester connection info
-	private String host;
-
-	private InetAddress addr;
-
-	private int port;
-
-	private String protocol;
-
-	private String prompt;
-
-	private String scheme;
-	    
-	private URL url; 
-
-	private RequestorType rt;
-
-	/**
-	 * This method is responsible for retrieving the username and password for
-	 * the sender. The implementation varies. The subclass has to overwrite
-	 * this.
-	 * <p>
-	 * It answers null by default.
-	 * 
-	 * @return java.net.PasswordAuthentication The password authentication that
-	 *         it obtains
-	 */
-	protected PasswordAuthentication getPasswordAuthentication() {
-		return null;
-	}
-
-	/**
-	 * Answers the port of the connection that requests authorization.
-	 * 
-	 * @return int the port of the connection
-	 */
-	protected final int getRequestingPort() {
-		return this.port;
-	}
-
-	/**
-	 * Answers the address of the connection that requests authorization or null
-	 * if unknown.
-	 * 
-	 * @return InetAddress the address of the connection
-	 */
-	protected final InetAddress getRequestingSite() {
-		return this.addr;
-	}
-
-	/**
-	 * Answers the realm (prompt string) of the connection that requires
-	 * authorization.
-	 * 
-	 * @return java.lang.String the prompt string of the connection
-	 */
-	protected final String getRequestingPrompt() {
-		return this.prompt;
-	}
-
-	/**
-	 * Answers the protocol of the connection that requests authorization.
-	 * 
-	 * @return java.lang.String the protocol of connection
-	 */
-	protected final String getRequestingProtocol() {
-		return this.protocol;
-	}
-
-	/**
-	 * Answers the scheme of the connection that requires authorization. Eg.
-	 * Basic
-	 * 
-	 * @return java.lang.String the scheme of the connection
-	 */
-	protected final String getRequestingScheme() {
-		return this.scheme;
-	}
-
-	/**
-	 * If the permission check of the security manager does not result in a
-	 * security exception, this method invokes the methods of the registered
-	 * authenticator to get the authentication info.
-	 * 
-	 * @return java.net.PasswordAuthentication the authentication info
-	 * 
-	 * @param rAddr
-	 *            java.net.InetAddress the address of the connection that
-	 *            requests authentication
-	 * @param rPort
-	 *            int the port of the connection that requests
-	 *            authentication
-	 * @param rProtocol
-	 *            java.lang.String the protocol of the connection that requests
-	 *            authentication
-	 * @param rPrompt
-	 *            java.lang.String the realm of the connection that requests
-	 *            authentication
-	 * @param rScheme
-	 *            java.lang.String the scheme of the connection that requests
-	 *            authentication
-	 * @throws SecurityException
-	 *             if requestPasswordAuthenticationPermission is denied
-	 */
-	public static synchronized PasswordAuthentication requestPasswordAuthentication(
-			InetAddress rAddr, int rPort, String rProtocol, String rPrompt,
-			String rScheme) {
-		SecurityManager sm = System.getSecurityManager();
-		if (sm != null) {
-			sm.checkPermission(requestPasswordAuthenticationPermission);
-		}
-		if (thisAuthenticator == null) {
-			return null;
-		}
-		// set the requester info so it knows what it is requesting
-		// authentication for
-		thisAuthenticator.addr = rAddr;
-		thisAuthenticator.port = rPort;
-		thisAuthenticator.protocol = rProtocol;
-		thisAuthenticator.prompt = rPrompt;
-		thisAuthenticator.scheme = rScheme;
-		thisAuthenticator.rt = RequestorType.SERVER;
-
-		// returns the authentication info obtained by the registered
-		// Authenticator
-		return thisAuthenticator.getPasswordAuthentication();
-	}
-
-	/**
-	 * This method sets <code>a</code> to be the default authenticator. It
-	 * will be called whenever the realm that the URL is pointing to requires
-	 * authorization. If there is a security manager set then the caller must
-	 * have the NetPermission "setDefaultAuthenticator".
-	 * 
-	 * @param a
-	 *            java.net.Authenticator The authenticator to be set.
-	 * @throws SecurityException
-	 *             if requestPasswordAuthenticationPermission is denied
-	 */
-	public static void setDefault(Authenticator a) {
-		SecurityManager sm = System.getSecurityManager();
-		if (sm != null) {
-			sm.checkPermission(setDefaultAuthenticatorPermission);
-		}
-		thisAuthenticator = a;
-	}
-
-	/**
-	 * If the permission check of the security manager does not result in a
-	 * security exception, this method invokes the methods of the registered
-	 * authenticator to get the authentication info.
-	 * 
-	 * @return java.net.PasswordAuthentication the authentication info
-	 * 
-	 * @param rHost
-	 *            java.lang.String the host name of the connection that requests
-	 *            authentication
-	 * @param rAddr
-	 *            java.net.InetAddress the address of the connection that
-	 *            requests authentication
-	 * @param rPort
-	 *            int the port of the connection that requests
-	 *            authentication
-	 * @param rProtocol
-	 *            java.lang.String the protocol of the connection that requests
-	 *            authentication
-	 * @param rPrompt
-	 *            java.lang.String the realm of the connection that requests
-	 *            authentication
-	 * @param rScheme
-	 *            java.lang.String the scheme of the connection that requests
-	 *            authentication
-	 * @throws SecurityException
-	 *             if requestPasswordAuthenticationPermission is denied
-	 */
-	public static synchronized PasswordAuthentication requestPasswordAuthentication(
-			String rHost, InetAddress rAddr, int rPort, String rProtocol,
-			String rPrompt, String rScheme) {
-		SecurityManager sm = System.getSecurityManager();
-		if (sm != null) {
-			sm.checkPermission(requestPasswordAuthenticationPermission);
-		}
-		if (thisAuthenticator == null) {
-			return null;
-		}
-		// set the requester info so it knows what it is requesting
-		// authentication for
-		thisAuthenticator.host = rHost;
-		thisAuthenticator.addr = rAddr;
-		thisAuthenticator.port = rPort;
-		thisAuthenticator.protocol = rProtocol;
-		thisAuthenticator.prompt = rPrompt;
-		thisAuthenticator.scheme = rScheme;
-		thisAuthenticator.rt = RequestorType.SERVER;
-
-		// returns the authentication info obtained by the registered
-		// Authenticator
-		return thisAuthenticator.getPasswordAuthentication();
-	}
-
-	/**
-	 * Return the host name of the connection that requests authentication, or
-	 * null if unknown.
-	 */
-	protected final String getRequestingHost() {
-		return host;
-	}
-	
-
-	/**
-	 * If the permission check of the security manager does not result in a
-	 * security exception, this method invokes the methods of the registered
-	 * authenticator to get the authentication info.
-	 * 
-	 * @return java.net.PasswordAuthentication the authentication info
-	 * 
-	 * @param rHost
-	 *            java.lang.String the host name of the connection that requests
-	 *            authentication
-	 * @param rAddr
-	 *            java.net.InetAddress the address of the connection that
-	 *            requests authentication
-	 * @param rPort
-	 *            int the port of the connection that requests authentication
-	 * @param rProtocol
-	 *            java.lang.String the protocol of the connection that requests
-	 *            authentication
-	 * @param rPrompt
-	 *            java.lang.String the realm of the connection that requests
-	 *            authentication
-	 * @param rScheme
-	 *            java.lang.String the scheme of the connection that requests
-	 *            authentication
-	 * @param rURL
-	 *            java.net.URL the url of the connection that requests
-	 *            authentication
-	 * @param reqType
-	 *            java.net.Authenticator.RequestorType the RequestorType of the
-	 *            connection that requests authentication
-	 * @throws SecurityException
-	 *             if requestPasswordAuthenticationPermission is denied
-	 */
-	public static PasswordAuthentication requestPasswordAuthentication(
-			String rHost, InetAddress rAddr, int rPort, String rProtocol,
-			String rPrompt, String rScheme, URL rURL,
-			Authenticator.RequestorType reqType) {
-		SecurityManager sm = System.getSecurityManager();
-		if (null != sm) {
-			sm.checkPermission(requestPasswordAuthenticationPermission);
-		}
-		if (null == thisAuthenticator) {
-			return null;
-		}
-		// sets the requester info so it knows what it is requesting
-		// authentication for
-		thisAuthenticator.host = rHost;
-		thisAuthenticator.addr = rAddr;
-		thisAuthenticator.port = rPort;
-		thisAuthenticator.protocol = rProtocol;
-		thisAuthenticator.prompt = rPrompt;
-		thisAuthenticator.scheme = rScheme;
-		thisAuthenticator.url = rURL;
-		thisAuthenticator.rt = reqType;
-
-		// returns the authentication info obtained by the registered
-		// Authenticator
-		return thisAuthenticator.getPasswordAuthentication();
-
-	}
-
-	/**
-	 * returns the URL of the authentication resulted in this request.
-	 * 
-	 * @return the url of request
-	 */
-	protected URL getRequestingURL() {
-		return url;
-	}
-
-	/**
-	 * returns the type of this request, it can be proxy or server
-	 * 
-	 * @return RequestorType of request
-	 */
-	protected Authenticator.RequestorType getRequestorType() {
-		return rt;
-	}
+    // the requester connection info
+    private String host;
+
+    private InetAddress addr;
+
+    private int port;
+
+    private String protocol;
+
+    private String prompt;
+
+    private String scheme;
+
+    private URL url;
+
+    private RequestorType rt;
+
+    /**
+     * This method is responsible for retrieving the username and password for
+     * the sender. The implementation varies. The subclass has to overwrite
+     * this.
+     * <p>
+     * It answers null by default.
+     * 
+     * @return java.net.PasswordAuthentication The password authentication that
+     *         it obtains
+     */
+    protected PasswordAuthentication getPasswordAuthentication() {
+        return null;
+    }
+
+    /**
+     * Answers the port of the connection that requests authorization.
+     * 
+     * @return int the port of the connection
+     */
+    protected final int getRequestingPort() {
+        return this.port;
+    }
+
+    /**
+     * Answers the address of the connection that requests authorization or null
+     * if unknown.
+     * 
+     * @return InetAddress the address of the connection
+     */
+    protected final InetAddress getRequestingSite() {
+        return this.addr;
+    }
+
+    /**
+     * Answers the realm (prompt string) of the connection that requires
+     * authorization.
+     * 
+     * @return java.lang.String the prompt string of the connection
+     */
+    protected final String getRequestingPrompt() {
+        return this.prompt;
+    }
+
+    /**
+     * Answers the protocol of the connection that requests authorization.
+     * 
+     * @return java.lang.String the protocol of connection
+     */
+    protected final String getRequestingProtocol() {
+        return this.protocol;
+    }
+
+    /**
+     * Answers the scheme of the connection that requires authorization. Eg.
+     * Basic
+     * 
+     * @return java.lang.String the scheme of the connection
+     */
+    protected final String getRequestingScheme() {
+        return this.scheme;
+    }
+
+    /**
+     * If the permission check of the security manager does not result in a
+     * security exception, this method invokes the methods of the registered
+     * authenticator to get the authentication info.
+     * 
+     * @return java.net.PasswordAuthentication the authentication info
+     * 
+     * @param rAddr
+     *            java.net.InetAddress the address of the connection that
+     *            requests authentication
+     * @param rPort
+     *            int the port of the connection that requests authentication
+     * @param rProtocol
+     *            java.lang.String the protocol of the connection that requests
+     *            authentication
+     * @param rPrompt
+     *            java.lang.String the realm of the connection that requests
+     *            authentication
+     * @param rScheme
+     *            java.lang.String the scheme of the connection that requests
+     *            authentication
+     * @throws SecurityException
+     *             if requestPasswordAuthenticationPermission is denied
+     */
+    public static synchronized PasswordAuthentication requestPasswordAuthentication(
+            InetAddress rAddr, int rPort, String rProtocol, String rPrompt,
+            String rScheme) {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(requestPasswordAuthenticationPermission);
+        }
+        if (thisAuthenticator == null) {
+            return null;
+        }
+        // set the requester info so it knows what it is requesting
+        // authentication for
+        thisAuthenticator.addr = rAddr;
+        thisAuthenticator.port = rPort;
+        thisAuthenticator.protocol = rProtocol;
+        thisAuthenticator.prompt = rPrompt;
+        thisAuthenticator.scheme = rScheme;
+        thisAuthenticator.rt = RequestorType.SERVER;
+
+        // returns the authentication info obtained by the registered
+        // Authenticator
+        return thisAuthenticator.getPasswordAuthentication();
+    }
+
+    /**
+     * This method sets <code>a</code> to be the default authenticator. It
+     * will be called whenever the realm that the URL is pointing to requires
+     * authorization. If there is a security manager set then the caller must
+     * have the NetPermission "setDefaultAuthenticator".
+     * 
+     * @param a
+     *            java.net.Authenticator The authenticator to be set.
+     * @throws SecurityException
+     *             if requestPasswordAuthenticationPermission is denied
+     */
+    public static void setDefault(Authenticator a) {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(setDefaultAuthenticatorPermission);
+        }
+        thisAuthenticator = a;
+    }
+
+    /**
+     * If the permission check of the security manager does not result in a
+     * security exception, this method invokes the methods of the registered
+     * authenticator to get the authentication info.
+     * 
+     * @return java.net.PasswordAuthentication the authentication info
+     * 
+     * @param rHost
+     *            java.lang.String the host name of the connection that requests
+     *            authentication
+     * @param rAddr
+     *            java.net.InetAddress the address of the connection that
+     *            requests authentication
+     * @param rPort
+     *            int the port of the connection that requests authentication
+     * @param rProtocol
+     *            java.lang.String the protocol of the connection that requests
+     *            authentication
+     * @param rPrompt
+     *            java.lang.String the realm of the connection that requests
+     *            authentication
+     * @param rScheme
+     *            java.lang.String the scheme of the connection that requests
+     *            authentication
+     * @throws SecurityException
+     *             if requestPasswordAuthenticationPermission is denied
+     */
+    public static synchronized PasswordAuthentication requestPasswordAuthentication(
+            String rHost, InetAddress rAddr, int rPort, String rProtocol,
+            String rPrompt, String rScheme) {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            sm.checkPermission(requestPasswordAuthenticationPermission);
+        }
+        if (thisAuthenticator == null) {
+            return null;
+        }
+        // set the requester info so it knows what it is requesting
+        // authentication for
+        thisAuthenticator.host = rHost;
+        thisAuthenticator.addr = rAddr;
+        thisAuthenticator.port = rPort;
+        thisAuthenticator.protocol = rProtocol;
+        thisAuthenticator.prompt = rPrompt;
+        thisAuthenticator.scheme = rScheme;
+        thisAuthenticator.rt = RequestorType.SERVER;
+
+        // returns the authentication info obtained by the registered
+        // Authenticator
+        return thisAuthenticator.getPasswordAuthentication();
+    }
+
+    /**
+     * Return the host name of the connection that requests authentication, or
+     * null if unknown.
+     */
+    protected final String getRequestingHost() {
+        return host;
+    }
+
+    /**
+     * If the permission check of the security manager does not result in a
+     * security exception, this method invokes the methods of the registered
+     * authenticator to get the authentication info.
+     * 
+     * @return java.net.PasswordAuthentication the authentication info
+     * 
+     * @param rHost
+     *            java.lang.String the host name of the connection that requests
+     *            authentication
+     * @param rAddr
+     *            java.net.InetAddress the address of the connection that
+     *            requests authentication
+     * @param rPort
+     *            int the port of the connection that requests authentication
+     * @param rProtocol
+     *            java.lang.String the protocol of the connection that requests
+     *            authentication
+     * @param rPrompt
+     *            java.lang.String the realm of the connection that requests
+     *            authentication
+     * @param rScheme
+     *            java.lang.String the scheme of the connection that requests
+     *            authentication
+     * @param rURL
+     *            java.net.URL the url of the connection that requests
+     *            authentication
+     * @param reqType
+     *            java.net.Authenticator.RequestorType the RequestorType of the
+     *            connection that requests authentication
+     * @throws SecurityException
+     *             if requestPasswordAuthenticationPermission is denied
+     */
+    public static PasswordAuthentication requestPasswordAuthentication(
+            String rHost, InetAddress rAddr, int rPort, String rProtocol,
+            String rPrompt, String rScheme, URL rURL,
+            Authenticator.RequestorType reqType) {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(requestPasswordAuthenticationPermission);
+        }
+        if (null == thisAuthenticator) {
+            return null;
+        }
+        // sets the requester info so it knows what it is requesting
+        // authentication for
+        thisAuthenticator.host = rHost;
+        thisAuthenticator.addr = rAddr;
+        thisAuthenticator.port = rPort;
+        thisAuthenticator.protocol = rProtocol;
+        thisAuthenticator.prompt = rPrompt;
+        thisAuthenticator.scheme = rScheme;
+        thisAuthenticator.url = rURL;
+        thisAuthenticator.rt = reqType;
+
+        // returns the authentication info obtained by the registered
+        // Authenticator
+        return thisAuthenticator.getPasswordAuthentication();
+
+    }
+
+    /**
+     * returns the URL of the authentication resulted in this request.
+     * 
+     * @return the url of request
+     */
+    protected URL getRequestingURL() {
+        return url;
+    }
+
+    /**
+     * returns the type of this request, it can be proxy or server
+     * 
+     * @return RequestorType of request
+     */
+    protected Authenticator.RequestorType getRequestorType() {
+        return rt;
+    }
 
-	/**
+    /**
      * an enum class of requestor type
      */
     public enum RequestorType {

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/BindException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/BindException.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/BindException.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/BindException.java Fri Jan  5 06:44:04 2007
@@ -17,7 +17,6 @@
 
 package java.net;
 
-
 /**
  * A BindException is thrown when a process cannot bind a local address/port,
  * either because it is already bound or reserved by the OS.
@@ -27,20 +26,20 @@
     private static final long serialVersionUID = -5945005768251722951L;
 
     /**
-	 * Constructs a new instance of this class with its walkback filled in.
-	 */
-	public BindException() {
-		super();
-	}
+     * Constructs a new instance of this class with its walkback filled in.
+     */
+    public BindException() {
+        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 BindException(String detailMessage) {
-		super(detailMessage);
-	}
+    /**
+     * Constructs a new instance of this class with its walkback and message
+     * filled in.
+     * 
+     * @param detailMessage
+     *            String The detail message for the exception.
+     */
+    public BindException(String detailMessage) {
+        super(detailMessage);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java Fri Jan  5 06:44:04 2007
@@ -20,37 +20,41 @@
 import java.io.OutputStream;
 
 /**
- * CacheRequest provides channels for storing resource data in the <code>ResponseCache</code>.
- * Protocol handler calls the <code>OutputStream</code> which is supplied by CachedRequest 
- * object, to store the resource data into the cache. It also allows the user to interrupt 
- * and abort the current store operation by calling method <code>abort</code>. 
- * If IOException occurs while reading the response or writing data to the cache, 
- * the current cache store operation will be abandoned.
- *
+ * CacheRequest provides channels for storing resource data in the
+ * <code>ResponseCache</code>. Protocol handler calls the
+ * <code>OutputStream</code> which is supplied by CachedRequest object, to
+ * store the resource data into the cache. It also allows the user to interrupt
+ * and abort the current store operation by calling method <code>abort</code>.
+ * If IOException occurs while reading the response or writing data to the
+ * cache, the current cache store operation will be abandoned.
  */
 public abstract class CacheRequest {
-	
-	/**
-	 * Constructor method. 
-	 */
-	public CacheRequest() {
-		super();
-	}
 
-	/**
-	 * Aborts the current cache operation.
-	 * If an IOException occurs while reading the response or writing resource data to the cache,
-	 * the current cache store operation will be aborted. 
-	 */
-	public abstract void abort();
-	
-	/**
-	 * <p>
-	 * Returns an <code>OutputStream</code>, which is used to write the response body.
-	 * </p>
-	 * @return an <code>OutputStream</code> which is used to write the response body. 
-	 * @throws IOException
-	 *             if an I/O error is encountered during writing response body operation.
-	 */
-	public abstract OutputStream getBody() throws IOException;
+    /**
+     * Constructor method.
+     */
+    public CacheRequest() {
+        super();
+    }
+
+    /**
+     * Aborts the current cache operation. If an IOException occurs while
+     * reading the response or writing resource data to the cache, the current
+     * cache store operation will be aborted.
+     */
+    public abstract void abort();
+
+    /**
+     * <p>
+     * Returns an <code>OutputStream</code>, which is used to write the
+     * response body.
+     * </p>
+     * 
+     * @return an <code>OutputStream</code> which is used to write the
+     *         response body.
+     * @throws IOException
+     *             if an I/O error is encountered during writing response body
+     *             operation.
+     */
+    public abstract OutputStream getBody() throws IOException;
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java Fri Jan  5 06:44:04 2007
@@ -22,39 +22,43 @@
 import java.util.Map;
 
 /**
- * CacheResponse is used for getting resource from the ResponseCache. 
- * An CacheResponse object provides an <code>InputStream</code> to access the response body,
- * and also a method <code>getHeaders()</code> to fetch the response headers.
- * 
+ * CacheResponse is used for getting resource from the ResponseCache. An
+ * CacheResponse object provides an <code>InputStream</code> to access the
+ * response body, and also a method <code>getHeaders()</code> to fetch the
+ * response headers.
  */
 public abstract class CacheResponse {
-	/**
-	 * Constructor method
-	 */
-	public CacheResponse() {
-		super();
-	}
+    /**
+     * Constructor method
+     */
+    public CacheResponse() {
+        super();
+    }
 
-	/**
-	 * <p>
-	 * Returns an <code>InputStream</code> for the respsonse body access.
-	 * </p>
-	 * @return an <code>InputStream</code>, which can be used to fetch the response body.
-	 * @throws IOException
-	 *             if an I/O error is encounted while retrieving the response body.
-	 */
-	public abstract InputStream getBody() throws IOException;
+    /**
+     * Returns an <code>InputStream</code> for the respsonse body access.
+     * 
+     * @return an <code>InputStream</code>, which can be used to fetch the
+     *         response body.
+     * @throws IOException
+     *             if an I/O error is encounted while retrieving the response
+     *             body.
+     */
+    public abstract InputStream getBody() throws IOException;
 
-	/**
-	 * <p>
-	 * Returns an immutable <code>Map</code>, which contains the response headers information.
-	 * @return an immutable <code>Map</code>, which contains the response headers. 
-	 * The map is from response header field names to lists of field values.
-	 * Field name is a <code>String</code>, and the field values list is a <code>List</code>
-	 * of <code>String</code>.The status line as its field name has null as its list of field values.
-	 * </p> 
-	 * @throws IOException
-	 *             if an I/O error is encounted while retrieving the response headers.
-	 */
-	public abstract Map<String,List<String>> getHeaders() throws IOException;
+    /**
+     * Returns an immutable <code>Map</code>, which contains the response
+     * headers information.
+     * 
+     * @return an immutable <code>Map</code>, which contains the response
+     *         headers. The map is from response header field names to lists of
+     *         field values. Field name is a <code>String</code>, and the
+     *         field values list is a <code>List</code> of <code>String</code>.The
+     *         status line as its field name has null as its list of field
+     *         values.
+     * @throws IOException
+     *             if an I/O error is encounted while retrieving the response
+     *             headers.
+     */
+    public abstract Map<String, List<String>> getHeaders() throws IOException;
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ConnectException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ConnectException.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ConnectException.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ConnectException.java Fri Jan  5 06:44:04 2007
@@ -17,7 +17,6 @@
 
 package java.net;
 
-
 /**
  * This ConnectException is thrown when a connection cannot be established to a
  * remote host/port, because for instance a server was not listening.
@@ -27,20 +26,20 @@
     private static final long serialVersionUID = 3831404271622369215L;
 
     /**
-	 * Constructs a new instance of this class with its walkback filled in.
-	 */
-	public ConnectException() {
-		super();
-	}
+     * Constructs a new instance of this class with its walkback filled in.
+     */
+    public ConnectException() {
+        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 ConnectException(String detailMessage) {
-		super(detailMessage);
-	}
+    /**
+     * Constructs a new instance of this class with its walkback and message
+     * filled in.
+     * 
+     * @param detailMessage
+     *            String The detail message for the exception.
+     */
+    public ConnectException(String detailMessage) {
+        super(detailMessage);
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandler.java Fri Jan  5 06:44:04 2007
@@ -58,8 +58,8 @@
      * @throws IOException
      *             If an error occurred obtaining the content.
      */
-    @SuppressWarnings("unchecked")
     // Class arg not generified in the spec.
+    @SuppressWarnings("unchecked")
     public Object getContent(URLConnection uConn, Class[] types)
             throws IOException {
         Object content = getContent(uConn);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandlerFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandlerFactory.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandlerFactory.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ContentHandlerFactory.java Fri Jan  5 06:44:04 2007
@@ -17,17 +17,16 @@
 
 package java.net;
 
-
 /**
  * Defines a factory which is reponsible for creating a ContentHandler
  */
 public interface ContentHandlerFactory {
-	/**
-	 * Creates a content handler to handle <code>contentType</code>
-	 * 
-	 * @return java.net.ContentHandler
-	 * @param contentType
-	 *            java.lang.String
-	 */
-	ContentHandler createContentHandler(String contentType);
+    /**
+     * Creates a content handler to handle <code>contentType</code>
+     * 
+     * @return java.net.ContentHandler
+     * @param contentType
+     *            java.lang.String
+     */
+    ContentHandler createContentHandler(String contentType);
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CookieHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CookieHandler.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CookieHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CookieHandler.java Fri Jan  5 06:44:04 2007
@@ -22,46 +22,45 @@
 
 /**
  * This class is ready for managing a stateful cookie with HTTP protocol
- * 
  */
 public abstract class CookieHandler {
 
-	private static CookieHandler systemWideCookieHandler;
+    private static CookieHandler systemWideCookieHandler;
 
-	private final static NetPermission getCookieHandlerPermission = new NetPermission(
-			"getCookieHandler"); //$NON-NLS-1$
+    private final static NetPermission getCookieHandlerPermission = new NetPermission(
+            "getCookieHandler"); //$NON-NLS-1$
 
-	private final static NetPermission setCookieHandlerPermission = new NetPermission(
-			"setCookieHandler"); //$NON-NLS-1$
+    private final static NetPermission setCookieHandlerPermission = new NetPermission(
+            "setCookieHandler"); //$NON-NLS-1$
 
-	/**
-	 * returns a system-wide cookie handler, or null if not set
-	 * 
-	 * @return a cookie handler
-	 */
-	public static CookieHandler getDefault() {
-		SecurityManager sm = System.getSecurityManager();
-		if (null != sm) {
-			sm.checkPermission(getCookieHandlerPermission);
-		}
-		return systemWideCookieHandler;
-	}
-
-	/**
-	 * sets a system-wide cookie handler
-	 * 
-	 * @param cHandler
-	 *            the cookie handler to set
-	 */
-	public static void setDefault(CookieHandler cHandler) {
-		SecurityManager sm = System.getSecurityManager();
-		if (null != sm) {
-			sm.checkPermission(setCookieHandlerPermission);
-		}
-		systemWideCookieHandler = cHandler;
-	}
+    /**
+     * Returns a system-wide cookie handler, or null if not set
+     * 
+     * @return a cookie handler
+     */
+    public static CookieHandler getDefault() {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(getCookieHandlerPermission);
+        }
+        return systemWideCookieHandler;
+    }
+
+    /**
+     * sets a system-wide cookie handler
+     * 
+     * @param cHandler
+     *            the cookie handler to set
+     */
+    public static void setDefault(CookieHandler cHandler) {
+        SecurityManager sm = System.getSecurityManager();
+        if (null != sm) {
+            sm.checkPermission(setCookieHandlerPermission);
+        }
+        systemWideCookieHandler = cHandler;
+    }
 
-	/**
+    /**
      * Searchs and gets all cookies in the cache by the specified uri in the
      * request header.
      * 
@@ -76,7 +75,7 @@
     public abstract Map<String, List<String>> get(URI uri,
             Map<String, List<String>> requestHeaders) throws IOException;
 
-	/**
+    /**
      * Sets cookies according to uri and responseHeaders
      * 
      * @param uri

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramPacket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramPacket.java?view=diff&rev=493040&r1=493039&r2=493040
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramPacket.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramPacket.java Fri Jan  5 06:44:04 2007
@@ -19,7 +19,6 @@
 
 import org.apache.harmony.luni.util.Msg;
 
-
 /**
  * This class models a datagram packet to be sent or received. The
  * DatagramPacket(byte[], int, InetAddress, int) constructor is used for packets
@@ -29,262 +28,262 @@
  * @see DatagramSocket
  */
 public final class DatagramPacket {
-	
-	byte[] data;
 
-	int length;
+    byte[] data;
+
+    int length;
 
-	InetAddress address;
+    InetAddress address;
 
-	int port = -1; // The default port number is -1
+    int port = -1; // The default port number is -1
 
-	int offset = 0;
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for receiving
-	 * datagram packets of length up to <code>length</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param length
-	 *            length of the data buffer
-	 */
-	public DatagramPacket(byte[] data, int length) {
-		this(data, 0, length);
-	}
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for receiving
-	 * datagram packets of length up to <code>length</code>, with an offset
-	 * into the buffer <code>offset</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param offset
-	 *            the offset into the byte array
-	 * @param length
-	 *            length of the data buffer
-	 */
-	public DatagramPacket(byte[] data, int offset, int length) {
-		super();
-		setData(data, offset, length);
-	}
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for sending
-	 * packets to the nominated host/port. The <code>length</code> must be
-	 * less than or equal to the size of <code>data</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param offset
-	 *            the offset in to read/write from
-	 * @param length
-	 *            length of the data buffer
-	 * @param host
-	 *            address of the target host
-	 * @param aPort
-	 *            target host port
-	 */
-
-	public DatagramPacket(byte[] data, int offset, int length,
-			InetAddress host, int aPort) {
-		this(data, offset, length);
-		setPort(aPort);
-		address = host;
-	}
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for sending
-	 * packets to the nominated host/port. The <code>length</code> must be
-	 * less than or equal to the size of <code>data</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param length
-	 *            length of the data buffer
-	 * @param host
-	 *            address of the target host
-	 * @param port
-	 *            target host port
-	 */
-	public DatagramPacket(byte[] data, int length, InetAddress host, int port) {
-		this(data, 0, length, host, port);
-	}
-
-	/**
-	 * Answer the IP address of the machine that is the target or sender of this
-	 * datagram.
-	 * 
-	 * @return InetAddress the target host address
-	 */
-	public synchronized InetAddress getAddress() {
-		return address;
-	}
-
-	/**
-	 * Answer the data sent or received in this datagram.
-	 * 
-	 * @return byte[] the data sent/received
-	 */
-	public synchronized byte[] getData() {
-		return data;
-	}
-
-	/**
-	 * Answer the length of the data sent or received in this datagram.
-	 * 
-	 * @return int the length of the sent/received data
-	 */
-	public synchronized int getLength() {
-		return length;
-	}
-
-	/**
-	 * Answer the offset of the data sent or received in this datagram buffer.
-	 * 
-	 * @return int the offset of the start of the sent/received data
-	 */
-	public synchronized int getOffset() {
-		return offset;
-	}
-
-	/**
-	 * Answer the port number of the target or sender machine of this datagram.
-	 * 
-	 * @return int for received packets, the sender address and for sent
-	 *         packets, the target host
-	 */
-
-	public synchronized int getPort() {
-		return port;
-	}
-
-	/**
-	 * Set the IP address of the machine that is the target of this datagram.
-	 * 
-	 * @param addr
-	 *            the target host address
-	 */
-	public synchronized void setAddress(InetAddress addr) {
-		address = addr;
-	}
-
-	/**
-	 * Set the data buffer for this datagram.
-	 * 
-	 * @param buf
-	 *            the data to be sent
-	 * @param anOffset
-	 *            the offset into the data
-	 * @param aLength
-	 *            the length of the data to be sent
-	 */
-	public synchronized void setData(byte[] buf, int anOffset, int aLength) {
-		if (0 > anOffset || anOffset > buf.length || 0 > aLength
-				|| aLength > buf.length - anOffset)
-			throw new IllegalArgumentException(org.apache.harmony.luni.util.Msg
-					.getString("K002f"));
-		data = buf;
-		offset = anOffset;
-		length = aLength;
-	}
-
-	/**
-	 * Set the data sent in this datagram.
-	 * 
-	 * @param buf
-	 *            the data to be sent
-	 */
-	public synchronized void setData(byte[] buf) {
-		length = buf.length; // This will check for null
-		data = buf;
-		offset = 0;
-	}
-
-	/**
-	 * Set the length of the data sent in this datagram.
-	 * 
-	 * @param len
-	 *            the length of the data to be sent
-	 */
-	public synchronized void setLength(int len) {
-		if (0 > len || offset + len > data.length) {
-			throw new IllegalArgumentException(Msg.getString("K002f"));
-		}
-		length = len;
-	}
-
-	/**
-	 * Set the port number of the target machine of this datagram.
-	 * 
-	 * @param aPort
-	 *            the target host port
-	 */
-	public synchronized void setPort(int aPort) {
-		if (aPort < 0 || aPort > 65535) {
-			throw new IllegalArgumentException(Msg.getString("K0325", aPort));
-		}
-		port = aPort;
-	}
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for sending
-	 * packets to the nominated host/port. The <code>length</code> must be
-	 * less than or equal to the size of <code>data</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param length
-	 *            length of the data buffer
-	 * @param sockAddr
-	 *            the machine address and port
-	 */
-	public DatagramPacket(byte[] data, int length, SocketAddress sockAddr) throws SocketException {
-		this(data, 0, length);
-		setSocketAddress(sockAddr);
-	}
-
-	/**
-	 * Constructs a new <code>DatagramPacket</code> suitable for sending
-	 * packets to the nominated host/port. The <code>length</code> must be
-	 * less than or equal to the size of <code>data</code>.
-	 * 
-	 * @param data
-	 *            byte array to store the read characters
-	 * @param offset
-	 *            the offset in to read/write from
-	 * @param length
-	 *            length of the data buffer
-	 * @param sockAddr
-	 *            the machine address and port
-	 */
-	public DatagramPacket(byte[] data, int offset, int length,
-			SocketAddress sockAddr) throws SocketException {
-		this(data, offset, length);
-		setSocketAddress(sockAddr);
-	}
-
-	/**
-	 * Answer the SocketAddress for this packet.
-	 */
-	public synchronized SocketAddress getSocketAddress() {
-		return new InetSocketAddress(getAddress(), getPort());
-	}
-
-	/**
-	 * Set the SocketAddress for this packet.
-	 * 
-	 * @param sockAddr
-	 *            the machine address and port
-	 */
-	public synchronized void setSocketAddress(SocketAddress sockAddr) {
-		if (!(sockAddr instanceof InetSocketAddress)) {
-			throw new IllegalArgumentException(Msg.getString(
-					"K0316", sockAddr == null ? null : sockAddr.getClass())); //$NON-NLS-1$
-		}
-		InetSocketAddress inetAddr = (InetSocketAddress) sockAddr;
-		port = inetAddr.getPort();
-		address = inetAddr.getAddress();
-	}
+    int offset = 0;
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for receiving
+     * datagram packets of length up to <code>length</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param length
+     *            length of the data buffer
+     */
+    public DatagramPacket(byte[] data, int length) {
+        this(data, 0, length);
+    }
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for receiving
+     * datagram packets of length up to <code>length</code>, with an offset
+     * into the buffer <code>offset</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param offset
+     *            the offset into the byte array
+     * @param length
+     *            length of the data buffer
+     */
+    public DatagramPacket(byte[] data, int offset, int length) {
+        super();
+        setData(data, offset, length);
+    }
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for sending
+     * packets to the nominated host/port. The <code>length</code> must be
+     * less than or equal to the size of <code>data</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param offset
+     *            the offset in to read/write from
+     * @param length
+     *            length of the data buffer
+     * @param host
+     *            address of the target host
+     * @param aPort
+     *            target host port
+     */
+
+    public DatagramPacket(byte[] data, int offset, int length,
+            InetAddress host, int aPort) {
+        this(data, offset, length);
+        setPort(aPort);
+        address = host;
+    }
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for sending
+     * packets to the nominated host/port. The <code>length</code> must be
+     * less than or equal to the size of <code>data</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param length
+     *            length of the data buffer
+     * @param host
+     *            address of the target host
+     * @param port
+     *            target host port
+     */
+    public DatagramPacket(byte[] data, int length, InetAddress host, int port) {
+        this(data, 0, length, host, port);
+    }
+
+    /**
+     * Answer the IP address of the machine that is the target or sender of this
+     * datagram.
+     * 
+     * @return InetAddress the target host address
+     */
+    public synchronized InetAddress getAddress() {
+        return address;
+    }
+
+    /**
+     * Answer the data sent or received in this datagram.
+     * 
+     * @return byte[] the data sent/received
+     */
+    public synchronized byte[] getData() {
+        return data;
+    }
+
+    /**
+     * Answer the length of the data sent or received in this datagram.
+     * 
+     * @return int the length of the sent/received data
+     */
+    public synchronized int getLength() {
+        return length;
+    }
+
+    /**
+     * Answer the offset of the data sent or received in this datagram buffer.
+     * 
+     * @return int the offset of the start of the sent/received data
+     */
+    public synchronized int getOffset() {
+        return offset;
+    }
+
+    /**
+     * Answer the port number of the target or sender machine of this datagram.
+     * 
+     * @return int for received packets, the sender address and for sent
+     *         packets, the target host
+     */
+    public synchronized int getPort() {
+        return port;
+    }
+
+    /**
+     * Set the IP address of the machine that is the target of this datagram.
+     * 
+     * @param addr
+     *            the target host address
+     */
+    public synchronized void setAddress(InetAddress addr) {
+        address = addr;
+    }
+
+    /**
+     * Set the data buffer for this datagram.
+     * 
+     * @param buf
+     *            the data to be sent
+     * @param anOffset
+     *            the offset into the data
+     * @param aLength
+     *            the length of the data to be sent
+     */
+    public synchronized void setData(byte[] buf, int anOffset, int aLength) {
+        if (0 > anOffset || anOffset > buf.length || 0 > aLength
+                || aLength > buf.length - anOffset) {
+            throw new IllegalArgumentException(Msg.getString("K002f")); //$NON-NLS-1$
+        }
+        data = buf;
+        offset = anOffset;
+        length = aLength;
+    }
+
+    /**
+     * Set the data sent in this datagram.
+     * 
+     * @param buf
+     *            the data to be sent
+     */
+    public synchronized void setData(byte[] buf) {
+        length = buf.length; // This will check for null
+        data = buf;
+        offset = 0;
+    }
+
+    /**
+     * Set the length of the data sent in this datagram.
+     * 
+     * @param len
+     *            the length of the data to be sent
+     */
+    public synchronized void setLength(int len) {
+        if (0 > len || offset + len > data.length) {
+            throw new IllegalArgumentException(Msg.getString("K002f")); //$NON-NLS-1$
+        }
+        length = len;
+    }
+
+    /**
+     * Set the port number of the target machine of this datagram.
+     * 
+     * @param aPort
+     *            the target host port
+     */
+    public synchronized void setPort(int aPort) {
+        if (aPort < 0 || aPort > 65535) {
+            throw new IllegalArgumentException(Msg.getString("K0325", aPort)); //$NON-NLS-1$
+        }
+        port = aPort;
+    }
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for sending
+     * packets to the nominated host/port. The <code>length</code> must be
+     * less than or equal to the size of <code>data</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param length
+     *            length of the data buffer
+     * @param sockAddr
+     *            the machine address and port
+     */
+    public DatagramPacket(byte[] data, int length, SocketAddress sockAddr)
+            throws SocketException {
+        this(data, 0, length);
+        setSocketAddress(sockAddr);
+    }
+
+    /**
+     * Constructs a new <code>DatagramPacket</code> suitable for sending
+     * packets to the nominated host/port. The <code>length</code> must be
+     * less than or equal to the size of <code>data</code>.
+     * 
+     * @param data
+     *            byte array to store the read characters
+     * @param offset
+     *            the offset in to read/write from
+     * @param length
+     *            length of the data buffer
+     * @param sockAddr
+     *            the machine address and port
+     */
+    public DatagramPacket(byte[] data, int offset, int length,
+            SocketAddress sockAddr) throws SocketException {
+        this(data, offset, length);
+        setSocketAddress(sockAddr);
+    }
+
+    /**
+     * Answer the SocketAddress for this packet.
+     */
+    public synchronized SocketAddress getSocketAddress() {
+        return new InetSocketAddress(getAddress(), getPort());
+    }
+
+    /**
+     * Set the SocketAddress for this packet.
+     * 
+     * @param sockAddr
+     *            the machine address and port
+     */
+    public synchronized void setSocketAddress(SocketAddress sockAddr) {
+        if (!(sockAddr instanceof InetSocketAddress)) {
+            throw new IllegalArgumentException(Msg.getString(
+                    "K0316", sockAddr == null ? null : sockAddr.getClass())); //$NON-NLS-1$
+        }
+        InetSocketAddress inetAddr = (InetSocketAddress) sockAddr;
+        port = inetAddr.getPort();
+        address = inetAddr.getAddress();
+    }
 }



Mime
View raw message