You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/04/21 23:52:05 UTC
svn commit: r396013 - in
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
main/java/java/net/Inet6Address.java main/java/java/net/InetAddress.java
test/java/tests/api/java/net/Inet6AddressTest.java
Author: tellison
Date: Fri Apr 21 14:52:02 2006
New Revision: 396013
URL: http://svn.apache.org/viewcvs?rev=396013&view=rev
Log:
Apply patch HARMONY-360 (Java 5 Enhancement: One new method getByAddress(String, byte[], int) in class java.net.Inet6Address)
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java
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=396013&r1=396012&r2=396013&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 Fri Apr 21 14:52:02 2006
@@ -1,4 +1,4 @@
-/* Copyright 2003, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2003, 2006 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.
@@ -58,7 +58,7 @@
* @param address
* network address
* @param name
- * Name assocaited with the address
+ * Name associated with the address
* @param scope_id
* The scope id for link or site local addresses
*/
@@ -71,6 +71,31 @@
}
}
+ /**
+ * Constructs an IPv6 address according to the given <code>host</code>,
+ * <code>addr</code> and <code>scope_id</code>.
+ *
+ * @param host
+ * hostname associated with the address
+ * @param addr
+ * network address
+ * @param scope_id
+ * the scope id for link or site local addresses
+ * @return an Inet6Address instance
+ * @throws UnknownHostException
+ * if the address is null or of invalid length
+ */
+ public static Inet6Address getByAddress(String host, byte[] addr,
+ int scope_id) throws UnknownHostException {
+ if (null == addr || 16 != addr.length) {
+ throw new UnknownHostException("Illegal ipv6 address");
+ }
+ if(scope_id < 0){
+ scope_id = 0;
+ }
+ return new Inet6Address(addr, host, scope_id);
+ }
+
/**
* Constructs an InetAddress, representing the <code>address</code> and
* <code>hostName</code> and <code>scope_id</code>
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java?rev=396013&r1=396012&r2=396013&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java Fri Apr 21 14:52:02 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 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.
@@ -813,7 +813,7 @@
throws UnknownHostException {
// just call the method by the same name passing in a default scope id
// of 0
- return getByAddress(hostName, ipAddress, 0);
+ return getByAddressInternal(hostName, ipAddress, 0);
}
/**
@@ -837,7 +837,7 @@
*
* @throws UnknownHostException
*/
- static InetAddress getByAddress(String hostName, byte[] ipAddress,
+ static InetAddress getByAddressInternal(String hostName, byte[] ipAddress,
int scope_id) throws UnknownHostException {
byte[] copy_address;
if (ipAddress != null && ipAddress.length == 4) {
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java?rev=396013&r1=396012&r2=396013&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java Fri Apr 21 14:52:02 2006
@@ -1,4 +1,4 @@
-/* Copyright 2003, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2003, 2006 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.
@@ -825,6 +825,40 @@
}
;
+ }
+ }
+
+ /**
+ * @tests java.net.Inet6Address#getByAddress(String, byte[], int)
+ */
+ public void test_getByAddressLString$BI(){
+ try {
+ Inet6Address.getByAddress("123", null, 0);
+ fail("should throw UnknownHostException");
+ } catch (UnknownHostException uhe) {
+ // expected
+ }
+ byte[] addr1 = { (byte) 127, 0, 0, 1 };
+ try {
+ Inet6Address.getByAddress("123", addr1, 0);
+ fail("should throw UnknownHostException");
+ } catch (UnknownHostException uhe) {
+ // expected
+ }
+
+ byte[] addr2 = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02,
+ 0x11, 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
+ (byte) 0xB2 };
+
+ try {
+ Inet6Address.getByAddress("123", addr2, 3);
+ } catch (UnknownHostException e) {
+ fail("no exception should be thrown");
+ }
+ try {
+ Inet6Address.getByAddress("123", addr2, 3);
+ } catch (UnknownHostException e) {
+ fail("no exception should be thrown");
}
}