harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r374034 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java: com/ibm/oti/util/Inet6Util.java java/net/Inet6Address.java
Date Wed, 01 Feb 2006 10:32:53 GMT
Author: tellison
Date: Wed Feb  1 02:32:48 2006
New Revision: 374034

URL: http://svn.apache.org/viewcvs?rev=374034&view=rev
Log:
Make Inet6Util helper public, and call from from getHostAddress()

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/com/ibm/oti/util/Inet6Util.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/com/ibm/oti/util/Inet6Util.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/com/ibm/oti/util/Inet6Util.java?rev=374034&r1=374033&r2=374034&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/com/ibm/oti/util/Inet6Util.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/com/ibm/oti/util/Inet6Util.java
Wed Feb  1 02:32:48 2006
@@ -147,8 +147,9 @@
 
 	}
 
-	static String createIPAddrStringFromByteArray(byte ipByteArray[]) {
+	static String hexCharacters = "0123456789ABCDEF";
 
+	public static String createIPAddrStringFromByteArray(byte ipByteArray[]) {
 		if (ipByteArray.length == 4) {
 			return addressToString(bytesToInt(ipByteArray, 0));
 		}
@@ -160,27 +161,23 @@
 					ipv4ByteArray[i] = ipByteArray[i + 12];
 				}
 				return addressToString(bytesToInt(ipv4ByteArray, 0));
-			}
-
-			StringBuffer buffer = new StringBuffer();
-			for (int i = 0; i < ipByteArray.length; i++) {
-				int j = (ipByteArray[i] & 0xf0) >>> 4;
-				buffer.append(hexCharacters[j]);
-				j = ipByteArray[i] & 0x0f;
-				buffer.append(hexCharacters[j]);
-				if (i % 2 != 0) {
-					buffer.append(":");
+			} else {
+				StringBuffer buffer = new StringBuffer();
+				for (int i = 0; i < ipByteArray.length; i++) {
+					int j = (ipByteArray[i] & 0xf0) >>> 4;
+					buffer.append(hexCharacters.charAt(j));
+					j = ipByteArray[i] & 0x0f;
+					buffer.append(hexCharacters.charAt(j));
+					if (i % 2 != 0 && (i + 1) < ipByteArray.length) {
+						buffer.append(":");
+					}
 				}
+				return buffer.toString();
 			}
-			return buffer.toString().substring(0, buffer.length() - 1)
-					.toUpperCase();
 		}
 		return null;
 	}
 
-	static char[] hexCharacters = { '0', '1', '2', '3', '4', '5', '6', '7',
-			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
 	/** Converts a 4 character hex word into a 2 byte word equivalent */
 	public static void convertToBytes(String hexWord, byte ipByteArray[],
 			int byteIndex) {
@@ -406,8 +403,7 @@
 				return false;
 		} else {
 			// If we're at then end and we haven't had 7 colons then there is a
-			// problem
-			// unless we encountered a doubleColon
+			// problem unless we encountered a doubleColon
 			if (numberOfColons != 7 && !doubleColon) {
 				return false;
 			}
@@ -416,7 +412,7 @@
 			// a : or a .
 			// If we did not end in :: then this is invalid
 			if (numberOfPercent == 0) {
-				if (word == "" && ipAddress.charAt(length - 1 - offset) != ':'
+				if (word == "" && ipAddress.charAt(length - 1 - offset) == ':'
 						&& ipAddress.charAt(length - 2 - offset) != ':') {
 					return false;
 				}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java?rev=374034&r1=374033&r2=374034&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
Wed Feb  1 02:32:48 2006
@@ -21,6 +21,8 @@
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamField;
 
+import com.ibm.oti.util.Inet6Util;
+
 public final class Inet6Address extends InetAddress {
 
 	static final long serialVersionUID = 6880410070516793377L;
@@ -247,38 +249,8 @@
 		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();
+		return Inet6Util.createIPAddrStringFromByteArray(ipaddress);
 	}
 
 	public int hashCode() {



Mime
View raw message