You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/08/30 06:10:38 UTC
svn commit: r438345 [1/2] -
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/
Author: ndbeyer
Date: Tue Aug 29 21:10:37 2006
New Revision: 438345
URL: http://svn.apache.org/viewvc?rev=438345&view=rev
Log:
java.net code cleanup; add braces, remove unecessary initialization and compiler warnings
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java
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/main/java/java/net/InetSocketAddress.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URISyntaxException.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLDecoder.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java
incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/DatagramSocketImpl.java Tue Aug 29 21:10:37 2006
@@ -23,7 +23,7 @@
import org.apache.harmony.luni.platform.Platform;
/**
- * The abstract superclass of datagram & multicast socket implementatations.
+ * The abstract superclass of datagram & multicast socket implementations.
*/
public abstract class DatagramSocketImpl implements SocketOptions {
@@ -50,7 +50,7 @@
* the address on the multihomed localhost to bind
*
* @exception SocketException
- * if an error occured during bind, such as if the port was
+ * if an error occurred during bind, such as if the port was
* already bound
*/
protected abstract void bind(int port, InetAddress addr)
@@ -110,18 +110,19 @@
* Answer the time-to-live (TTL) for multicast packets sent on this socket.
*
* @return java.net.InetAddress
- * @exception java.io.IOException
+ * @@throws IOException
* The exception description.
* @deprecated Replaced by getTimeToLive
* @see #getTimeToLive()
*/
- protected abstract byte getTTL() throws IOException;
+ @Deprecated
+ protected abstract byte getTTL() throws IOException;
/**
* Answer the time-to-live (TTL) for multicast packets sent on this socket.
*
* @return int
- * @exception java.io.IOException
+ * @@throws IOException
* The exception description.
*/
protected abstract int getTimeToLive() throws IOException;
@@ -143,7 +144,7 @@
*
* @param addr
* the multicast group to be joined
- * @exception java.io.IOException
+ * @@throws IOException
* may be thrown while joining a group
*/
protected abstract void join(InetAddress addr) throws IOException;
@@ -157,7 +158,7 @@
* the multicast group to be joined
* @param netInterface
* the network interface on which the addresses should be dropped
- * @exception java.io.IOException
+ * @@throws IOException
* may be thrown while joining a group
*/
protected abstract void joinGroup(SocketAddress addr,
@@ -168,7 +169,7 @@
*
* @param addr
* the multicast group to be left
- * @exception java.io.IOException
+ * @@throws IOException
* May be thrown while leaving the group
*/
protected abstract void leave(InetAddress addr) throws IOException;
@@ -180,7 +181,7 @@
* the multicast group to be left
* @param netInterface
* the network interface on which the addresses should be dropped
- * @exception java.io.IOException
+ * @@throws IOException
* May be thrown while leaving the group
*/
protected abstract void leaveGroup(SocketAddress addr,
@@ -236,7 +237,7 @@
*
* @param ttl
* the time-to-live, 0<ttl<= 255
- * @exception java.io.IOException
+ * @@throws IOException
* The exception thrown while setting the TTL
*/
protected abstract void setTimeToLive(int ttl) throws IOException;
@@ -246,12 +247,13 @@
*
* @param ttl
* the time-to-live, 0<ttl<= 255
- * @exception java.io.IOException
+ * @@throws IOException
* The exception thrown while setting the TTL
* @deprecated Replaced by setTimeToLive
* @see #setTimeToLive(int)
*/
- protected abstract void setTTL(byte ttl) throws IOException;
+ @Deprecated
+ protected abstract void setTTL(byte ttl) throws IOException;
/**
* Connect the socket to the specified remote address and port.
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/HttpURLConnection.java Tue Aug 29 21:10:37 2006
@@ -16,6 +16,7 @@
package java.net;
+import java.io.IOException;
import java.net.ProtocolException;
import java.net.URL;
import org.apache.harmony.luni.util.Msg;
@@ -100,7 +101,7 @@
public final static int HTTP_FORBIDDEN = 403;
/**
- * Numeric status code, 504: atewaytimeout
+ * Numeric status code, 504: Gateway timeout
*/
public final static int HTTP_GATEWAY_TIMEOUT = 504;
@@ -207,7 +208,8 @@
/**
* @deprecated Use HTTP_INTERNAL_ERROR
*/
- public final static int HTTP_SERVER_ERROR = 500;
+ @Deprecated
+ public final static int HTTP_SERVER_ERROR = 500;
/**
* Numeric status code, 305: Use proxy
@@ -289,21 +291,23 @@
*
* @return the permission object required for this connection
*
- * @throws java.io.IOException
+ * @throws IOException
* if an IO exception occurs during the creation of the
* permission object.
*/
- public java.security.Permission getPermission() throws java.io.IOException {
+ @Override
+ public java.security.Permission getPermission() throws IOException {
int port = url.getPort();
- if (port < 0)
- port = 80;
+ 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
+ * remote HTTP server. All possible methods of this HTTP implementation is listed in
* the class definition.
*
* @return the request method string
@@ -316,34 +320,38 @@
}
/**
- * Answers the reponse code returned by the remote HTTP server
+ * Answers the response code returned by the remote HTTP server
*
* @return the response code, -1 if no valid response code
*
- * @throws java.io.IOException
+ * @throws IOException
* if there is an IO error during the retrieval.
*
* @see #getResponseMessage
*/
- public int getResponseCode() throws java.io.IOException {
+ public int getResponseCode() throws 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;
+ if (response == null) {
+ return -1;
+ }
response.trim();
int mark = response.indexOf(" ") + 1;
- if (mark == 0)
- return -1;
+ if (mark == 0) {
+ return -1;
+ }
int last = mark + 3;
- if (last > response.length())
- last = response.length();
+ if (last > response.length()) {
+ last = response.length();
+ }
responseCode = Integer.parseInt(response.substring(mark, last));
- if (last + 1 <= response.length())
- responseMessage = response.substring(last + 1);
+ if (last + 1 <= response.length()) {
+ responseMessage = response.substring(last + 1);
+ }
return responseCode;
}
@@ -352,15 +360,16 @@
*
* @return the response message. <code>null</code> if such response exists
*
- * @throws java.io.IOException
+ * @throws IOException
* if there is an IO error during the retrieval.
*
* @see #getResponseCode()
- * @see java.io.IOException
+ * @see IOException
*/
- public String getResponseMessage() throws java.io.IOException {
- if (responseMessage != null)
- return responseMessage;
+ public String getResponseMessage() throws IOException {
+ if (responseMessage != null) {
+ return responseMessage;
+ }
getResponseCode();
return responseMessage;
}
@@ -378,8 +387,9 @@
public static void setFollowRedirects(boolean auto) {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkSetFactory();
+ if (security != null) {
+ security.checkSetFactory();
+ }
followRedirects = auto;
}
@@ -392,14 +402,15 @@
*
* @throws java.net.ProtocolException
* Thrown when this is called after connected, or the method is
- * not supported by this HTTP impl.
+ * not supported by this HTTP implementation.
*
* @see #getRequestMethod()
* @see #method
*/
public void setRequestMethod(String method) throws ProtocolException {
- if (connected)
- throw new ProtocolException(org.apache.harmony.luni.util.Msg.getString("K0037"));
+ if (connected) {
+ throw new ProtocolException(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
@@ -451,7 +462,8 @@
* the default value if no field is found
* @return milliseconds since epoch
*/
- public long getHeaderFieldDate(String field, long defaultValue) {
+ @Override
+ public long getHeaderFieldDate(String field, long defaultValue) {
return super.getHeaderFieldDate(field, defaultValue);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet4Address.java Tue Aug 29 21:10:37 2006
@@ -32,37 +32,38 @@
}
/**
- * 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 true if the address is a multicast address. Valid IPv4 multicast
+ * addresses are prefixed with 1110 = 0xE
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isMulticastAddress() {
+ return (ipaddress[0] & 0xF0) == 0xE0;
+ }
/**
* Answers if the address is the ANY Address
*
* @return boolean
*/
- public boolean isAnyLocalAddress() {
+ @Override
+ public boolean isAnyLocalAddress() {
for (int i = 0; i < ipaddress.length; i++) {
- if (ipaddress[i] != 0)
- return false;
+ 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
+ * @return boolean
*/
- public boolean isLoopbackAddress() {
+ @Override
+ public boolean isLoopbackAddress() {
return (ipaddress[0] & 255) == 127;
}
@@ -75,7 +76,8 @@
*
* @return boolean
*/
- public boolean isLinkLocalAddress() {
+ @Override
+ public boolean isLinkLocalAddress() {
// The reference implementation does not return true
// for loopback addresses even though RFC 3484 says to do so
return (((ipaddress[0] & 255) == 169) && ((ipaddress[1] & 255) == 254));
@@ -83,14 +85,13 @@
/**
* Answers whether this address has site-local scope.
- *
- * @return boolean
- *
* RFC 3484 Default Address Selection for Internet Protocol version 6 (IPv6)
* states IPv4 private addresses, prefixes 10/8, 172.16/12, and 192.168/16,
* are assigned site-local scope.
+ * @return boolean
*/
- public boolean isSiteLocalAddress() {
+ @Override
+ public boolean isSiteLocalAddress() {
return ((ipaddress[0] & 255) == 10) || ((ipaddress[0] & 255) == 172)
&& (((ipaddress[1] & 255) > 15) && (ipaddress[1] & 255) < 32)
|| ((ipaddress[0] & 255) == 192)
@@ -99,82 +100,87 @@
/**
* 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
+ * @return boolean true, if the address is in the global multicast group,
+ * false otherwise
*/
- public boolean isMCGlobal() {
+ @Override
+ public boolean isMCGlobal() {
// Check if we have a prefix of 1110
- if (!isMulticastAddress())
- return false;
+ 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;
+ /*
+ * 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 multicast. ( < 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() {
+ * Answers false for all IPv4 addresses. There are no valid IPv4 Node-local
+ * addresses
+ *
+ * @return boolean
+ */
+ @Override
+ 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() {
+ * Answers true if the address is a link-local address.The valid range for
+ * IPv4 link-local addresses is: 224.0.0.0 to 239.0.0.255 Hence a mask of
+ * 111000000000000000000000 = 0xE00000
+ *
+ * @return boolean
+ */
+ @Override
+ 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() {
+ * Answers true if the address is a site-local address.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.
+ *
+ * @return boolean
+ */
+ @Override
+ 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() {
+ * Answers true if the address is a organization-local address. 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
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean isMCOrgLocal() {
int prefix = InetAddress.bytesToInt(ipaddress, 0) >>> 16;
return prefix >= 0xEFC0 && prefix <= 0xEFC3;
}
@@ -185,12 +191,14 @@
* @return String
*
*/
- public String getHostAddress() {
+ @Override
+ public String getHostAddress() {
String hostAddress = "";
for (int i = 0; i < 4; i++) {
hostAddress += ipaddress[i] & 255;
- if (i != 3)
- hostAddress += ".";
+ if (i != 3) {
+ hostAddress += ".";
+ }
}
return hostAddress;
}
@@ -201,7 +209,8 @@
* @return String
*
*/
- public int hashCode() {
+ @Override
+ public int hashCode() {
return InetAddress.bytesToInt(ipaddress, 0);
}
@@ -212,7 +221,8 @@
* @return String
*
*/
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj) {
return super.equals(obj);
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Inet6Address.java?rev=438345&r1=438344&r2=438345&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 Tue Aug 29 21:10:37 2006
@@ -32,18 +32,18 @@
static final InetAddress ANY = new Inet6Address(any_bytes);
static final InetAddress LOOPBACK = new Inet6Address(localhost_bytes, "localhost");
- int scope_id = 0;
+ int scope_id;
- boolean scope_id_set = false;
+ boolean scope_id_set;
- boolean scope_ifname_set = false;
+ boolean scope_ifname_set;
- String ifname = null;
+ String ifname;
/*
* scoped interface.
*/
- transient NetworkInterface scopedIf = null;
+ transient NetworkInterface scopedIf;
Inet6Address(byte address[]) {
ipaddress = address;
@@ -200,7 +200,8 @@
* @return boolean true, if the address is in the multicast group, false
* otherwise
*/
- public boolean isMulticastAddress() {
+ @Override
+ public boolean isMulticastAddress() {
// Multicast addresses are prefixed with 11111111 (255)
return ipaddress[0] == -1;
@@ -212,7 +213,8 @@
* @return boolean true, if the address is in the multicast group, false
* otherwise
*/
- public boolean isAnyLocalAddress() {
+ @Override
+ public boolean isAnyLocalAddress() {
for (int i = 0; i < ipaddress.length; i++) {
if (ipaddress[i] != 0) {
return false;
@@ -228,7 +230,8 @@
*
* @return boolean true if the address is the loopback, false otherwise
*/
- public boolean isLoopbackAddress() {
+ @Override
+ public boolean isLoopbackAddress() {
// The last word must be 1
if (ipaddress[15] != 1) {
@@ -252,7 +255,8 @@
*
* @return boolean true, if it is a link-local address, false otherwise
*/
- public boolean isLinkLocalAddress() {
+ @Override
+ public boolean isLinkLocalAddress() {
// the first 10 bits need to be 1111111010 (1018)
return (ipaddress[0] == -2) && ((ipaddress[1] & 255) >>> 6) == 2;
@@ -265,7 +269,8 @@
*
* @return boolean true, if it is a site-local address, false otherwise
*/
- public boolean isSiteLocalAddress() {
+ @Override
+ public boolean isSiteLocalAddress() {
// the first 10 bits need to be 1111111011 (1019)
return (ipaddress[0] == -2) && ((ipaddress[1] & 255) >>> 6) == 3;
@@ -279,7 +284,8 @@
* @return boolean true, if it is a global multicast address, false
* otherwise
*/
- public boolean isMCGlobal() {
+ @Override
+ public boolean isMCGlobal() {
// the first byte should be 0xFF and the lower 4 bits
// of the second byte should be 0xE
@@ -295,7 +301,8 @@
* @return boolean true, if it is a node-local multicast address, false
* otherwise
*/
- public boolean isMCNodeLocal() {
+ @Override
+ public boolean isMCNodeLocal() {
// the first byte should be 0xFF and the lower 4 bits
// of the second byte should be 0x1
@@ -312,7 +319,8 @@
* @return boolean true, if it is a link-local multicast address, false
* otherwise
*/
- public boolean isMCLinkLocal() {
+ @Override
+ public boolean isMCLinkLocal() {
// the first byte should be 0xFF and the lower 4 bits
// of the second byte should be 0x2
@@ -329,7 +337,8 @@
* @return boolean true, if it is a site-local multicast address, false
* otherwise
*/
- public boolean isMCSiteLocal() {
+ @Override
+ public boolean isMCSiteLocal() {
// the first byte should be 0xFF and the lower 4 bits
// of the second byte should be 0x5
@@ -346,14 +355,16 @@
* @return boolean true, if it is a org-local multicast address, false
* otherwise
*/
- public boolean isMCOrgLocal() {
+ @Override
+ 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;
}
- public String getHostAddress() {
+ @Override
+ public String getHostAddress() {
return Inet6Util.createIPAddrStringFromByteArray(ipaddress);
}
@@ -383,7 +394,8 @@
return null;
}
- public int hashCode() {
+ @Override
+ public int hashCode() {
/* Returns the low order int as the hash code */
return bytesToInt(ipaddress, 12);
}
@@ -396,7 +408,8 @@
* @return String
*
*/
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj) {
return super.equals(obj);
}
@@ -454,7 +467,8 @@
*
* @return String the description, as host/address
*/
- public String toString() {
+ @Override
+ public String toString() {
if (ifname != null) {
return super.toString() + "%" + ifname;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java?rev=438345&r1=438344&r2=438345&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 Tue Aug 29 21:10:37 2006
@@ -61,7 +61,7 @@
private Object waitReachable = new Object();
- private boolean reached = false;
+ private boolean reached;
private int addrCount;
@@ -136,7 +136,8 @@
* the object to be tested for equality
* @return boolean true, if the objects are equal
*/
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
@@ -374,7 +375,8 @@
*
* @return int the hashcode
*/
- public int hashCode() {
+ @Override
+ public int hashCode() {
return bytesToInt(ipaddress, 0);
}
@@ -514,7 +516,8 @@
*
* @return String the description, as host/address
*/
- public String toString() {
+ @Override
+ public String toString() {
return (hostName == null ? "" : hostName) + "/" + getHostAddress();
}
@@ -810,6 +813,7 @@
while (addresses.hasMoreElements()) {
final InetAddress addr = addresses.nextElement();
new Thread() {
+ @Override
public void run() {
boolean threadReached = false;
// if isICMP, tries ICMP ping, else TCP echo
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetSocketAddress.java Tue Aug 29 21:10:37 2006
@@ -34,12 +34,14 @@
}
public InetSocketAddress(InetAddress address, int port) {
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException();
- if (address == null)
- addr = InetAddress.ANY;
- else
- addr = address;
+ if (port < 0 || port > 65535) {
+ throw new IllegalArgumentException();
+ }
+ if (address == null) {
+ addr = InetAddress.ANY;
+ } else {
+ addr = address;
+ }
hostname = addr.getHostName();
this.port = port;
}
@@ -53,8 +55,9 @@
* createUnresolved(String, int);
*/
InetSocketAddress(String host, int port, boolean needResolved){
- if (host == null || port < 0 || port > 65535)
- throw new IllegalArgumentException();
+ if (host == null || port < 0 || port > 65535) {
+ throw new IllegalArgumentException();
+ }
hostname = host;
this.port = port;
if(needResolved){
@@ -97,7 +100,8 @@
return addr == null;
}
- public String toString() {
+ @Override
+ public String toString() {
String host;
if (addr != null) {
host = addr.toString();
@@ -107,11 +111,14 @@
return host + ":" + port; //$NON-NLS-1$
}
- public final boolean equals(Object socketAddr) {
- if (this == socketAddr)
- return true;
- if (!(socketAddr instanceof InetSocketAddress))
- return false;
+ @Override
+ 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
@@ -123,18 +130,19 @@
// 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);
}
+
+ // 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() {
+ @Override
+ public final int hashCode() {
if (addr == null) {
return hostname.hashCode() + port;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/MulticastSocket.java Tue Aug 29 21:10:37 2006
@@ -32,7 +32,7 @@
final static int SO_REUSEPORT = 512;
- private InetAddress interfaceSet = null;
+ private InetAddress interfaceSet;
/**
* Constructs a multicast socket, bound to any available port on the
@@ -173,12 +173,15 @@
* @deprecated Replaced by getTimeToLive
* @see #getTimeToLive()
*/
- public byte getTTL() throws IOException {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public byte getTTL() throws IOException {
checkClosedAndBind(false);
return impl.getTTL();
}
- boolean isMulticastSocket() {
+ @Override
+ boolean isMulticastSocket() {
return true;
}
@@ -348,7 +351,9 @@
*
* @deprecated use MulticastSocket#setTimeToLive
*/
- public void send(DatagramPacket pack, byte ttl) throws IOException {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public void send(DatagramPacket pack, byte ttl) throws IOException {
checkClosedAndBind(false);
InetAddress packAddr = pack.getAddress();
SecurityManager security = System.getSecurityManager();
@@ -545,12 +550,15 @@
* @deprecated Replaced by setTimeToLive
* @see #setTimeToLive(int)
*/
- public void setTTL(byte ttl) throws IOException {
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public void setTTL(byte ttl) throws IOException {
checkClosedAndBind(false);
impl.setTTL(ttl);
}
- synchronized void createSocket(int aPort, InetAddress addr)
+ @Override
+ synchronized void createSocket(int aPort, InetAddress addr)
throws SocketException {
impl = factory != null ? factory.createDatagramSocketImpl()
: SocketImplProvider.getMulticastSocketImpl();
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java Tue Aug 29 21:10:37 2006
@@ -55,7 +55,8 @@
* @param eldest
* the map entry which will be deleted if we return true
*/
- protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > MAX_NEGATIVE_ENTRIES;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NetworkInterface.java Tue Aug 29 21:10:37 2006
@@ -33,18 +33,18 @@
static final int UNSET_INTERFACE_INDEX = -1;
- private String name = null;
+ private String name;
- private String displayName = null;
+ private String displayName;
- InetAddress addresses[] = null;
+ InetAddress addresses[];
// The interface index is a positive integer which is non-negative. Where
// value is zero then we do not have an index for the interface (which
// occurs in systems which only support IPV4)
- private int interfaceIndex = 0;
+ private int interfaceIndex;
- private int hashCode = 0;
+ private int hashCode;
/**
* This native answers the list of network interfaces supported by the
@@ -328,6 +328,7 @@
*
* @see #hashCode
*/
+ @Override
public boolean equals(Object obj) {
// just return true if it is the exact same object
if (obj == this) {
@@ -395,6 +396,7 @@
*
* @return the hashcode for hashtable indexing
*/
+ @Override
public int hashCode() {
if (hashCode == 0) {
hashCode = name.hashCode();
@@ -408,6 +410,7 @@
*
* @return a printable representation for the network interface
*/
+ @Override
public String toString() {
StringBuilder string = new StringBuilder(25);
string.append("[");
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/PasswordAuthentication.java Tue Aug 29 21:10:37 2006
@@ -36,7 +36,7 @@
*/
public PasswordAuthentication(String userName, char[] password) {
this.userName = userName;
- this.password = (char[]) password.clone();
+ this.password = password.clone();
}
/**
@@ -45,7 +45,7 @@
* @return char[] the reference of the password
*/
public char[] getPassword() {
- return (char[]) password.clone();
+ return password.clone();
}
/**
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Proxy.java Tue Aug 29 21:10:37 2006
@@ -104,7 +104,8 @@
* @see java.lang.Object#equals(java.lang.Object)
* @return representing string of the proxy.
*/
- public String toString() {
+ @Override
+ public String toString() {
String proxyString = String.valueOf(type);
if (null != address) {
proxyString += "/" + address.toString();
@@ -124,7 +125,8 @@
* @return true if <code>obj</code> represents the same proxy. Otherwise,
* returns false.
*/
- public final boolean equals(Object obj) {
+ @Override
+ public final boolean equals(Object obj) {
if(this == obj){
return true;
}
@@ -142,7 +144,8 @@
* @see java.lang.Object#hashCode()
* @return the hash code of <code>Proxy</code>.
*/
- public final int hashCode() {
+ @Override
+ public final int hashCode() {
int ret = 0;
ret += type.hashCode();
if (null != address) {
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ProxySelectorImpl.java Tue Aug 29 21:10:37 2006
@@ -22,7 +22,7 @@
import org.apache.harmony.luni.util.Msg;
import org.apache.harmony.luni.util.PriviAction;
-/*
+/**
* Default implementation for ProxySelector
*/
class ProxySelectorImpl extends ProxySelector {
@@ -35,32 +35,20 @@
private static final int SOCKS_PROXY_PORT = 1080;
- /*
- * Constructor method.
- */
public ProxySelectorImpl() {
super();
}
- /*
- * (non-Javadoc)
- *
- * @see java.net.ProxySelector#connectFailed(java.net.URI,
- * java.net.SocketAddress, java.io.IOException)
- */
- public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+ @Override
+ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
if (null == uri || null == sa || null == ioe) {
// "KA001=Argument must not be null"
throw new IllegalArgumentException(Msg.getString("KA001")); //$NON-NLS-1$
}
}
- /*
- * (non-Javadoc)
- *
- * @see java.net.ProxySelector#select(java.net.URI)
- */
- public List<Proxy> select(URI uri) {
+ @Override
+ public List<Proxy> select(URI uri) {
// argument check
if (null == uri) {
// "KA001=Argument must not be null"
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ServerSocket.java Tue Aug 29 21:10:37 2006
@@ -37,11 +37,11 @@
static SocketImplFactory factory;
- private volatile boolean isCreated = false;
+ private volatile boolean isCreated;
- private boolean isBound = false;
+ private boolean isBound;
- private boolean isClosed = false;
+ private boolean isClosed;
/**
* Construct a ServerSocket, which is not bound to any port. The default
@@ -131,8 +131,9 @@
*/
public Socket accept() throws IOException {
checkClosedAndCreate(false);
- if (!isBound())
- throw new SocketException(Msg.getString("K031f"));
+ if (!isBound()) {
+ throw new SocketException(Msg.getString("K031f"));
+ }
Socket aSocket = new Socket();
try {
@@ -163,11 +164,13 @@
* the candidate port to listen on
*/
void checkListen(int aPort) {
- if (aPort < 0 || aPort > 65535)
- throw new IllegalArgumentException(Msg.getString("K0325", aPort)); //$NON-NLS-1$
+ if (aPort < 0 || aPort > 65535) {
+ throw new IllegalArgumentException(Msg.getString("K0325", aPort)); //$NON-NLS-1$
+ }
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkListen(aPort);
+ if (security != null) {
+ security.checkListen(aPort);
+ }
}
/**
@@ -195,8 +198,9 @@
* @return InetAddress the local address
*/
public InetAddress getInetAddress() {
- if (!isBound())
- return null;
+ if (!isBound()) {
+ return null;
+ }
return impl.getInetAddress();
}
@@ -207,8 +211,9 @@
* @return int the local port the server is listening on
*/
public int getLocalPort() {
- if (!isBound())
- return -1;
+ if (!isBound()) {
+ return -1;
+ }
return impl.getLocalPort();
}
@@ -267,12 +272,14 @@
public static synchronized void setSocketFactory(SocketImplFactory aFactory)
throws IOException {
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkSetFactory();
- if (factory == null)
- factory = aFactory;
- else
- throw new SocketException(Msg.getString("K0042")); //$NON-NLS-1$
+ if (security != null) {
+ security.checkSetFactory();
+ }
+ if (factory == null) {
+ factory = aFactory;
+ } else {
+ throw new SocketException(Msg.getString("K0042")); //$NON-NLS-1$
+ }
}
/**
@@ -299,7 +306,8 @@
*
* @return String the description
*/
- public String toString() {
+ @Override
+ public String toString() {
StringBuffer result = new StringBuffer(64);
result.append("ServerSocket["); //$NON-NLS-1$
if (!isBound()) {
@@ -348,23 +356,27 @@
*/
public void bind(SocketAddress localAddr, int backlog) throws IOException {
checkClosedAndCreate(true);
- if (isBound())
- throw new BindException(Msg.getString("K0315")); //$NON-NLS-1$
+ if (isBound()) {
+ throw new BindException(Msg.getString("K0315")); //$NON-NLS-1$
+ }
int port = 0;
InetAddress addr = InetAddress.ANY;
if (localAddr != null) {
- if (!(localAddr instanceof InetSocketAddress))
- throw new IllegalArgumentException(Msg.getString(
+ if (!(localAddr instanceof InetSocketAddress)) {
+ throw new IllegalArgumentException(Msg.getString(
"K0316", localAddr.getClass())); //$NON-NLS-1$
+ }
InetSocketAddress inetAddr = (InetSocketAddress) localAddr;
- if ((addr = inetAddr.getAddress()) == null)
- throw new SocketException(Msg.getString(
+ if ((addr = inetAddr.getAddress()) == null) {
+ throw new SocketException(Msg.getString(
"K0317", inetAddr.getHostName())); //$NON-NLS-1$
+ }
port = inetAddr.getPort();
}
SecurityManager security = System.getSecurityManager();
- if (security != null)
- security.checkListen(port);
+ if (security != null) {
+ security.checkListen(port);
+ }
synchronized (this) {
try {
@@ -383,8 +395,9 @@
* socket is not bound. This is useful on multihomed hosts.
*/
public SocketAddress getLocalSocketAddress() {
- if (!isBound())
- return null;
+ if (!isBound()) {
+ return null;
+ }
return new InetSocketAddress(getInetAddress(), getLocalPort());
}
@@ -406,15 +419,18 @@
* Check if the socket is closed, and throw an exception.
*/
private void checkClosedAndCreate(boolean create) throws SocketException {
- if (isClosed())
- throw new SocketException(Msg.getString("K003d"));
+ if (isClosed()) {
+ throw new SocketException(Msg.getString("K003d"));
+ }
- if (!create || isCreated)
- return;
+ if (!create || isCreated) {
+ return;
+ }
synchronized (this) {
- if (isCreated)
- return;
+ if (isCreated) {
+ return;
+ }
try {
impl.create(true);
} catch (SocketException e) {
@@ -459,10 +475,11 @@
*/
public void setReceiveBufferSize(int size) throws SocketException {
checkClosedAndCreate(true);
- if (size >= 1)
- impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
- else
- throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
+ if (size >= 1) {
+ impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
+ } else {
+ throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
+ }
}
/**
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketImpl.java Tue Aug 29 21:10:37 2006
@@ -52,11 +52,11 @@
INetworkSystem netImpl;
- int receiveTimeout = 0;
+ int receiveTimeout;
boolean streaming = true;
- boolean shutdownInput = false;
+ boolean shutdownInput;
// Used when cache mode is OK
// Fill in the JNI id caches
@@ -376,15 +376,17 @@
*/
int read(byte[] buffer, int offset, int count) throws IOException {
- if (shutdownInput)
- return -1;
+ if (shutdownInput) {
+ return -1;
+ }
try {
// int read = receiveStreamImpl(fd, buffer, offset, count,
// receiveTimeout);
int read = this.netImpl.receiveStream(fd, buffer, offset, count,
receiveTimeout);
- if (read == -1)
- shutdownInput = true;
+ if (read == -1) {
+ shutdownInput = true;
+ }
return read;
} catch (InterruptedIOException e) {
throw new SocketTimeoutException(e.getMessage());
@@ -411,7 +413,8 @@
*
* @return String the description
*/
- public String toString() {
+ @Override
+ public String toString() {
return new StringBuffer(100).append("Socket[addr=").append(
getInetAddress()).append(",port=").append(port).append(
",localport=").append(getLocalPort()).append("]").toString();
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermission.java Tue Aug 29 21:10:37 2006
@@ -78,9 +78,9 @@
"accept", "", "", "", "resolve" };
// If a wildcard is present store the information
- private transient boolean isPartialWild = false;
+ private transient boolean isPartialWild;
- private transient boolean isWild = false;
+ private transient boolean isWild;
// The highest port number
private static final int HIGHEST_PORT = 65535;
@@ -92,7 +92,7 @@
transient String ipString; // IP address as returned by InetAddress
- transient boolean resolved = false; // IP address has been resolved
+ transient boolean resolved; // IP address has been resolved
// the port range;
transient int portMin = LOWEST_PORT;
@@ -120,10 +120,12 @@
public SocketPermission(String host, String action) {
super(host.equals("") ? "localhost" : host);
hostName = getHostString(host);
- if (action == null)
- throw new NullPointerException();
- if (action.equals(""))
- throw new IllegalArgumentException();
+ if (action == null) {
+ throw new NullPointerException();
+ }
+ if (action.equals("")) {
+ throw new IllegalArgumentException();
+ }
setActions(action);
actions = toCanonicalActionString(action);
@@ -142,20 +144,26 @@
* <code>false</code> if it is different from this object
* @see #hashCode
*/
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (this.getClass() != o.getClass())
- return false;
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (this.getClass() != o.getClass()) {
+ return false;
+ }
SocketPermission sp = (SocketPermission) o;
if (!hostName.equals(sp.hostName)) {
- if (getIPString() == null || !ipString.equals(sp.getIPString()))
- return false;
- }
- if (this.portMin != sp.portMin)
- return false;
- if (this.portMax != sp.portMax)
- return false;
+ if (getIPString() == null || !ipString.equals(sp.getIPString())) {
+ return false;
+ }
+ }
+ if (this.portMin != sp.portMin) {
+ return false;
+ }
+ if (this.portMax != sp.portMax) {
+ return false;
+ }
return this.actionsMask == sp.actionsMask;
}
@@ -168,7 +176,8 @@
*
* @see #equals
*/
- public int hashCode() {
+ @Override
+ public int hashCode() {
return hostName.hashCode() ^ actionsMask ^ portMin ^ portMax;
}
@@ -178,7 +187,8 @@
*
* @return java.lang.String the canonical action list
*/
- public String getActions() {
+ @Override
+ public String getActions() {
return actions;
}
@@ -189,8 +199,9 @@
* java.lang.String the action list
*/
private void setActions(String actions) throws IllegalArgumentException {
- if (actions.equals(""))
- return;
+ if (actions.equals("")) {
+ return;
+ }
boolean parsing = true;
String action;
StringBuffer sb = new StringBuffer();
@@ -198,21 +209,23 @@
while (parsing) {
char c;
sb.setLength(0);
- while (pos < length && (c = actions.charAt(pos++)) != ',')
- sb.append(c);
- if (pos == length)
- parsing = false;
+ while (pos < length && (c = actions.charAt(pos++)) != ',') {
+ sb.append(c);
+ }
+ if (pos == length) {
+ parsing = false;
+ }
action = sb.toString().trim().toLowerCase();
- if (action.equals(actionNames[SP_CONNECT]))
- actionsMask |= SP_CONNECT;
- else if (action.equals(actionNames[SP_LISTEN]))
- actionsMask |= SP_LISTEN;
- else if (action.equals(actionNames[SP_ACCEPT]))
- actionsMask |= SP_ACCEPT;
- else if (action.equals(actionNames[SP_RESOLVE])) {
- } else
- throw new IllegalArgumentException(Msg.getString("K0048",
- action));
+ if (action.equals(actionNames[SP_CONNECT])) {
+ actionsMask |= SP_CONNECT;
+ } else if (action.equals(actionNames[SP_LISTEN])) {
+ actionsMask |= SP_LISTEN;
+ } else if (action.equals(actionNames[SP_ACCEPT])) {
+ actionsMask |= SP_ACCEPT;
+ } else if (action.equals(actionNames[SP_RESOLVE])) {
+ } else {
+ throw new IllegalArgumentException(Msg.getString("K0048", action));
+ }
}
}
@@ -228,7 +241,8 @@
* @param p
* java.security.Permission the other socket permission
*/
- public boolean implies(Permission p) {
+ @Override
+ public boolean implies(Permission p) {
SocketPermission sp;
try {
sp = (SocketPermission) p;
@@ -238,14 +252,17 @@
// tests if the action list of p is the subset of the one of the
// receiver
- if (sp == null || (actionsMask & sp.actionsMask) != sp.actionsMask)
- return false;
+ if (sp == null || (actionsMask & sp.actionsMask) != sp.actionsMask) {
+ return false;
+ }
// only check the port range if the action string of the current object
// is not "resolve"
- if (!p.getActions().equals("resolve"))
- if ((sp.portMin < this.portMin) || (sp.portMax > this.portMax))
- return false;
+ if (!p.getActions().equals("resolve")) {
+ if ((sp.portMin < this.portMin) || (sp.portMax > this.portMax)) {
+ return false;
+ }
+ }
// Verify the host is valid
return checkHost(sp);
@@ -256,7 +273,8 @@
*
* @return java.security.PermissionCollection a permission collection
*/
- public PermissionCollection newPermissionCollection() {
+ @Override
+ public PermissionCollection newPermissionCollection() {
return new SocketPermissionCollection();
}
@@ -308,8 +326,9 @@
}
}
}
- if (portMax < portMin)
- throw new IllegalArgumentException(Msg.getString("K0049"));
+ if (portMax < portMin) {
+ throw new IllegalArgumentException(Msg.getString("K0049"));
+ }
} catch (NumberFormatException e) {
throw new IllegalArgumentException(Msg.getString("K004a"));
@@ -326,8 +345,9 @@
* @return java.lang.String
*/
private String toCanonicalActionString(String action) {
- if (action == null || action.equals("") || actionsMask == SP_RESOLVE)
- return actionNames[SP_RESOLVE]; // If none specified return the
+ if (action == null || action.equals("") || actionsMask == SP_RESOLVE) {
+ return actionNames[SP_RESOLVE]; // If none specified return the
+ }
// implied action resolve
StringBuffer sb = new StringBuffer();
if ((actionsMask & SP_CONNECT) == SP_CONNECT) {
@@ -400,8 +420,9 @@
*/
boolean checkHost(SocketPermission sp) {
if (isPartialWild) {
- if (isWild)
- return true; // Match on any host
+ if (isWild) {
+ return true; // Match on any host
+ }
int length = hostName.length() - 1;
return sp.hostName.regionMatches(sp.hostName.length() - length,
hostName, 1, length);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SocketPermissionCollection.java Tue Aug 29 21:10:37 2006
@@ -37,7 +37,8 @@
}
// Adds the argument to the collection.
- public void add(Permission permission) {
+ @Override
+ public void add(Permission permission) {
if (isReadOnly()) {
throw new IllegalStateException();
}
@@ -48,7 +49,8 @@
}
// Answers an enumeration of the permissions
- public Enumeration<Permission> elements() {
+ @Override
+ public Enumeration<Permission> elements() {
return permissions.elements();
}
@@ -56,7 +58,8 @@
* Basically it tests
* if <code>permission</code> is the subset of this collection.
* */
- public boolean implies(Permission permission) {
+ @Override
+ public boolean implies(Permission permission) {
if (!(permission instanceof SocketPermission)) {
return false;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java?rev=438345&r1=438344&r2=438345&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URI.java Tue Aug 29 21:10:37 2006
@@ -42,25 +42,25 @@
static final String allLegal = unreserved + reserved;
- private String string = null;
+ private String string;
- private transient String scheme = null;
+ private transient String scheme;
- private transient String schemespecificpart = null;
+ private transient String schemespecificpart;
- private transient String authority = null;
+ private transient String authority;
- private transient String userinfo = null;
+ private transient String userinfo;
- private transient String host = null;
+ private transient String host;
private transient int port = -1;
- private transient String path = null;
+ private transient String path;
- private transient String query = null;
+ private transient String query;
- private transient String fragment = null;
+ private transient String fragment;
private transient boolean opaque;
@@ -102,8 +102,9 @@
throws URISyntaxException {
if (scheme == null && userinfo == null && host == null &&
- path == null && query == null && fragment == null)
- return;
+ path == null && query == null && fragment == null) {
+ return;
+ }
if (scheme != null && path != null && path.length() > 0
&& path.charAt(0) != '/') {
@@ -116,8 +117,9 @@
uri.append(':');
}
- if (userinfo != null || host != null || port != -1)
- uri.append("//");
+ if (userinfo != null || host != null || port != -1) {
+ uri.append("//");
+ }
if (userinfo != null) {
// QUOTE ILLEGAL CHARACTERS in userinfo
@@ -129,8 +131,9 @@
// check for ipv6 addresses that hasn't been enclosed
// in square brackets
if (host.indexOf(':') != -1 && host.indexOf(']') == -1
- && host.indexOf('[') == -1)
- host = "[" + host + "]";
+ && host.indexOf('[') == -1) {
+ host = "[" + host + "]";
+ }
uri.append(host);
}
@@ -280,19 +283,22 @@
// never be null)
}
- if (authority.length() == 0)
- authority = null;
- else
- validateAuthority(uri, authority, index1 + 3);
+ if (authority.length() == 0) {
+ authority = null;
+ } else {
+ validateAuthority(uri, authority, index1 + 3);
+ }
} else { // no authority specified
path = temp;
}
int pathIndex = 0;
- if (index2 > -1)
- pathIndex += index2;
- if (index > -1)
- pathIndex += index;
+ if (index2 > -1) {
+ pathIndex += index2;
+ }
+ if (index > -1) {
+ pathIndex += index;
+ }
validatePath(uri, path, pathIndex);
} else { // if not hierarchical, URI is opaque
opaque = true;
@@ -383,8 +389,9 @@
*/
private void parseAuthority(boolean forceServer)
throws URISyntaxException {
- if (authority == null)
- return;
+ if (authority == null) {
+ return;
+ }
String temp, tempUserinfo = null, tempHost = null;
int index, hostindex = 0;
@@ -409,29 +416,34 @@
try {
tempPort = Integer.parseInt(temp.substring(index + 1));
if (tempPort < 0) {
- if (forceServer)
- throw new URISyntaxException(authority, Msg
+ if (forceServer) {
+ throw new URISyntaxException(authority, Msg
.getString("K00b1"), hostindex + index + 1);
+ }
return;
}
} catch (NumberFormatException e) {
- if (forceServer)
- throw new URISyntaxException(authority, Msg
+ if (forceServer) {
+ throw new URISyntaxException(authority, Msg
.getString("K00b1"), hostindex + index + 1);
+ }
return;
}
- } else
- tempHost = temp;
+ } else {
+ tempHost = temp;
+ }
if (tempHost.equals("")) {
- if (forceServer)
- throw new URISyntaxException(authority, Msg
+ if (forceServer) {
+ throw new URISyntaxException(authority, Msg
.getString("K030c"), hostindex);
+ }
return;
}
- if (!isValidHost(forceServer, tempHost))
- return;
+ if (!isValidHost(forceServer, tempHost)) {
+ return;
+ }
// this is a server based uri,
// fill in the userinfo, host and port fields
@@ -462,15 +474,12 @@
if (host.charAt(0) == '[') {
// ipv6 address
if (host.charAt(host.length() - 1) != ']') {
- throw new URISyntaxException(host, Msg.getString("K030e"),
- 0);
- } else {
- if (!isValidIP6Address(host)) {
- throw new URISyntaxException(host, Msg
- .getString("K030f"));
- } else
- return true;
- }
+ throw new URISyntaxException(host, Msg.getString("K030e"), 0);
+ }
+ if (!isValidIP6Address(host)) {
+ throw new URISyntaxException(host, Msg.getString("K030f"));
+ }
+ return true;
}
// '[' and ']' can only be the first char and last char
@@ -483,25 +492,23 @@
if (index < 0 || index == host.length() - 1
|| !Character.isDigit(host.charAt(index + 1))) {
// domain name
- if (isValidDomainName(host))
- return true;
- else {
- if (forceServer)
- throw new URISyntaxException(host, Msg
- .getString("K0310"), 0);
- return false;
- }
- }
+ if (isValidDomainName(host)) {
+ return true;
+ }
+ if (forceServer) {
+ throw new URISyntaxException(host, Msg.getString("K0310"), 0);
+ }
+ return false;
+ }
// IPv4 address
- if (isValidIPv4Address(host))
- return true;
- else {
- if (forceServer)
- throw new URISyntaxException(host, Msg.getString("K0311"),
- 0);
- return false;
- }
+ if (isValidIPv4Address(host)) {
+ return true;
+ }
+ if (forceServer) {
+ throw new URISyntaxException(host, Msg.getString("K0311"), 0);
+ }
+ return false;
}
private boolean isValidDomainName(String host) {
@@ -515,14 +522,16 @@
StringTokenizer st = new StringTokenizer(host, ".");
while (st.hasMoreTokens()) {
label = st.nextToken();
- if (label.startsWith("-") || label.endsWith("-"))
- return false;
+ if (label.startsWith("-") || label.endsWith("-")) {
+ return false;
+ }
}
if (!label.equals(host)) {
char ch = label.charAt(0);
- if (ch >= '0' && ch <= '9')
- return false;
+ if (ch >= '0' && ch <= '9') {
+ return false;
+ }
}
return true;
}
@@ -534,19 +543,23 @@
int num;
index = host.indexOf('.');
num = Integer.parseInt(host.substring(0, index));
- if (num < 0 || num > 255)
- return false;
+ if (num < 0 || num > 255) {
+ return false;
+ }
index2 = host.indexOf('.', index + 1);
num = Integer.parseInt(host.substring(index + 1, index2));
- if (num < 0 || num > 255)
- return false;
+ if (num < 0 || num > 255) {
+ return false;
+ }
index = host.indexOf('.', index2 + 1);
num = Integer.parseInt(host.substring(index2 + 1, index));
- if (num < 0 || num > 255)
- return false;
+ if (num < 0 || num > 255) {
+ return false;
+ }
num = Integer.parseInt(host.substring(index + 1));
- if (num < 0 || num > 255)
- return false;
+ if (num < 0 || num > 255) {
+ return false;
+ }
} catch (Exception e) {
return false;
}
@@ -563,8 +576,9 @@
char prevChar = 0;
int offset = 0; // offset for [] ip addresses
- if (length < 2)
- return false;
+ if (length < 2) {
+ return false;
+ }
for (int i = 0; i < length; i++) {
prevChar = c;
@@ -573,69 +587,84 @@
// case for an open bracket [x:x:x:...x]
case '[':
- if (i != 0)
- return false; // must be first character
- if (ipAddress.charAt(length - 1) != ']')
- return false; // must have a close ]
+ if (i != 0) {
+ return false; // must be first character
+ }
+ if (ipAddress.charAt(length - 1) != ']') {
+ return false; // must have a close ]
+ }
offset = 1;
- if (length < 4)
- return false;
+ if (length < 4) {
+ return false;
+ }
break;
// case for a closed bracket at end of IP [x:x:x:...x]
case ']':
- if (i != length - 1)
- return false; // must be last charcter
- if (ipAddress.charAt(0) != '[')
- return false; // must have a open [
+ if (i != length - 1) {
+ return false; // must be last charcter
+ }
+ if (ipAddress.charAt(0) != '[') {
+ return false; // must have a open [
+ }
break;
// case for the last 32-bits represented as IPv4
// x:x:x:x:x:x:d.d.d.d
case '.':
numberOfPeriods++;
- if (numberOfPeriods > 3)
- return false;
- if (!isValidIP4Word(word))
- return false;
- if (numberOfColons != 6 && !doubleColon)
- return false;
+ if (numberOfPeriods > 3) {
+ return false;
+ }
+ if (!isValidIP4Word(word)) {
+ return false;
+ }
+ if (numberOfColons != 6 && !doubleColon) {
+ return false;
+ }
// a special case ::1:2:3:4:5:d.d.d.d allows 7 colons with
// an IPv4 ending, otherwise 7 :'s is bad
if (numberOfColons == 7
&& ipAddress.charAt(0 + offset) != ':'
- && ipAddress.charAt(1 + offset) != ':')
- return false;
+ && ipAddress.charAt(1 + offset) != ':') {
+ return false;
+ }
word = "";
break;
case ':':
numberOfColons++;
- if (numberOfColons > 7)
- return false;
- if (numberOfPeriods > 0)
- return false;
+ if (numberOfColons > 7) {
+ return false;
+ }
+ if (numberOfPeriods > 0) {
+ return false;
+ }
if (prevChar == ':') {
- if (doubleColon)
- return false;
+ if (doubleColon) {
+ return false;
+ }
doubleColon = true;
}
word = "";
break;
default:
- if (word.length() > 3)
- return false;
- if (!isValidHexChar(c))
- return false;
+ if (word.length() > 3) {
+ return false;
+ }
+ if (!isValidHexChar(c)) {
+ return false;
+ }
word += c;
}
}
// Check if we have an IPv4 ending
if (numberOfPeriods > 0) {
- if (numberOfPeriods != 3 || !isValidIP4Word(word))
- return false;
+ if (numberOfPeriods != 3 || !isValidIP4Word(word)) {
+ return false;
+ }
} else {
// If we're at then end and we haven't had 7 colons then there
// is a problem
@@ -658,15 +687,18 @@
private boolean isValidIP4Word(String word) {
char c;
- if (word.length() < 1 || word.length() > 3)
- return false;
+ if (word.length() < 1 || word.length() > 3) {
+ return false;
+ }
for (int i = 0; i < word.length(); i++) {
c = word.charAt(i);
- if (!(c >= '0' && c <= '9'))
- return false;
- }
- if (Integer.parseInt(word) > 255)
- return false;
+ if (!(c >= '0' && c <= '9')) {
+ return false;
+ }
+ }
+ if (Integer.parseInt(word) > 255) {
+ return false;
+ }
return true;
}
@@ -703,92 +735,101 @@
int ret = 0;
// compare schemes
- if (scheme == null && uri.scheme != null)
- return -1;
- else if (scheme != null && uri.scheme == null)
- return 1;
- else if (scheme != null && uri.scheme != null) {
+ if (scheme == null && uri.scheme != null) {
+ return -1;
+ } else if (scheme != null && uri.scheme == null) {
+ return 1;
+ } else if (scheme != null && uri.scheme != null) {
ret = scheme.compareToIgnoreCase(uri.scheme);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
}
// compare opacities
- if (!opaque && uri.opaque)
- return -1;
- else if (opaque && !uri.opaque)
- return 1;
- else if (opaque && uri.opaque) {
+ if (!opaque && uri.opaque) {
+ return -1;
+ } else if (opaque && !uri.opaque) {
+ return 1;
+ } else if (opaque && uri.opaque) {
ret = schemespecificpart.compareTo(uri.schemespecificpart);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
} else {
// otherwise both must be hierarchical
// compare authorities
- if (authority != null && uri.authority == null)
- return 1;
- else if (authority == null && uri.authority != null)
- return -1;
- else if (authority != null && uri.authority != null) {
+ if (authority != null && uri.authority == null) {
+ return 1;
+ } else if (authority == null && uri.authority != null) {
+ return -1;
+ } else if (authority != null && uri.authority != null) {
if (host != null && uri.host != null) {
// both are server based, so compare userinfo, host, port
- if (userinfo != null && uri.userinfo == null)
- return 1;
- else if (userinfo == null && uri.userinfo != null)
- return -1;
- else if (userinfo != null && uri.userinfo != null) {
+ if (userinfo != null && uri.userinfo == null) {
+ return 1;
+ } else if (userinfo == null && uri.userinfo != null) {
+ return -1;
+ } else if (userinfo != null && uri.userinfo != null) {
ret = userinfo.compareTo(uri.userinfo);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
}
// userinfo's are the same, compare hostname
ret = host.compareToIgnoreCase(uri.host);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
// compare port
- if (port != uri.port)
- return port - uri.port;
+ if (port != uri.port) {
+ return port - uri.port;
+ }
} else { // one or both are registry based, compare the whole
// authority
ret = authority.compareTo(uri.authority);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
}
}
// authorities are the same
// compare paths
ret = path.compareTo(uri.path);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
// compare queries
- if (query != null && uri.query == null)
- return 1;
- else if (query == null && uri.query != null)
- return -1;
- else if (query != null && uri.query != null) {
+ if (query != null && uri.query == null) {
+ return 1;
+ } else if (query == null && uri.query != null) {
+ return -1;
+ } else if (query != null && uri.query != null) {
ret = query.compareTo(uri.query);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
}
}
// everything else is identical, so compare fragments
- if (fragment != null && uri.fragment == null)
- return 1;
- else if (fragment == null && uri.fragment != null)
- return -1;
- else if (fragment != null && uri.fragment != null) {
+ if (fragment != null && uri.fragment == null) {
+ return 1;
+ } else if (fragment == null && uri.fragment != null) {
+ return -1;
+ } else if (fragment != null && uri.fragment != null) {
ret = fragment.compareTo(uri.fragment);
- if (ret != 0)
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
}
// identical
@@ -826,8 +867,9 @@
// takes a string that may contain hex sequences like %F1 or %2b
// and converts the hex values following the '%' to lowercase
StringBuffer result = new StringBuffer("");
- if (s.indexOf('%') == -1)
- return s;
+ if (s.indexOf('%') == -1) {
+ return s;
+ }
int index = 0, previndex = 0;
while ((index = s.indexOf('%', previndex)) != -1) {
@@ -844,21 +886,24 @@
// and compares them, ignoring case for the hex values
// hex values must always occur in pairs like above
- if (first.indexOf('%') != second.indexOf('%'))
- return first.equals(second);
+ if (first.indexOf('%') != second.indexOf('%')) {
+ return first.equals(second);
+ }
int index = 0, previndex = 0;
while ((index = first.indexOf('%', previndex)) != -1
&& second.indexOf('%', previndex) == index) {
boolean match = first.substring(previndex, index).equals(
second.substring(previndex, index));
- if (!match)
- return false;
+ if (!match) {
+ return false;
+ }
match = first.substring(index + 1, index + 3).equalsIgnoreCase(
second.substring(index + 1, index + 3));
- if (!match)
- return false;
+ if (!match) {
+ return false;
+ }
index += 3;
previndex = index;
@@ -866,71 +911,85 @@
return first.substring(previndex).equals(second.substring(previndex));
}
- public boolean equals(Object o) {
- if (!(o instanceof URI))
- return false;
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof URI)) {
+ return false;
+ }
URI uri = (URI) o;
if (uri.fragment == null && fragment != null || uri.fragment != null
- && fragment == null)
- return false;
- else if (uri.fragment != null && fragment != null)
- if (!equalsHexCaseInsensitive(uri.fragment, fragment))
- return false;
+ && fragment == null) {
+ return false;
+ } else if (uri.fragment != null && fragment != null) {
+ if (!equalsHexCaseInsensitive(uri.fragment, fragment)) {
+ return false;
+ }
+ }
if (uri.scheme == null && scheme != null || uri.scheme != null
- && scheme == null)
- return false;
- else if (uri.scheme != null && scheme != null)
- if (!uri.scheme.equalsIgnoreCase(scheme))
- return false;
+ && scheme == null) {
+ return false;
+ } else if (uri.scheme != null && scheme != null) {
+ if (!uri.scheme.equalsIgnoreCase(scheme)) {
+ return false;
+ }
+ }
if (uri.opaque && opaque) {
return equalsHexCaseInsensitive(uri.schemespecificpart,
schemespecificpart);
} else if (!uri.opaque && !opaque) {
- if (!equalsHexCaseInsensitive(path, uri.path))
- return false;
+ if (!equalsHexCaseInsensitive(path, uri.path)) {
+ return false;
+ }
if (uri.query != null && query == null || uri.query == null
- && query != null)
- return false;
- else if (uri.query != null && query != null)
- if (!equalsHexCaseInsensitive(uri.query, query))
- return false;
+ && query != null) {
+ return false;
+ } else if (uri.query != null && query != null) {
+ if (!equalsHexCaseInsensitive(uri.query, query)) {
+ return false;
+ }
+ }
if (uri.authority != null && authority == null
- || uri.authority == null && authority != null)
- return false;
- else if (uri.authority != null && authority != null) {
+ || uri.authority == null && authority != null) {
+ return false;
+ } else if (uri.authority != null && authority != null) {
if (uri.host != null && host == null || uri.host == null
- && host != null)
- return false;
- else if (uri.host == null && host == null) {
+ && host != null) {
+ return false;
+ } else if (uri.host == null && host == null) {
// both are registry based, so compare the whole authority
return equalsHexCaseInsensitive(uri.authority, authority);
} else { // uri.host != null && host != null, so server-based
- if (!host.equalsIgnoreCase(uri.host))
- return false;
-
- if (port != uri.port)
- return false;
+ if (!host.equalsIgnoreCase(uri.host)) {
+ return false;
+ }
+
+ if (port != uri.port) {
+ return false;
+ }
if (uri.userinfo != null && userinfo == null
- || uri.userinfo == null && userinfo != null)
- return false;
- else if (uri.userinfo != null && userinfo != null)
- return equalsHexCaseInsensitive(userinfo, uri.userinfo);
- else
- return true;
+ || uri.userinfo == null && userinfo != null) {
+ return false;
+ } else if (uri.userinfo != null && userinfo != null) {
+ return equalsHexCaseInsensitive(userinfo, uri.userinfo);
+ } else {
+ return true;
+ }
}
- } else
- // no authority
+ } else {
+ // no authority
return true;
+ }
- } else
- // one is opaque, the other hierarchical
+ } else {
+ // one is opaque, the other hierarchical
return false;
+ }
}
@@ -1064,9 +1123,11 @@
return decode(userinfo);
}
- public int hashCode() {
- if (hash == -1)
- hash = getHashString().hashCode();
+ @Override
+ public int hashCode() {
+ if (hash == -1) {
+ hash = getHashString().hashCode();
+ }
return hash;
}
@@ -1114,11 +1175,14 @@
index = -1;
// count the number of '/'s, to determine number of segments
int size = 0;
- if (pathlen > 0 && path.charAt(0) != '/')
- size++;
- while ((index = path.indexOf('/', index + 1)) != -1)
- if (index + 1 < pathlen && path.charAt(index + 1) != '/')
- size++;
+ if (pathlen > 0 && path.charAt(0) != '/') {
+ size++;
+ }
+ while ((index = path.indexOf('/', index + 1)) != -1) {
+ if (index + 1 < pathlen && path.charAt(index + 1) != '/') {
+ size++;
+ }
+ }
String[] seglist = new String[size];
boolean[] include = new boolean[size];
@@ -1133,8 +1197,9 @@
// if current==size, then the last character was a slash
// and there are no more segments
- if (current < size)
- seglist[current] = path.substring(index);
+ if (current < size) {
+ seglist[current] = path.substring(index);
+ }
// determine which segments get included in the normalized path
for (int i = 0; i < size; i++) {
@@ -1151,28 +1216,32 @@
include[remove] = false;
include[i] = false;
}
- } else if (seglist[i].equals(".")) // remove the "." segment
- include[i] = false;
+ } else if (seglist[i].equals(".")) {
+ include[i] = false;
+ }
}
// put the path back together
newpath = new StringBuffer();
- if (path.startsWith("/"))
- newpath.append('/');
+ if (path.startsWith("/")) {
+ newpath.append('/');
+ }
- for (int i = 0; i < seglist.length; i++)
- if (include[i]) {
+ for (int i = 0; i < seglist.length; i++) {
+ if (include[i]) {
newpath.append(seglist[i]);
newpath.append('/');
}
+ }
// if we used at least one segment
// and the path previously ended with a slash
// and the last segment is still used, then
// delete the extra trailing '/'
if (!path.endsWith("/") && seglist.length > 0
- && include[seglist.length - 1])
- newpath.deleteCharAt(newpath.length() - 1);
+ && include[seglist.length - 1]) {
+ newpath.deleteCharAt(newpath.length() - 1);
+ }
String result = newpath.toString();
@@ -1188,22 +1257,20 @@
}
public URI normalize() {
- if (opaque)
- return this;
- else {
- String normalizedPath = normalize(path);
- // if the path is already normalized, return this
- if (path.equals(normalizedPath))
- return this;
- else {
- URI result = duplicate(); // get an exact copy of the URI
- // re-calculate the scheme specific part since
- // the path of the normalized URI is different from this URI.
- result.path = normalizedPath;
- result.setSchemeSpecificPart();
- return result;
- }
- }
+ if (opaque) {
+ return this;
+ }
+ String normalizedPath = normalize(path);
+ // if the path is already normalized, return this
+ if (path.equals(normalizedPath)) {
+ return this;
+ }
+ URI result = duplicate(); // get an exact copy of the URI
+ // re-calculate the scheme specific part since
+ // the path of the normalized URI is different from this URI.
+ result.path = normalizedPath;
+ result.setSchemeSpecificPart();
+ return result;
}
/**
@@ -1212,38 +1279,44 @@
* produce a URISyntaxException with the proper diagnostic message.
*/
public URI parseServerAuthority() throws URISyntaxException {
- if (!serverAuthority)
- new Helper().parseAuthority(true);
+ if (!serverAuthority) {
+ new Helper().parseAuthority(true);
+ }
return this;
}
public URI relativize(URI relative) {
- if (relative.opaque || opaque)
- return relative;
+ if (relative.opaque || opaque) {
+ return relative;
+ }
if (scheme == null ? relative.scheme != null : !scheme
- .equals(relative.scheme))
- return relative;
+ .equals(relative.scheme)) {
+ return relative;
+ }
if (authority == null ? relative.authority != null : !authority
- .equals(relative.authority))
- return relative;
+ .equals(relative.authority)) {
+ return relative;
+ }
// append a slash to the end if necessary
// (for a case like: "dir1" against "dir1/hi" should return "hi", not
// "/hi")
String tempPath = null;
- if (path.endsWith("/"))
- tempPath = path;
- else
- tempPath = path + "/";
+ if (path.endsWith("/")) {
+ tempPath = path;
+ } else {
+ tempPath = path + "/";
+ }
// normalize both paths
String normrel = normalize(relative.path);
tempPath = normalize(tempPath);
- if (!normrel.startsWith(tempPath))
- return relative;
+ if (!normrel.startsWith(tempPath)) {
+ return relative;
+ }
URI result = new URI();
result.fragment = relative.fragment;
@@ -1254,8 +1327,9 @@
}
public URI resolve(URI relative) {
- if (relative.absolute || opaque)
- return relative;
+ if (relative.absolute || opaque) {
+ return relative;
+ }
URI result;
if (relative.path.equals("") && relative.scheme == null
@@ -1308,12 +1382,15 @@
private void setSchemeSpecificPart() {
// ssp = [//authority][path][?query]
StringBuffer ssp = new StringBuffer();
- if (authority != null)
- ssp.append("//" + authority);
- if (path != null)
- ssp.append(path);
- if (query != null)
- ssp.append("?" + query);
+ if (authority != null) {
+ ssp.append("//" + authority);
+ }
+ if (path != null) {
+ ssp.append(path);
+ }
+ if (query != null) {
+ ssp.append("?" + query);
+ }
schemespecificpart = ssp.toString();
// reset string, so that it can be re-calculated correctly when asked.
string = null;
@@ -1348,8 +1425,9 @@
}
private String decode(String s) {
- if (s == null)
- return s;
+ if (s == null) {
+ return s;
+ }
try {
return URIEncoderDecoder.decode(s);
@@ -1362,23 +1440,25 @@
return encodeOthers(toString());
}
- public String toString() {
+ @Override
+ public String toString() {
if (string == null) {
StringBuffer result = new StringBuffer();
if (scheme != null) {
result.append(scheme);
result.append(':');
}
- if (opaque)
- result.append(schemespecificpart);
- else {
+ if (opaque) {
+ result.append(schemespecificpart);
+ } else {
if (authority != null) {
result.append("//");
result.append(authority);
}
- if (path != null)
- result.append(path);
+ if (path != null) {
+ result.append(path);
+ }
if (query != null) {
result.append('?');
@@ -1407,24 +1487,27 @@
result.append(scheme.toLowerCase());
result.append(':');
}
- if (opaque)
- result.append(schemespecificpart);
- else {
+ if (opaque) {
+ result.append(schemespecificpart);
+ } else {
if (authority != null) {
result.append("//");
- if (host == null)
- result.append(authority);
- else {
- if (userinfo != null)
- result.append(userinfo + "@");
+ if (host == null) {
+ result.append(authority);
+ } else {
+ if (userinfo != null) {
+ result.append(userinfo + "@");
+ }
result.append(host.toLowerCase());
- if (port != -1)
- result.append(":" + port);
+ if (port != -1) {
+ result.append(":" + port);
+ }
}
}
- if (path != null)
- result.append(path);
+ if (path != null) {
+ result.append(path);
+ }
if (query != null) {
result.append('?');