harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [108/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/GenericIPMreq.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/GenericIPMreq.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/GenericIPMreq.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/GenericIPMreq.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,102 @@
+/* Copyright 2005, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.util.Enumeration;
+
+/**
+ * This class provides is used to pass the information required in an ip_mreq or
+ * ip6_mreq structure to java natives. We don't have accessor methods as it is
+ * more straight forward in the natives to simply access the fields directly
+ */
+final class GenericIPMreq {
+
+	// private members
+	private InetAddress multiaddr;
+
+	private InetAddress interfaceAddr;
+
+	private boolean isIPV6Address;
+
+	private int interfaceIdx;
+
+	/**
+	 * This constructor is used to create an instance of the object
+	 * 
+	 * @param addr
+	 *            multicast address to join/leave
+	 * 
+	 */
+	GenericIPMreq(InetAddress addr) {
+		this.multiaddr = addr;
+		this.interfaceAddr = null;
+		this.interfaceIdx = 0;
+		init();
+	}
+
+	/**
+	 * This constructor is used to create an instance of the object
+	 * 
+	 * @param addr
+	 *            multicast address to join/leave
+	 * @param netInterface
+	 *            the NetworkInterface object identifying the interface on which
+	 *            to join/leave
+	 * 
+	 */
+	GenericIPMreq(InetAddress addr, NetworkInterface netInterface) {
+		this.multiaddr = addr;
+		if (null != netInterface) {
+			this.interfaceIdx = netInterface.getIndex();
+
+			// here we need to get the first IPV4 address as we only use it if
+			// we
+			// are settting the interface for an IPV4 multicast socket. For
+			// adds/drops on
+			// IPV6 addresses we use the index within the networkInterface
+			this.interfaceAddr = null;
+			Enumeration theAddresses = netInterface.getInetAddresses();
+			if ((addr instanceof Inet4Address) && (theAddresses != null)) {
+				boolean found = false;
+				while ((theAddresses.hasMoreElements()) && (found != true)) {
+					InetAddress theAddress = (InetAddress) theAddresses
+							.nextElement();
+					if (theAddress instanceof Inet4Address) {
+						this.interfaceAddr = theAddress;
+						found = true;
+					}
+				}
+			}
+		} else {
+			// network interface is null so we just want to defer the decision
+			// to
+			// the system
+			this.interfaceIdx = 0;
+			this.interfaceAddr = null;
+		}
+		init();
+	}
+
+	/**
+	 * This method does any required initialization for the constructors
+	 */
+	private void init() {
+		// set the flag indicating if the multicast address is an IPV6 address
+		// or not
+		isIPV6Address = ((this.multiaddr != null) && (this.multiaddr instanceof Inet6Address));
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/HttpURLConnection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/HttpURLConnection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/HttpURLConnection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/HttpURLConnection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,450 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.net.ProtocolException;
+import java.net.URL;
+
+/**
+ * This abstract subclass of <code>URLConnection</code> defines method for
+ * managing HTTP connection according to the description given by RFC 2068
+ * 
+ * @see ContentHandler
+ * @see URL
+ * @see URLConnection
+ * @see URLStreamHandler
+ */
+public abstract class HttpURLConnection extends java.net.URLConnection {
+	private String methodTokens[] = { "GET", "DELETE", "HEAD", "OPTIONS",
+			"POST", "PUT", "TRACE" };
+
+	protected String method = "GET"; // request method, DEFAULT: "GET"
+
+	protected int responseCode = -1; // response code obtained from the request
+
+	protected String responseMessage; // response message corresponds to the
+										// response code
+
+	protected boolean instanceFollowRedirects = followRedirects;
+
+	private static boolean followRedirects = true;
+
+	// 2XX: generally "OK"
+	// 3XX: relocation/redirect
+	// 4XX: client error
+	// 5XX: server error
+	/**
+	 * Numeric status code, 202: Accepted
+	 */
+	public final static int HTTP_ACCEPTED = 202;
+
+	/**
+	 * Numeric status code, 502: Bad Gateway
+	 */
+	public final static int HTTP_BAD_GATEWAY = 502;
+
+	/**
+	 * Numeric status code, 405: Bad Method
+	 */
+	public final static int HTTP_BAD_METHOD = 405;
+
+	/**
+	 * Numeric status code, 400: Bad Request
+	 */
+	public final static int HTTP_BAD_REQUEST = 400;
+
+	/**
+	 * Numeric status code, 408: Client Timeout
+	 */
+	public final static int HTTP_CLIENT_TIMEOUT = 408;
+
+	/**
+	 * Numeric status code, 409: Conflict
+	 */
+	public final static int HTTP_CONFLICT = 409;
+
+	/**
+	 * Numeric status code, 201: Created
+	 */
+	public final static int HTTP_CREATED = 201;
+
+	/**
+	 * Numeric status code, 413: Entity too large
+	 */
+	public final static int HTTP_ENTITY_TOO_LARGE = 413;
+
+	/**
+	 * Numeric status code, 403: Forbidden
+	 */
+	public final static int HTTP_FORBIDDEN = 403;
+
+	/**
+	 * Numeric status code, 504: atewaytimeout
+	 */
+	public final static int HTTP_GATEWAY_TIMEOUT = 504;
+
+	/**
+	 * Numeric status code, 410: Gone
+	 */
+	public final static int HTTP_GONE = 410;
+
+	/**
+	 * Numeric status code, 500: Internal error
+	 */
+	public final static int HTTP_INTERNAL_ERROR = 500;
+
+	/**
+	 * Numeric status code, 411: Length required
+	 */
+	public final static int HTTP_LENGTH_REQUIRED = 411;
+
+	/**
+	 * Numeric status code, 301 Moved permanently
+	 */
+	public final static int HTTP_MOVED_PERM = 301;
+
+	/**
+	 * Numeric status code, 302: Moved temporarily
+	 */
+	public final static int HTTP_MOVED_TEMP = 302;
+
+	/**
+	 * Numeric status code, 300: Multiple choices
+	 */
+	public final static int HTTP_MULT_CHOICE = 300;
+
+	/**
+	 * Numeric status code, 204: No content
+	 */
+	public final static int HTTP_NO_CONTENT = 204;
+
+	/**
+	 * Numeric status code, 406: Not acceptable
+	 */
+	public final static int HTTP_NOT_ACCEPTABLE = 406;
+
+	/**
+	 * Numeric status code, 203: Not authoritative
+	 */
+	public final static int HTTP_NOT_AUTHORITATIVE = 203;
+
+	/**
+	 * Numeric status code, 404: Not found
+	 */
+	public final static int HTTP_NOT_FOUND = 404;
+
+	/**
+	 * Numeric status code, 501: Not implemented
+	 */
+	public final static int HTTP_NOT_IMPLEMENTED = 501;
+
+	/**
+	 * Numeric status code, 304: Not modified
+	 */
+	public final static int HTTP_NOT_MODIFIED = 304;
+
+	/**
+	 * Numeric status code, 200: OK
+	 */
+	public final static int HTTP_OK = 200;
+
+	/**
+	 * Numeric status code, 206: Partial
+	 */
+	public final static int HTTP_PARTIAL = 206;
+
+	/**
+	 * Numeric status code, 402: Payment required
+	 */
+	public final static int HTTP_PAYMENT_REQUIRED = 402;
+
+	/**
+	 * Numeric status code, 412: Precondition failed
+	 */
+	public final static int HTTP_PRECON_FAILED = 412;
+
+	/**
+	 * Numeric status code, 407: Proxy authentication required
+	 */
+	public final static int HTTP_PROXY_AUTH = 407;
+
+	/**
+	 * Numeric status code, 414: Request too long
+	 */
+	public final static int HTTP_REQ_TOO_LONG = 414;
+
+	/**
+	 * Numeric status code, 205: Reset
+	 */
+	public final static int HTTP_RESET = 205;
+
+	/**
+	 * Numeric status code, 303: See other
+	 */
+	public final static int HTTP_SEE_OTHER = 303;
+
+	/**
+	 * @deprecated Use HTTP_INTERNAL_ERROR
+	 */
+	public final static int HTTP_SERVER_ERROR = 500;
+
+	/**
+	 * Numeric status code, 305: Use proxy
+	 */
+	public final static int HTTP_USE_PROXY = 305;
+
+	/**
+	 * Numeric status code, 401: Unauthorized
+	 */
+	public final static int HTTP_UNAUTHORIZED = 401;
+
+	/**
+	 * Numeric status code, 415: Unsupported type
+	 */
+	public final static int HTTP_UNSUPPORTED_TYPE = 415;
+
+	/**
+	 * Numeric status code, 503: Unavailable
+	 */
+	public final static int HTTP_UNAVAILABLE = 503;
+
+	/**
+	 * Numeric status code, 505: Version not supported
+	 */
+	public final static int HTTP_VERSION = 505;
+
+	/**
+	 * Constructs a <code>HttpURLConnection</code> pointing to the resource
+	 * specified by the <code>URL</code>.
+	 * 
+	 * @param url
+	 *            the URL of this connection
+	 * 
+	 * @see URL
+	 * @see URLConnection
+	 */
+	protected HttpURLConnection(URL url) {
+		super(url);
+	}
+
+	/**
+	 * Closes the connection with the HTTP server
+	 * 
+	 * @see URLConnection#connect()
+	 * @see URLConnection#connected
+	 */
+	public abstract void disconnect();
+
+	/**
+	 * Answers a input stream from the server in the case of error such as the
+	 * requested file (txt, htm, html) is not found on the remote server.
+	 * <p>
+	 * If the content type is not what stated above,
+	 * <code>FileNotFoundException</code> is thrown.
+	 * 
+	 * @return the error input stream returned by the server.
+	 */
+	public java.io.InputStream getErrorStream() {
+		return null;
+	}
+
+	/**
+	 * Answers the value of <code>followRedirects</code> which indicates if
+	 * this connection will follows a different URL redirected by the server. It
+	 * is enabled by default.
+	 * 
+	 * @return The value of the flag
+	 * 
+	 * @see #setFollowRedirects
+	 */
+	public static boolean getFollowRedirects() {
+		return followRedirects;
+	}
+
+	/**
+	 * Answers the permission object (in this case, SocketPermission) with the
+	 * host and the port number as the target name and "resolve, connect" as the
+	 * action list.
+	 * 
+	 * @return the permission object required for this connection
+	 * 
+	 * @throws java.io.IOException
+	 *             if an IO exception occurs during the creation of the
+	 *             permission object.
+	 */
+	public java.security.Permission getPermission() throws java.io.IOException {
+		int port = url.getPort();
+		if (port < 0)
+			port = 80;
+		return new java.net.SocketPermission(url.getHost() + ":" + port,
+				"connect, resolve");
+	}
+
+	/**
+	 * Answers the request method which will be used to make the request to the
+	 * remote HTTP server. All possible methods of this HTTP impl is listed in
+	 * the class definition.
+	 * 
+	 * @return the request method string
+	 * 
+	 * @see #method
+	 * @see #setRequestMethod
+	 */
+	public String getRequestMethod() {
+		return method;
+	}
+
+	/**
+	 * Answers the reponse code returned by the remote HTTP server
+	 * 
+	 * @return the response code, -1 if no valid response code
+	 * 
+	 * @throws java.io.IOException
+	 *             if there is an IO error during the retrieval.
+	 * 
+	 * @see #getResponseMessage
+	 */
+	public int getResponseCode() throws java.io.IOException {
+		// Response Code Sample : " HTTP/1.0 200 OK "
+
+		// Call getInputStream() first since getHeaderField() doesn't return
+		// exceptions
+		getInputStream();
+		String response = getHeaderField(0);
+		if (response == null)
+			return -1;
+		response.trim();
+		int mark = response.indexOf(" ") + 1;
+		if (mark == 0)
+			return -1;
+		int last = mark + 3;
+		if (last > response.length())
+			last = response.length();
+		responseCode = Integer.parseInt(response.substring(mark, last));
+		if (last + 1 <= response.length())
+			responseMessage = response.substring(last + 1);
+		return responseCode;
+	}
+
+	/**
+	 * Answers the response message returned the remote HTTP server
+	 * 
+	 * @return the response message. <code>null</code> if such response exists
+	 * 
+	 * @throws java.io.IOException
+	 *             if there is an IO error during the retrieval.
+	 * 
+	 * @see #getResponseCode()
+	 * @see java.io.IOException
+	 */
+	public String getResponseMessage() throws java.io.IOException {
+		if (responseMessage != null)
+			return responseMessage;
+		getResponseCode();
+		return responseMessage;
+	}
+
+	/**
+	 * Sets the flag of whether this connection will follow redirects returned
+	 * by the remote server. This method can only be called with the permission
+	 * from the security manager
+	 * 
+	 * @param auto
+	 *            The value to set
+	 * 
+	 * @see java.lang.SecurityManager#checkSetFactory()
+	 */
+
+	public static void setFollowRedirects(boolean auto) {
+		SecurityManager security = System.getSecurityManager();
+		if (security != null)
+			security.checkSetFactory();
+		followRedirects = auto;
+	}
+
+	/**
+	 * Sets the request command which will be sent to the remote HTTP server.
+	 * This method can only be called before the connection is made.
+	 * 
+	 * @param method
+	 *            The <code>non-null</code> string representing the method
+	 * 
+	 * @throws java.net.ProtocolException
+	 *             Thrown when this is called after connected, or the method is
+	 *             not supported by this HTTP impl.
+	 * 
+	 * @see #getRequestMethod()
+	 * @see #method
+	 */
+	public void setRequestMethod(String method) throws ProtocolException {
+		if (connected)
+			throw new ProtocolException(com.ibm.oti.util.Msg.getString("K0037"));
+		for (int i = 0; i < methodTokens.length; i++) {
+			if (methodTokens[i].equals(method)) {
+				// if there is a supported method that matches the desired
+				// method, then set the current method and return
+				this.method = methodTokens[i];
+				return;
+			}
+		}
+		// if none matches, then throw ProtocolException
+		throw new ProtocolException();
+	}
+
+	/**
+	 * Answers if this connection uses proxy.
+	 * 
+	 * @return true if this connection supports proxy, false otherwise.
+	 */
+	public abstract boolean usingProxy();
+
+	/**
+	 * Answers if this connection follows redirects.
+	 * 
+	 * @return true if this connection follows redirects, false otherwise.
+	 */
+	public boolean getInstanceFollowRedirects() {
+		return instanceFollowRedirects;
+	}
+
+	/**
+	 * Sets if this connection follows redirects.
+	 * 
+	 * @param followRedirects
+	 *            true if this connection should follows redirects, false
+	 *            otherwise.
+	 */
+	public void setInstanceFollowRedirects(boolean followRedirects) {
+		instanceFollowRedirects = followRedirects;
+	}
+
+	/**
+	 * Answers the date value in the form of milliseconds since epoch
+	 * corresponding to the field <code>field</code>. Answers
+	 * <code>defaultValue</code> if no such field can be found in the response
+	 * header.
+	 * 
+	 * @param field
+	 *            the field in question
+	 * @param defaultValue
+	 *            the default value if no field is found
+	 * @return milliseconds since epoch
+	 */
+	public long getHeaderFieldDate(String field, long defaultValue) {
+		return super.getHeaderFieldDate(field, defaultValue);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet4Address.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet4Address.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet4Address.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet4Address.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,224 @@
+/* Copyright 2003, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+import java.io.ObjectStreamException;
+
+
+public final class Inet4Address extends InetAddress {
+
+	static final long serialVersionUID = 3286316764910316507L;
+
+	Inet4Address(byte[] address) {
+		ipaddress = address;
+	}
+
+	Inet4Address(byte[] address, String name) {
+		ipaddress = address;
+		hostName = name;
+	}
+
+	/**
+	 * Answers true if the address is a mutlicast address.
+	 * 
+	 * @return boolean
+	 * 
+	 * Valid IPv4 mutlicast addresses are prefixed with 1110 = 0xE
+	 */
+	public boolean isMulticastAddress() {
+		return (ipaddress[0] & 0xF0) == 0xE0;
+	}
+
+	/**
+	 * Answers if the address is the ANY Address
+	 * 
+	 * @return boolean
+	 */
+	public boolean isAnyLocalAddress() {
+		for (int i = 0; i < ipaddress.length; i++) {
+			if (ipaddress[i] != 0)
+				return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Answers true if the address is a loopback address.
+	 * 
+	 * @return boolean
+	 * 
+	 * Loopback ipv4 addresses are prefixed with: 011111111 = 127
+	 */
+	public boolean isLoopbackAddress() {
+		return (ipaddress[0] & 255) == 127;
+	}
+
+	/**
+	 * Answers false for all IPv4 addresses.
+	 * 
+	 * @return boolean
+	 * 
+	 * There are no valid IPv4 link local addresses.
+	 */
+	public boolean isLinkLocalAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers false for all IPv4 addresses.
+	 * 
+	 * @return boolean
+	 * 
+	 * There are no valid IPv4 site local addresses.
+	 */
+	public boolean isSiteLocalAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers true if an address is a global multicast address.
+	 * 
+	 * @return boolean true, if the address is in the global multicast group,
+	 *         false otherwise
+	 * 
+	 * Valid MCGlobal IPv4 addresses are 224.0.1.0 - 238.255.255.255
+	 */
+	public boolean isMCGlobal() {
+
+		// Check if we have a prefix of 1110
+		if (!isMulticastAddress())
+			return false;
+
+		int address = InetAddress.bytesToInt(ipaddress, 0);
+		// Now check the boundaries of the global space
+		// if we have an address that is prefixed by something less
+		// than 111000000000000000000001 (fortunately we don't have
+		// to worry about sign after shifting 8 bits right) it is
+		// not mutlicast. ( < 224.0.1.0)
+		if (address >>> 8 < 0xE00001)
+			return false;
+
+		// Now check the high boundary which is prefixed by
+		// 11101110 = 0xEE. If the value is higher than this than
+		// it is not MCGlobal ( > 238.255.255.255 )
+		if (address >>> 24 > 0xEE)
+			return false;
+
+		return true;
+
+	}
+
+	/**
+	 * Answers false for all IPv4 addresses.
+	 * 
+	 * @return boolean
+	 * 
+	 * There are no valid IPv4 Node-local addresses
+	 */
+	public boolean isMCNodeLocal() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a link-local address.
+	 * 
+	 * @return boolean
+	 * 
+	 * The valid range for IPv4 link-local addresses is: 224.0.0.0 to
+	 * 239.0.0.255 Hence a mask of 111000000000000000000000 = 0xE00000
+	 */
+	public boolean isMCLinkLocal() {
+		return InetAddress.bytesToInt(ipaddress, 0) >>> 8 == 0xE00000;
+	}
+
+	/**
+	 * Answers true if the address is a site-local address.
+	 * 
+	 * @return boolean
+	 * 
+	 * The valid range for IPv4 site-local addresses is: 239.255.0.0 to
+	 * 239.255.255.255 Hence a mask of 11101111 11111111 = 0xEFFF.
+	 */
+	public boolean isMCSiteLocal() {
+		return (InetAddress.bytesToInt(ipaddress, 0) >>> 16) == 0xEFFF;
+	}
+
+	/**
+	 * Answers true if the address is a organization-local address.
+	 * 
+	 * @return boolean
+	 * 
+	 * The valid range for IPv4 org-local addresses is: 239.192.0.0 to
+	 * 239.195.255.255 Hence masks of 11101111 11000000 to 11101111 11000011 are
+	 * valid. 0xEFC0 to 0xEFC3
+	 */
+	public boolean isMCOrgLocal() {
+		int prefix = InetAddress.bytesToInt(ipaddress, 0) >>> 16;
+		return prefix >= 0xEFC0 && prefix <= 0xEFC3;
+	}
+
+	/**
+	 * Returns the byte array representation of the IP address.
+	 * 
+	 * @return byte[]
+	 * 
+	 */
+	public byte[] getAddress() {
+		return ipaddress;
+	}
+
+	/**
+	 * Returns a String representation of the IP address.
+	 * 
+	 * @return String
+	 * 
+	 */
+	public String getHostAddress() {
+		String hostAddress = "";
+		for (int i = 0; i < 4; i++) {
+			hostAddress += ipaddress[i] & 255;
+			if (i != 3)
+				hostAddress += ".";
+		}
+		return hostAddress;
+	}
+
+	/**
+	 * Overrides the basic hashcode function.
+	 * 
+	 * @return String
+	 * 
+	 */
+	public int hashCode() {
+		return InetAddress.bytesToInt(ipaddress, 0);
+	}
+
+	/**
+	 * Returns true if obj is of the same type as the IPv4 address and they have
+	 * the same IP address, false otherwise.
+	 * 
+	 * @return String
+	 * 
+	 */
+	public boolean equals(Object obj) {
+		return super.equals(obj);
+	}
+
+	private Object writeReplace() throws ObjectStreamException {
+		return new InetAddress(ipaddress);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet6Address.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet6Address.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet6Address.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Inet6Address.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,354 @@
+/* Copyright 2003, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+
+public final class Inet6Address extends InetAddress {
+
+	static final long serialVersionUID = 6880410070516793377L;
+
+	final static byte[] any_bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+			0, 0 };
+
+	static InetAddress ANY = new Inet6Address(any_bytes);
+
+	int scope_id = 0;
+
+	boolean scope_id_set = false;
+
+	boolean scope_ifname_set = false;
+
+	String ifname = null;
+
+	Inet6Address(byte address[]) {
+		ipaddress = address;
+		scope_id = 0;
+	}
+
+	Inet6Address(byte address[], String name) {
+		hostName = name;
+		ipaddress = address;
+		scope_id = 0;
+	}
+
+	/**
+	 * Constructs an InetAddress, representing the <code>address</code> and
+	 * <code>hostName</code> and <code>scope_id</code>
+	 * 
+	 * @param address
+	 *            network address
+	 * @param name
+	 *            Name assocaited with the address
+	 * @param scope_id
+	 *            The scope id for link or site local addresses
+	 */
+	Inet6Address(byte address[], String name, int scope_id) {
+		hostName = name;
+		ipaddress = address;
+		this.scope_id = scope_id;
+		if (scope_id != 0) {
+			scope_id_set = true;
+		}
+	}
+
+	/**
+	 * Constructs an InetAddress, representing the <code>address</code> and
+	 * <code>hostName</code> and <code>scope_id</code>
+	 * 
+	 * @param address
+	 *            network address
+	 * @param scope_id
+	 *            The scope id for link or site local addresses
+	 */
+	Inet6Address(byte address[], int scope_id) {
+		ipaddress = address;
+		this.scope_id = scope_id;
+		if (scope_id != 0) {
+			scope_id_set = true;
+		}
+	}
+
+	/**
+	 * Answer true if the InetAddress is an IP multicast address.
+	 * 
+	 * Valid IPv6 multicast address have the binary prefixed with 11111111 or FF
+	 * (hex).
+	 * 
+	 * @return boolean true, if the address is in the multicast group, false
+	 *         otherwise
+	 */
+	public boolean isMulticastAddress() {
+
+		// mutlicast addresses are prefixed with 11111111 (255)
+		return ipaddress[0] == -1;
+	}
+
+	/**
+	 * Answer true if the InetAddress is the unspecified adddress "::".
+	 * 
+	 * @return boolean true, if the address is in the multicast group, false
+	 *         otherwise
+	 */
+	public boolean isAnyLocalAddress() {
+		for (int i = 0; i < ipaddress.length; i++) {
+			if (ipaddress[i] != 0)
+				return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Answer true if the InetAddress is the loopback address
+	 * 
+	 * The valid IPv6 loopback address is ::1
+	 * 
+	 * @return boolean true if the address is the loopback, false otherwise
+	 */
+	public boolean isLoopbackAddress() {
+
+		// The last word must be 1
+		if (ipaddress[15] != 1) {
+			return false;
+		}
+
+		// All other words must be 0
+		for (int i = 0; i < 15; i++) {
+			if (ipaddress[i] != 0) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+
+	/**
+	 * Answer true if the InetAddress is a link-local address.
+	 * 
+	 * A valid IPv6 link-local address is prefixed with 1111111010
+	 * 
+	 * @return boolean true, if it is a link-local address, false otherwise
+	 */
+	public boolean isLinkLocalAddress() {
+
+		// the first 10 bits need to be 1111111010 (1018)
+		return (ipaddress[0] == -2) && ((ipaddress[1] & 255) >>> 6) == 2;
+	}
+
+	/**
+	 * Answer true if the InetAddress is a site-local address.
+	 * 
+	 * A valid IPv6 site-local address is prefixed with 1111111011
+	 * 
+	 * @return boolean true, if it is a site-local address, false otherwise
+	 */
+	public boolean isSiteLocalAddress() {
+
+		// the first 10 bits need to be 1111111011 (1019)
+		return (ipaddress[0] == -2) && ((ipaddress[1] & 255) >>> 6) == 3;
+	}
+
+	/**
+	 * Answer true if the InetAddress is a global multicast address.
+	 * 
+	 * A valid IPv6 global mutlicast address is 11111111xxxx1110
+	 * 
+	 * @return boolean true, if it is a global mutlicast address, false
+	 *         otherwise
+	 */
+	public boolean isMCGlobal() {
+
+		// the first byte should be 0xFF and the lower 4 bits
+		// of the second byte should be 0xE
+		return (ipaddress[0] == -1) && (ipaddress[1] & 14) == 14;
+
+	}
+
+	/**
+	 * Answer true if the InetAddress is a node-local multicast address.
+	 * 
+	 * A valid IPv6 node-local mutlicast address is prefixed with
+	 * 11111111xxxx0001
+	 * 
+	 * @return boolean true, if it is a node-local mutlicast address, false
+	 *         otherwise
+	 */
+	public boolean isMCNodeLocal() {
+
+		// the first byte should be 0xFF and the lower 4 bits
+		// of the second byte should be 0x1
+		return (ipaddress[0] == -1) && (ipaddress[1] & 15) == 1;
+
+	}
+
+	/**
+	 * Answer true if the InetAddress is a link-local multicast address.
+	 * 
+	 * A valid IPv6 link-local mutlicast address is prefixed with
+	 * 11111111xxxx0010
+	 * 
+	 * @return boolean true, if it is a link-local mutlicast address, false
+	 *         otherwise
+	 */
+	public boolean isMCLinkLocal() {
+
+		// the first byte should be 0xFF and the lower 4 bits
+		// of the second byte should be 0x2
+		return (ipaddress[0] == -1) && (ipaddress[1] & 15) == 2;
+
+	}
+
+	/**
+	 * Answer true if the InetAddress is a site-local multicast address.
+	 * 
+	 * A valid IPv6 site-local mutlicast address is prefixed with
+	 * 11111111xxxx0101
+	 * 
+	 * @return boolean true, if it is a site-local mutlicast address, false
+	 *         otherwise
+	 */
+	public boolean isMCSiteLocal() {
+
+		// the first byte should be 0xFF and the lower 4 bits
+		// of the second byte should be 0x5
+		return (ipaddress[0] == -1) && (ipaddress[1] & 15) == 5;
+
+	}
+
+	/**
+	 * Answer true if the InetAddress is a org-local multicast address.
+	 * 
+	 * A valid IPv6 org-local mutlicast address is prefixed with
+	 * 11111111xxxx1000
+	 * 
+	 * @return boolean true, if it is a org-local mutlicast address, false
+	 *         otherwise
+	 */
+	public boolean isMCOrgLocal() {
+
+		// the first byte should be 0xFF and the lower 4 bits
+		// of the second byte should be 0x8
+		return (ipaddress[0] == -1) && (ipaddress[1] & 15) == 8;
+	}
+
+	/**
+	 * Returns the byte array representation of the IP address.
+	 * 
+	 * @return byte[]
+	 * 
+	 */
+	public byte[] getAddress() {
+		return ipaddress;
+	}
+
+	public String getHostAddress() {
+		StringBuffer hostAddress = new StringBuffer();
+		String tempString;
+		int length = ipaddress.length / 2;
+		for (int i = 0; i < length; i++) {
+
+			tempString = Integer.toHexString(ipaddress[i * 2] & 255);
+			if (tempString.length() == 1) {
+				tempString = "0" + tempString;
+			}
+			hostAddress.append(tempString);
+			tempString = Integer.toHexString(ipaddress[i * 2 + 1] & 255);
+			if (tempString.length() == 1) {
+				tempString = "0" + tempString;
+			}
+			hostAddress.append(tempString);
+			if (i + 1 < length) {
+				hostAddress.append(":");
+			}
+		}
+
+		return hostAddress.toString().toUpperCase();
+	}
+
+	public int hashCode() {
+		/* Returns the low order int as the hash code */
+		return bytesToInt(ipaddress, 12);
+	}
+
+	/**
+	 * Returns true if obj is of the same type as the IPv6 address and they have
+	 * the same IP address, false otherwise. the scope id does not seem to be
+	 * part of the comparison
+	 * 
+	 * @return String
+	 * 
+	 */
+	public boolean equals(Object obj) {
+		return super.equals(obj);
+	}
+
+	/**
+	 * An IPv4 compatible address is prefixed with 96 bits of 0's. The last
+	 * 32-bits are varied corresponding with the 32-bit IPv4 address space.
+	 */
+	public boolean isIPv4CompatibleAddress() {
+		for (int i = 0; i < 12; i++) {
+			if (ipaddress[i] != 0) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	private static final ObjectStreamField[] serialPersistentFields = {
+			new ObjectStreamField("ipaddress", new byte[0].getClass()),
+			new ObjectStreamField("scope_id", Integer.TYPE),
+			new ObjectStreamField("scope_id_set", Boolean.TYPE) };
+
+	private void writeObject(ObjectOutputStream stream) throws IOException {
+		ObjectOutputStream.PutField fields = stream.putFields();
+		if (ipaddress == null) {
+			fields.put("ipaddress", null);
+		} else {
+			fields.put("ipaddress", ipaddress);
+		}
+
+		fields.put("scope_id", scope_id);
+		fields.put("scope_id_set", scope_id_set);
+
+		stream.writeFields();
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		ObjectInputStream.GetField fields = stream.readFields();
+		ipaddress = (byte[]) fields.get("ipaddress", null);
+		scope_id = fields.get("scope_id", 0);
+		scope_id_set = fields.get("scope_id_set", false);
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * address.
+	 * 
+	 * @return String the description, as host/address
+	 */
+	public String toString() {
+		if (scope_id != 0) {
+			return super.toString() + "%" + scope_id;
+		}
+		return super.toString();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetAddress.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetAddress.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetAddress.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,1089 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import com.ibm.oti.util.Inet6Util;
+import com.ibm.oti.util.Msg;
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * The Internet Protocol (IP) address class. This class encapsulates an IP
+ * address and provides name and reverse name resolution functions. The address
+ * is stored in network order, but as a signed (rather than unsigned) integer.
+ */
+public class InetAddress extends Object implements Serializable {
+
+	final static byte[] any_bytes = { 0, 0, 0, 0 };
+
+	final static byte[] localhost_bytes = { 127, 0, 0, 1 };
+
+	static InetAddress ANY = new Inet4Address(any_bytes);
+
+	final static InetAddress LOOPBACK = new Inet4Address(localhost_bytes,
+			"localhost");
+
+	static final long serialVersionUID = 3286316764910316507L;
+
+	String hostName;
+
+	int family = 2;
+
+	byte[] ipaddress;
+
+	// Fill in the JNI id caches
+	private static native void oneTimeInitialization(boolean supportsIPv6);
+
+	static {
+		oneTimeInitialization(true);
+	}
+
+	/**
+	 * Constructs an InetAddress.
+	 */
+	InetAddress() {
+		super();
+	}
+
+	/**
+	 * Constructs an InetAddress, representing the <code>address</code> and
+	 * <code>hostName</code>.
+	 * 
+	 * @param address
+	 *            network address
+	 */
+	InetAddress(byte[] address) {
+		super();
+		this.ipaddress = address;
+	}
+
+	/**
+	 * Constructs an InetAddress, representing the <code>address</code> and
+	 * <code>hostName</code>.
+	 * 
+	 * @param address
+	 *            network address
+	 */
+	private InetAddress(byte[] address, String hostName) {
+		super();
+		this.ipaddress = address;
+		this.hostName = hostName;
+	}
+
+	/**
+	 * Returns the IP address of the argument <code>addr</code> as an array.
+	 * The elements are in network order (the highest order address byte is in
+	 * the zeroeth element).
+	 * 
+	 * @return byte[] the network address as a byte array
+	 */
+	static byte[] addressOf(int addr) {
+		int temp = addr;
+		byte array[] = new byte[4];
+		array[3] = (byte) (temp & 0xFF);
+		array[2] = (byte) ((temp >>>= 8) & 0xFF);
+		array[1] = (byte) ((temp >>>= 8) & 0xFF);
+		array[0] = (byte) ((temp >>>= 8) & 0xFF);
+		return array;
+	}
+
+	CacheElement cacheElement() {
+		return new CacheElement();
+	}
+
+	/**
+	 * Compares this <code>InetAddress</code> against the specified object.
+	 * 
+	 * @param obj
+	 *            the object to be tested for equality
+	 * @return boolean true, if the objects are equal
+	 */
+	public boolean equals(Object obj) {
+		if (obj == null) {
+			return false;
+		}
+		if (obj.getClass() != this.getClass()) {
+			return false;
+		}
+
+		// now check if their byte arrays match...
+		byte[] objIPaddress = ((InetAddress) obj).ipaddress;
+		for (int i = 0; i < objIPaddress.length; i++) {
+			if (objIPaddress[i] != this.ipaddress[i])
+				return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Returns the IP address of this <code>InetAddress</code> as an array.
+	 * The elements are in network order (the highest order address byte is in
+	 * the zeroeth element).
+	 * 
+	 * @return byte[] the address as a byte array
+	 */
+	public byte[] getAddress() {
+		return (byte[]) ipaddress.clone();
+	}
+
+	/**
+	 * Answer the IP addresses of a named host. The host name may either be a
+	 * machine name or a dotted string IP address. If the host name is empty or
+	 * null, an UnknownHostException is thrown. If the host name is a dotted IP
+	 * string, an array with the corresponding single InetAddress is returned.
+	 * 
+	 * @param host
+	 *            the hostName to be resolved to an address
+	 * 
+	 * @return InetAddress[] an array of addresses for the host
+	 * @throws UnknownHostException
+	 *             if the address lookup fails
+	 */
+	public static InetAddress[] getAllByName(String host)
+			throws UnknownHostException {
+		if (host == null || 0 == host.length())
+			throw new UnknownHostException(Msg.getString("K0038"));
+
+		if (isHostName(host)) {
+			SecurityManager security = System.getSecurityManager();
+			if (security != null)
+				security.checkConnect(host, -1);
+			if (Socket.preferIPv4Stack()) {
+				return getAliasesByNameImpl(host);
+			}
+			
+			// ok we may have to re-order to make sure the
+			// preferIPv6Addresses is respected
+			InetAddress[] returnedAddresses = getAliasesByNameImpl(host);
+			InetAddress[] orderedAddresses = null;
+			if (returnedAddresses != null) {
+				orderedAddresses = new InetAddress[returnedAddresses.length];
+				int curPosition = 0;
+				if (InetAddress.preferIPv6Addresses()) {
+					for (int i = 0; i < returnedAddresses.length; i++) {
+						if (returnedAddresses[i] instanceof Inet6Address) {
+							orderedAddresses[curPosition] = returnedAddresses[i];
+							curPosition++;
+						}
+					}
+					for (int i = 0; i < returnedAddresses.length; i++) {
+						if (returnedAddresses[i] instanceof Inet4Address) {
+							orderedAddresses[curPosition] = returnedAddresses[i];
+							curPosition++;
+						}
+					}
+				} else {
+					for (int i = 0; i < returnedAddresses.length; i++) {
+						if (returnedAddresses[i] instanceof Inet4Address) {
+							orderedAddresses[curPosition] = returnedAddresses[i];
+							curPosition++;
+						}
+					}
+					for (int i = 0; i < returnedAddresses.length; i++) {
+						if (returnedAddresses[i] instanceof Inet6Address) {
+							orderedAddresses[curPosition] = returnedAddresses[i];
+							curPosition++;
+						}
+					}
+				}
+			}
+			return orderedAddresses;
+		}
+		
+		byte[] hBytes = Inet6Util.createByteArrayFromIPAddressString(host);
+		return (new InetAddress[] { new InetAddress(hBytes) });
+	}
+
+	/**
+	 * Answers the address of a host, given a host string name. The host string
+	 * may be either a machine name or a dotted string IP address. If the
+	 * latter, the hostName field will be determined upon demand.
+	 * 
+	 * @param host
+	 *            the hostName to be resolved to an address
+	 * @return InetAddress the InetAddress representing the host
+	 * 
+	 * @throws UnknownHostException
+	 *             if the address lookup fails
+	 */
+	public static InetAddress getByName(String host)
+			throws UnknownHostException {
+		if (host == null || 0 == host.length())
+			return InetAddress.LOOPBACK;
+		if (host.equals("0")) {
+			return InetAddress.ANY;
+		}
+
+		if (isHostName(host)) {
+			SecurityManager security = System.getSecurityManager();
+			if (security != null)
+				security.checkConnect(host, -1);
+			return lookupHostByName(host);
+		}
+		
+		return createHostNameFromIPAddress(host);
+	}
+
+	/**
+	 * Answer the dotted string IP address representing this address.
+	 * 
+	 * @return String the corresponding dotted string IP address
+	 */
+	public String getHostAddress() {
+
+		return inetNtoaImpl(bytesToInt(ipaddress, 0));
+	}
+
+	/**
+	 * Answer the host name.
+	 * 
+	 * @return String the corresponding string name
+	 */
+	public String getHostName() {
+		int address = 0;
+		try {
+			if (hostName == null) {
+				address = bytesToInt(ipaddress, 0);
+				hostName = (0 == address) ? inetNtoaImpl(address)
+						: getHostByAddrImpl(ipaddress).hostName;
+			}
+		} catch (UnknownHostException e) {
+			return hostName = inetNtoaImpl(address);
+		}
+		SecurityManager security = System.getSecurityManager();
+		try {
+			// Only check host names, not addresses
+			if (security != null && isHostName(hostName))
+				security.checkConnect(hostName, -1);
+		} catch (SecurityException e) {
+			address = bytesToInt(ipaddress, 0);
+			return inetNtoaImpl(address);
+		}
+		return hostName;
+	}
+
+	/**
+	 * Answers canonical name for the host associated with the inet address
+	 * 
+	 * @return String string containing the host name
+	 */
+	public String getCanonicalHostName() {
+		int address = 0;
+		try {
+
+			address = bytesToInt(ipaddress, 0);
+			hostName = (0 == address) ? inetNtoaImpl(address)
+					: getHostByAddrImpl(ipaddress).hostName;
+		} catch (UnknownHostException e) {
+			return hostName = inetNtoaImpl(address);
+		}
+		SecurityManager security = System.getSecurityManager();
+		try {
+			// Only check host names, not addresses
+			if (security != null && isHostName(hostName))
+				security.checkConnect(hostName, -1);
+		} catch (SecurityException e) {
+			address = bytesToInt(ipaddress, 0);
+			return inetNtoaImpl(address);
+		}
+		return hostName;
+	}
+
+	/**
+	 * Answer the local host, if allowed by the security policy. Otherwise,
+	 * answer the loopback address which allows this machine to be contacted.
+	 * 
+	 * @return InetAddress the InetAddress representing the local host
+	 * @throws UnknownHostException
+	 *             if the address lookup fails
+	 */
+	public static InetAddress getLocalHost() throws UnknownHostException {
+		String host = getHostNameImpl();
+		SecurityManager security = System.getSecurityManager();
+		try {
+			if (security != null)
+				security.checkConnect(host, -1);
+		} catch (SecurityException e) {
+			return InetAddress.LOOPBACK;
+		}
+		return lookupHostByName(host);
+	}
+
+	/**
+	 * Answer a hashcode for this IP address.
+	 * 
+	 * @return int the hashcode
+	 */
+	public int hashCode() {
+		return bytesToInt(ipaddress, 0);
+	}
+
+	/**
+	 * Answer true if the InetAddress is an IP multicast address.
+	 * 
+	 * @return boolean true, if the address is in the multicast group
+	 */
+	public boolean isMulticastAddress() {
+		return ((ipaddress[0] & 255) >>> 4) == 0xE;
+	}
+
+	static synchronized InetAddress lookupHostByName(String host)
+			throws UnknownHostException {
+		int ttl = -1;
+
+		String ttlValue = (String) AccessController
+				.doPrivileged(new PriviAction("networkaddress.cache.ttl"));
+		try {
+			if (ttlValue != null)
+				ttl = Integer.decode(ttlValue).intValue();
+		} catch (NumberFormatException e) {
+		}
+		CacheElement element = null;
+		if (ttl == 0)
+			Cache.clear();
+		else {
+			element = Cache.get(host);
+			if (element != null
+					&& ttl > 0
+					&& element.timeAdded + (ttl * 1000) < System
+							.currentTimeMillis())
+				element = null;
+		}
+		if (element != null)
+			return element.inetAddress();
+		
+		// now try the negative cache
+		String failedMessage = NegativeCache.getFailedMessage(host);
+		if (failedMessage != null) {
+			throw new UnknownHostException(host + " - " + failedMessage);
+		}
+
+		InetAddress anInetAddress;
+		try {
+			anInetAddress = getHostByNameImpl(host, preferIPv6Addresses());
+		} catch (UnknownHostException e) {
+			// put the entry in the negative cache
+			NegativeCache.put(host, e.getMessage());
+			throw new UnknownHostException(host + " - " + e.getMessage());
+		}
+
+		Cache.add(anInetAddress);
+		return anInetAddress;
+	}
+
+	/**
+	 * Query the IP stack for aliases for the host. The host is in string name
+	 * form.
+	 * 
+	 * @param name
+	 *            the host name to lookup
+	 * @throws UnknownHostException
+	 *             if an error occurs during lookup
+	 */
+	static native InetAddress[] getAliasesByNameImpl(String name)
+			throws UnknownHostException;
+
+	/**
+	 * Query the IP stack for the host address. The host is in address form.
+	 * 
+	 * @param addr
+	 *            the host address to lookup
+	 * @throws UnknownHostException
+	 *             if an error occurs during lookup
+	 */
+	static native InetAddress getHostByAddrImpl(byte[] addr)
+			throws UnknownHostException;
+
+	static int inetAddr(String host) throws UnknownHostException {
+		return (host.equals("255.255.255.255")) ? 0xFFFFFFFF
+				: inetAddrImpl(host);
+	}
+
+	/**
+	 * Convert a string containing an Ipv4 Internet Protocol dotted address into
+	 * a binary address. Note, the special case of '255.255.255.255' throws an
+	 * exception, so this value should not be used as an argument. See also
+	 * inetAddr(String).
+	 */
+	static native int inetAddrImpl(String host) throws UnknownHostException;
+
+	/**
+	 * Convert a binary address into a string containing an Ipv4 Internet
+	 * Protocol dotted address.
+	 */
+	static native String inetNtoaImpl(int hipAddr);
+
+	/**
+	 * Query the IP stack for the host address. The host is in string name form.
+	 * 
+	 * @param name
+	 *            the host name to lookup
+	 * @param preferIPv6Addresses
+	 *            address preference if underlying platform is V4/V6
+	 * @return InetAddress the host address
+	 * 
+	 * @throws UnknownHostException
+	 *             if an error occurs during lookup
+	 */
+	static native InetAddress getHostByNameImpl(String name,
+			boolean preferIPv6Address) throws UnknownHostException;
+
+	/**
+	 * Query the IP stack for the host machine name.
+	 * 
+	 * @return String the host machine name
+	 */
+	static native String getHostNameImpl();
+
+	static String getHostNameInternal(String host) throws UnknownHostException {
+		if (host == null || 0 == host.length())
+			return InetAddress.LOOPBACK.getHostAddress();
+		if (isHostName(host))
+			return lookupHostByName(host).getHostAddress();
+		return host;
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * address.
+	 * 
+	 * @return String the description, as host/address
+	 */
+	public String toString() {
+		return getHostName() + "/" + getHostAddress();
+	}
+
+	class CacheElement {
+		long timeAdded = System.currentTimeMillis();
+
+		CacheElement next;
+
+		public CacheElement() {
+			super();
+		}
+
+		String hostName() {
+			return hostName;
+		}
+
+		InetAddress inetAddress() {
+			return InetAddress.this;
+		}
+	}
+
+	static class Cache {
+		static int maxSize = 5;
+
+		private static int size = 0;
+
+		private static CacheElement head;
+
+		static void clear() {
+			size = 0;
+			head = null;
+		}
+
+		static void add(InetAddress value) {
+			CacheElement newElement = value.cacheElement();
+			if (size < maxSize)
+				size++;
+			else
+				deleteTail();
+			newElement.next = head; // If the head is null, this does no harm.
+			head = newElement;
+		}
+
+		static CacheElement get(String name) {
+			CacheElement previous = null;
+			CacheElement current = head;
+			boolean notFound = true;
+			while ((null != current)
+					&& (notFound = !(name.equals(current.hostName())))) {
+				previous = current;
+				current = current.next;
+			}
+			if (notFound)
+				return null;
+			moveToHead(current, previous);
+			return current;
+		}
+
+		private static void deleteTail() {
+			if (0 == size)
+				return;
+			if (1 == size)
+				head = null;
+
+			CacheElement previous = null;
+			CacheElement current = head;
+			while (null != current.next) {
+				previous = current;
+				current = current.next;
+			}
+			previous.next = null;
+		}
+
+		private static void moveToHead(CacheElement element,
+				CacheElement elementPredecessor) {
+			if (null == elementPredecessor) {
+				head = element;
+			} else {
+				elementPredecessor.next = element.next;
+				element.next = head;
+				head = element;
+			}
+		}
+	}
+
+	/**
+	 * Answer true if the string is a host name, false if it is an IP Address.
+	 */
+
+	private static boolean isHostName(String value) {
+		return !(Inet6Util.isValidIPV4Address(value) || Inet6Util
+				.isValidIP6Address(value));
+	}
+
+	/**
+	 * Answer true if the address is a loop back address. Valid IPv4 loopback
+	 * addresses are 127.d.d.d Valid IPv6 loopback address is ::1
+	 * 
+	 * @return boolean
+	 */
+	public boolean isLoopbackAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a link local address.
+	 * 
+	 * Valid IPv6 link local addresses are FE80::0 through to
+	 * FEBF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
+	 * 
+	 * There are no valid IPv4 link local addresses.
+	 * 
+	 * @return boolean
+	 */
+	public boolean isLinkLocalAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a site local address.
+	 * 
+	 * Valid IPv6 link local addresses are FEC0::0 through to
+	 * FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
+	 * 
+	 * There are no valid IPv4 site local addresses.
+	 * 
+	 * @return boolean
+	 */
+	public boolean isSiteLocalAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a global multicast address.
+	 * 
+	 * Valid IPv6 link global multicast addresses are FFxE:/112 where x is a set
+	 * of flags, and the additional 112 bits make up the global multicast
+	 * address space
+	 * 
+	 * Valid IPv4 global multi-cast addresses are between: 224.0.1.0 to
+	 * 238.255.255.255
+	 * 
+	 * @return boolean
+	 */
+	public boolean isMCGlobal() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a node local multicast address.
+	 * 
+	 * Valid IPv6 node local multicast addresses are FFx1:/112 where x is a set
+	 * of flags, and the additional 112 bits make up the node local multicast
+	 * address space
+	 * 
+	 * There are no valid IPv4 node local multicast addresses.
+	 * 
+	 * @return boolean
+	 */
+	public boolean isMCNodeLocal() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a link local multicast address.
+	 * 
+	 * Valid IPv6 link local multicast addresses are FFx2:/112 where x is a set
+	 * of flags, and the additional 112 bits make up the node local multicast
+	 * address space
+	 * 
+	 * Valid IPv4 link-local addresses are between: 224.0.0.0 to 224.0.0.255
+	 * 
+	 * @return boolean
+	 */
+	public boolean isMCLinkLocal() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a site local multicast address.
+	 * 
+	 * Valid IPv6 site local multicast addresses are FFx5:/112 where x is a set
+	 * of flags, and the additional 112 bits make up the node local multicast
+	 * address space
+	 * 
+	 * Valid IPv4 site-local addresses are between: 239.252.0.0 to
+	 * 239.255.255.255
+	 * 
+	 * @return boolean
+	 */
+	public boolean isMCSiteLocal() {
+		return false;
+	}
+
+	/**
+	 * Answers true if the address is a organization local multicast address.
+	 * 
+	 * Valid IPv6 organization local multicast addresses are FFx8:/112 where x
+	 * is a set of flags, and the additional 112 bits make up the node local
+	 * multicast address space
+	 * 
+	 * Valid IPv4 organization-local addresses are between: 239.192.0.0 to
+	 * 239.251.255.255
+	 * 
+	 * @return boolean
+	 */
+	public boolean isMCOrgLocal() {
+		return false;
+	}
+
+	/**
+	 * Method isAnyLocalAddress.
+	 * 
+	 * @return boolean
+	 */
+	public boolean isAnyLocalAddress() {
+		return false;
+	}
+
+	/**
+	 * Answers the InetAddress corresponding to the array of bytes. In the case
+	 * of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16
+	 * bytes. If not, an UnknownHostException is thrown.
+	 * 
+	 * The IP address is not validated by a name service.
+	 * 
+	 * The high order byte is <code>ipAddress[0]<\code>.
+	 *
+	 * @param 		ipAddress	either a 4 (IPv4) or 16 (IPv6) byte array
+	 * @return 		the InetAddress
+	 *
+	 * @throws		UnknownHostException
+	 */
+	public static InetAddress getByAddress(byte[] ipAddress)
+			throws UnknownHostException {
+		// simply call the method by the same name specifying the default scope
+		// id of 0
+		return getByAddress(ipAddress, 0);
+	}
+
+	/**
+	 * Answers the InetAddress corresponding to the array of bytes. In the case
+	 * of an IPv4 address there must be exactly 4 bytes and for IPv6 exactly 16
+	 * bytes. If not, an UnknownHostException is thrown.
+	 * 
+	 * The IP address is not validated by a name service.
+	 * 
+	 * The high order byte is <code>ipAddress[0]<\code>.
+	 *
+	 * @param 		ipAddress	either a 4 (IPv4) or 16 (IPv6) byte array
+	 * @param 		scope_id	the scope id for an IPV6 scoped address. If not a scoped
+	 *                          address just pass in 0
+	 * @return 		the InetAddress
+	 *
+	 * @throws		UnknownHostException
+	 */
+	static InetAddress getByAddress(byte[] ipAddress, int scope_id)
+			throws UnknownHostException {
+		byte[] copy_address;
+		if (ipAddress.length == 4) {
+			copy_address = new byte[4];
+			for (int i = 0; i < 4; i++) {
+				copy_address[i] = ipAddress[i];
+			}
+			return new Inet4Address(ipAddress);
+		}
+
+		if (ipAddress.length == 16) {
+			// First check to see if the address is an IPv6-mapped
+			// IPv4 address. If it is, then we can make it a IPv4
+			// address, otherwise, we'll create an IPv6 address.
+			if (isIPv4MappedAddress(ipAddress)) {
+				copy_address = new byte[4];
+				for (int i = 0; i < 4; i++) {
+					copy_address[i] = ipAddress[12 + i];
+				}
+				return new Inet4Address(copy_address);
+			}
+			copy_address = (byte[]) ipAddress.clone();
+			return new Inet6Address(copy_address, scope_id);
+		}
+		throw new UnknownHostException(Msg.getString("K0339"));
+	}
+
+	private static boolean isIPv4MappedAddress(byte ipAddress[]) {
+
+		// Check if the address matches ::FFFF:d.d.d.d
+		// The first 10 bytes are 0. The next to are -1 (FF).
+		// The last 4 bytes are varied.
+		for (int i = 0; i < 10; i++) {
+			if (ipAddress[i] != 0) {
+				return false;
+			}
+		}
+
+		if (ipAddress[10] != -1 || ipAddress[11] != -1) {
+			return false;
+		}
+
+		return true;
+
+	}
+
+	/**
+	 * Answers the InetAddress corresponding to the array of bytes, and the
+	 * given hostname. In the case of an IPv4 address there must be exactly 4
+	 * bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is
+	 * thrown.
+	 * 
+	 * The host name and IP address are not validated.
+	 * 
+	 * The hostname either be a machine alias or a valid IPv6 or IPv4 address
+	 * format.
+	 * 
+	 * The high order byte is <code>ipAddress[0]<\code>.
+	 *
+	 * @param 		hostName	string representation of hostname or ip address
+	 * @param 		ipAddress	either a 4 (IPv4) or 16 (IPv6) byte array
+	 * @return 		the InetAddress
+	 *
+	 * @throws 		UnknownHostException
+	 */
+	public static InetAddress getByAddress(String hostName, byte[] ipAddress)
+			throws UnknownHostException {
+		// just call the method by the same name passing in a default scope id
+		// of 0
+		return getByAddress(hostName, ipAddress, 0);
+	}
+
+	/**
+	 * Answers the InetAddress corresponding to the array of bytes, and the
+	 * given hostname. In the case of an IPv4 address there must be exactly 4
+	 * bytes and for IPv6 exactly 16 bytes. If not, an UnknownHostException is
+	 * thrown.
+	 * 
+	 * The host name and IP address are not validated.
+	 * 
+	 * The hostname either be a machine alias or a valid IPv6 or IPv4 address
+	 * format.
+	 * 
+	 * The high order byte is <code>ipAddress[0]<\code>.
+	 *
+	 * @param 		hostName	string representation of hostname or ip address
+	 * @param 		ipAddress	either a 4 (IPv4) or 16 (IPv6) byte array
+	 * @param 		scope_id	the scope id for a scoped address.  If not a scoped address just pass
+	 * 							in 0
+	 * @return 		the InetAddress
+	 *
+	 * @throws 		UnknownHostException
+	 */
+	static InetAddress getByAddress(String hostName, byte[] ipAddress,
+			int scope_id) throws UnknownHostException {
+		byte[] copy_address;
+		if (ipAddress.length == 4) {
+			copy_address = new byte[4];
+			for (int i = 0; i < 4; i++) {
+				copy_address[i] = ipAddress[i];
+			}
+			return new Inet4Address(ipAddress, hostName);
+		}
+
+		if (ipAddress.length == 16) {
+			// First check to see if the address is an IPv6-mapped
+			// IPv4 address. If it is, then we can make it a IPv4
+			// address, otherwise, we'll create an IPv6 address.
+			if (isIPv4MappedAddress(ipAddress)) {
+				copy_address = new byte[4];
+				for (int i = 0; i < 4; i++) {
+					copy_address[i] = ipAddress[12 + i];
+				}
+				return new Inet4Address(ipAddress, hostName);
+			}
+			
+			copy_address = new byte[16];
+			for (int i = 0; i < 16; i++) {
+				copy_address[i] = ipAddress[i];
+			}
+
+			return new Inet6Address(ipAddress, hostName, scope_id);
+		}
+		throw new UnknownHostException(Msg.getString("K0332", hostName));
+	}
+
+	/**
+	 * Takes the integer and chops it into 4 bytes, putting it into the byte
+	 * array starting with the high order byte at the index start. This method
+	 * makes no checks on the validity of the paramaters.
+	 */
+	static void intToBytes(int value, byte bytes[], int start) {
+		// Shift the int so the current byte is right-most
+		// Use a byte mask of 255 to single out the last byte.
+		bytes[start] = (byte) ((value >> 24) & 255);
+		bytes[start + 1] = (byte) ((value >> 16) & 255);
+		bytes[start + 2] = (byte) ((value >> 8) & 255);
+		bytes[start + 3] = (byte) (value & 255);
+	}
+
+	/**
+	 * Takes the byte array and creates an integer out of four bytes starting at
+	 * start as the high-order byte. This method makes no checks on the validity
+	 * of the parameters.
+	 */
+	static int bytesToInt(byte bytes[], int start) {
+		// First mask the byte with 255, as when a negative
+		// signed byte converts to an integer, it has bits
+		// on in the first 3 bytes, we are only concerned
+		// about the right-most 8 bits.
+		// Then shift the rightmost byte to align with its
+		// position in the integer.
+		int value = ((bytes[start + 3] & 255))
+				| ((bytes[start + 2] & 255) << 8)
+				| ((bytes[start + 1] & 255) << 16)
+				| ((bytes[start] & 255) << 24);
+		return value;
+	}
+
+	/**
+	 * Creates an InetAddress based on an ipAddressString. No error handling is
+	 * performed here.
+	 */
+	static InetAddress createHostNameFromIPAddress(String ipAddressString)
+			throws UnknownHostException {
+
+		InetAddress address = null;
+
+		if (Inet6Util.isValidIPV4Address(ipAddressString)) {
+
+			StringTokenizer tokenizer = new StringTokenizer(ipAddressString,
+					".");
+			String token = "";
+			int tempInt = 0;
+			byte[] byteAddress = new byte[4];
+			for (int i = 0; i < 4; i++) {
+				token = tokenizer.nextToken();
+				tempInt = Integer.parseInt(token);
+				byteAddress[i] = (byte) tempInt;
+			}
+
+			address = new Inet4Address(byteAddress);
+
+		} else { // otherwise it must be ipv6
+
+			if (ipAddressString.charAt(0) == '[') {
+				ipAddressString = ipAddressString.substring(1, ipAddressString
+						.length() - 1);
+			}
+
+			StringTokenizer tokenizer = new StringTokenizer(ipAddressString,
+					":.%", true);
+			ArrayList hexStrings = new ArrayList();
+			ArrayList decStrings = new ArrayList();
+			String scopeString = null;
+			String token = "";
+			String prevToken = "";
+			String prevPrevToken = "";
+			int doubleColonIndex = -1; // If a double colon exists, we need to
+										// insert 0s.
+
+			// Go through the tokens, including the seperators ':' and '.'
+			// When we hit a : or . the previous token will be added to either
+			// the hex list or decimal list. In the case where we hit a ::
+			// we will save the index of the hexStrings so we can add zeros
+			// in to fill out the string
+			while (tokenizer.hasMoreTokens()) {
+				prevPrevToken = prevToken;
+				prevToken = token;
+				token = tokenizer.nextToken();
+
+				if (token.equals(":")) {
+					if (prevToken.equals(":")) {
+						doubleColonIndex = hexStrings.size();
+					} else if (!prevToken.equals("")) {
+						hexStrings.add(prevToken);
+					}
+				} else if (token.equals(".")) {
+					decStrings.add(prevToken);
+				} else if (token.equals("%")) {
+					// add the last word before the % properly
+					if (!prevToken.equals(":") && !prevToken.equals(".")) {
+						if (prevPrevToken.equals(":")) {
+							hexStrings.add(prevToken);
+						} else if (prevPrevToken.equals(".")) {
+							decStrings.add(prevToken);
+						}
+					}
+
+					// the rest should be the scope string
+					scopeString = tokenizer.nextToken();
+					while (tokenizer.hasMoreTokens()) {
+						scopeString = scopeString + tokenizer.nextToken();
+					}
+				}
+			}
+
+			if (prevToken.equals(":")) {
+				if (token.equals(":")) {
+					doubleColonIndex = hexStrings.size();
+				} else {
+					hexStrings.add(token);
+				}
+			} else if (prevToken.equals(".")) {
+				decStrings.add(token);
+			}
+
+			// figure out how many hexStrings we should have
+			// also check if it is a IPv4 address
+			int hexStringsLength = 8;
+
+			// If we have an IPv4 address tagged on at the end, subtract
+			// 4 bytes, or 2 hex words from the total
+			if (decStrings.size() > 0) {
+				hexStringsLength -= 2;
+			}
+
+			// if we hit a double Colon add the appropriate hex strings
+			if (doubleColonIndex != -1) {
+				int numberToInsert = hexStringsLength - hexStrings.size();
+				for (int i = 0; i < numberToInsert; i++) {
+					hexStrings.add(doubleColonIndex, "0");
+				}
+			}
+
+			byte ipByteArray[] = new byte[16];
+
+			// Finally convert these strings to bytes...
+			for (int i = 0; i < hexStrings.size(); i++) {
+				Inet6Util.convertToBytes((String) hexStrings.get(i),
+						ipByteArray, i * 2);
+			}
+
+			// Now if there are any decimal values, we know where they go...
+			for (int i = 0; i < decStrings.size(); i++) {
+				ipByteArray[i + 12] = (byte) (Integer
+						.parseInt((String) decStrings.get(i)) & 255);
+			}
+
+			// now check to see if this guy is actually and IPv4 address
+			// an ipV4 address is ::FFFF:d.d.d.d
+			boolean ipV4 = true;
+			for (int i = 0; i < 10; i++) {
+				if (ipByteArray[i] != 0) {
+					ipV4 = false;
+					break;
+				}
+			}
+
+			if (ipByteArray[10] != -1 || ipByteArray[11] != -1) {
+				ipV4 = false;
+			}
+
+			if (ipV4) {
+				byte ipv4ByteArray[] = new byte[4];
+				for (int i = 0; i < 4; i++) {
+					ipv4ByteArray[i] = ipByteArray[i + 12];
+				}
+				address = InetAddress.getByAddress(ipv4ByteArray);
+			} else {
+				int scopeId = 0;
+				if (scopeString != null) {
+					try {
+						scopeId = Integer.parseInt(scopeString);
+					} catch (Exception e) {
+						// this should not occur as we should not get into this
+						// function
+						// unless the address is in a valid format
+					}
+				}
+				address = InetAddress.getByAddress(ipByteArray, scopeId);
+			}
+		}
+
+		return address;
+	}
+
+	static boolean preferIPv6Addresses() {
+		String result = (String) AccessController.doPrivileged(new PriviAction(
+				"java.net.preferIPv6Addresses"));
+		if ("true".equals(result))
+			return true;
+		return false;
+	}
+
+	private static final ObjectStreamField[] serialPersistentFields = {
+			new ObjectStreamField("address", Integer.TYPE),
+			new ObjectStreamField("family", Integer.TYPE),
+			new ObjectStreamField("hostName", String.class) };
+
+	private void writeObject(ObjectOutputStream stream) throws IOException {
+		ObjectOutputStream.PutField fields = stream.putFields();
+		if (ipaddress == null) {
+			fields.put("address", 0);
+		} else {
+			fields.put("address", bytesToInt(ipaddress, 0));
+		}
+		fields.put("family", family);
+		fields.put("hostName", hostName);
+
+		stream.writeFields();
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		ObjectInputStream.GetField fields = stream.readFields();
+		int addr = fields.get("address", 0);
+		ipaddress = new byte[4];
+		intToBytes(addr, ipaddress, 0);
+		hostName = (String) fields.get("hostName", null);
+		family = fields.get("family", 2);
+	}
+
+	private Object readResolve() throws ObjectStreamException {
+		return new Inet4Address(ipaddress);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetSocketAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetSocketAddress.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetSocketAddress.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/InetSocketAddress.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,127 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+public class InetSocketAddress extends SocketAddress {
+
+	static final long serialVersionUID = 5076001401234631237L;
+
+	private String hostName;
+
+	private InetAddress addr;
+
+	private int port;
+
+	public InetSocketAddress(int port) {
+		this((InetAddress) null, port);
+	}
+
+	public InetSocketAddress(InetAddress address, int port) {
+		if (port < 0 || port > 65535)
+			throw new IllegalArgumentException();
+		if (address == null)
+			addr = InetAddress.ANY;
+		else
+			addr = address;
+		hostName = addr.getHostName();
+		this.port = port;
+	}
+
+	public InetSocketAddress(String host, int port) {
+		if (host == null || port < 0 || port > 65535)
+			throw new IllegalArgumentException();
+		hostName = host;
+		this.port = port;
+		try {
+			addr = InetAddress.getByName(hostName);
+		} catch (UnknownHostException e) {
+		}
+	}
+
+	public final int getPort() {
+		return port;
+	}
+
+	public final InetAddress getAddress() {
+		return addr;
+	}
+
+	public final String getHostName() {
+		return hostName;
+	}
+
+	public final boolean isUnresolved() {
+		return addr == null;
+	}
+
+	public String toString() {
+		String host;
+		if (addr != null)
+			host = addr.toString();
+		else
+			host = hostName;
+		return host + ":" + port; //$NON-NLS-1$
+	}
+
+	public final boolean equals(Object socketAddr) {
+		if (this == socketAddr)
+			return true;
+		if (!(socketAddr instanceof InetSocketAddress))
+			return false;
+		InetSocketAddress iSockAddr = (InetSocketAddress) socketAddr;
+
+		// check the ports as we always need to do this
+		if (port != iSockAddr.port) {
+			return false;
+		}
+
+		// we only use the hostnames in the comparison if the addrs were not
+		// resolved
+		if ((addr == null) && (iSockAddr.addr == null)) {
+			return hostName.equals(iSockAddr.hostName);
+		} else {
+			// addrs were resolved so use them for the comparison
+			if (addr == null) {
+				// if we are here we know iSockAddr is not null so just return
+				// false
+				return false;
+			}
+			return addr.equals(iSockAddr.addr);
+		}
+	}
+
+	public final int hashCode() {
+		if (addr == null)
+			return hostName.hashCode() + port;
+		return addr.hashCode() + port;
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		stream.defaultReadObject();
+		if (addr == null) {
+			try {
+				addr = InetAddress.getByName(hostName);
+			} catch (UnknownHostException e) {
+			}
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/JarURLConnection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/JarURLConnection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/JarURLConnection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/JarURLConnection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,172 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+/**
+ * This class establishes a connection to a URL using the jar protocol. Jar URLs
+ * are specified as follows: <center><code>jar:<url>!/{entry}</code></center>
+ * where "!/" is called a seperator.
+ */
+public abstract class JarURLConnection extends URLConnection {
+	// the location of the seperator
+	protected URLConnection jarFileURLConnection;
+
+	private String entryName;
+
+	private URL fileURL;
+
+	// the file component of the URL
+	private String file;
+
+	/**
+	 * Contructs an instance of <code>JarURLConnection</code>.
+	 * 
+	 * @param url
+	 *            java.net.URL the URL that contains the location to connect to
+	 */
+	protected JarURLConnection(URL url) throws MalformedURLException {
+		super(url);
+		file = url.getFile();
+		int sepIdx;
+		// Support embedded jar URLs by using lastIndexOf()
+		if ((sepIdx = file.lastIndexOf("!/")) < 0) {
+			throw new MalformedURLException();
+		}
+		if (file.length() == sepIdx + 2) {
+			return;
+		}
+		entryName = file.substring(sepIdx + 2, file.length());
+	}
+
+	/**
+	 * Answers the attributes of the JarEntry referenced by this
+	 * <code>JarURLConnection</code>.
+	 * 
+	 * @return java.util.jar.Attributes the attributes of the the JarEntry
+	 * @exception java.io.IOException
+	 *                thrown if an IO exception occurs while retrieving the
+	 *                JarEntry
+	 */
+	public Attributes getAttributes() throws java.io.IOException {
+		JarEntry jEntry = getJarEntry();
+		return (jEntry == null) ? null : jEntry.getAttributes();
+	}
+
+	/**
+	 * Answers the Certificates of the JarEntry referenced by this
+	 * <code>URLConnection</code>. This method will return null until the
+	 * InputStream has been completely verified
+	 * 
+	 * @return Certificate[] the Certificates of the JarEntry.
+	 * @exception java.io.IOException
+	 *                thrown if there is an IO exception occurs while getting
+	 *                the JarEntry.
+	 */
+	public Certificate[] getCertificates() throws java.io.IOException {
+		JarEntry jEntry = getJarEntry();
+		if (jEntry == null)
+			return null;
+
+		return jEntry.getCertificates();
+
+	}
+
+	/**
+	 * Answers the JarEntry name of the entry referenced by this
+	 * <code>URLConnection</code>.
+	 * 
+	 * @return java.lang.String the JarEntry name
+	 */
+	public String getEntryName() {
+		return entryName;
+	}
+
+	/**
+	 * Answers the JarEntry of the entry referenced by this
+	 * <code>URLConnection</code>.
+	 * 
+	 * @return java.util.jar.JarEntry the JarEntry referenced
+	 */
+	public JarEntry getJarEntry() throws IOException {
+		if (!connected) {
+			connect();
+		}
+		if (entryName == null) {
+			return null;
+		}
+		// The entry must exist since the connect succeeded
+		return getJarFile().getJarEntry(entryName);
+	}
+
+	/**
+	 * Answers the Manifest associated with the Jar URL
+	 * 
+	 * @return java.util.jar.Manifest The JarFile's Manifest
+	 */
+	public Manifest getManifest() throws java.io.IOException {
+		return getJarFile().getManifest();
+	}
+
+	/**
+	 * Answers the the JarFile referenced by this <code>URLConnection</code>.
+	 * 
+	 * @return java.util.jar.JarFile the JarFile
+	 * @exception java.io.IOException
+	 *                thrown if an IO exception occurs while retrieving the Jar
+	 *                file
+	 */
+	public abstract JarFile getJarFile() throws java.io.IOException;
+
+	/**
+	 * Answers the URL of the JarFile referenced by this
+	 * <code>URLConnection</code>.
+	 * 
+	 * @return java.net.URL the URL of the JarFile.
+	 */
+	public URL getJarFileURL() {
+		if (fileURL != null)
+			return fileURL;
+		try {
+			// Support embedded jar URLs by using lastIndexOf()
+			return fileURL = new URL(url.getFile().substring(0,
+					url.getFile().lastIndexOf("!/")));
+		} catch (MalformedURLException e) {
+			return null;
+		}
+	}
+
+	/**
+	 * Answers the main Attributes of the JarFile referenced by this
+	 * <code>URLConnection</code>.
+	 * 
+	 * @return java.util.jar.Attributes the Attributes of the the JarFile
+	 * @exception java.io.IOException
+	 *                thrown if an IO exception occurs while retrieving the
+	 *                JarFile
+	 */
+	public Attributes getMainAttributes() throws java.io.IOException {
+		Manifest m = getJarFile().getManifest();
+		return (m == null) ? null : m.getMainAttributes();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/MalformedURLException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/MalformedURLException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/MalformedURLException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/MalformedURLException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package java.net;
+
+
+import java.io.IOException;
+
+/**
+ * This exception is thrown when a program attempts to create an URL from an
+ * incorrect specification.
+ * 
+ * @see URL
+ */
+public class MalformedURLException extends IOException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public MalformedURLException() {
+		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 MalformedURLException(String detailMessage) {
+		super(detailMessage);
+	}
+}



Mime
View raw message