harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r415058 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java: net/Socket.java net/SocketPermissionCollection.java net/URL.java net/URLClassLoader.java net/URLConnection.java util/Arrays.java
Date Sat, 17 Jun 2006 20:32:31 GMT
Author: ndbeyer
Date: Sat Jun 17 13:32:31 2006
New Revision: 415058

URL: http://svn.apache.org/viewvc?rev=415058&view=rev
Log:
Code cleanup; generification, etc

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.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/URL.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.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/util/Arrays.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java?rev=415058&r1=415057&r2=415058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/Socket.java
Sat Jun 17 13:32:31 2006
@@ -324,8 +324,9 @@
 	 *         <code>null</code> return signifies no connection has been made.
 	 */
 	public InetAddress getInetAddress() {
-		if (!isConnected())
-			return null;
+		if (!isConnected()) {
+            return null;
+        }
 		return impl.getInetAddress();
 	}
 
@@ -342,8 +343,9 @@
 	 */
 	public InputStream getInputStream() throws IOException {
 		checkClosedAndCreate(false);
-		if (isInputShutdown())
-			throw new SocketException(Msg.getString("K0321"));
+		if (isInputShutdown()) {
+            throw new SocketException(Msg.getString("K0321"));
+        }
 		return impl.getInputStream();
 	}
 
@@ -368,8 +370,9 @@
 	 * @return the local address that this socket has bound to
 	 */
 	public InetAddress getLocalAddress() {
-		if (!isBound())
-			return InetAddress.ANY;
+		if (!isBound()) {
+            return InetAddress.ANY;
+        }
 		return Platform.getNetworkSystem().getSocketLocalAddress(impl.fd, InetAddress
 				.preferIPv6Addresses());
 	}
@@ -380,8 +383,9 @@
 	 * @return the local port to which the socket is bound
 	 */
 	public int getLocalPort() {
-		if (!isBound())
-			return -1;
+		if (!isBound()) {
+            return -1;
+        }
 		return impl.getLocalPort();
 	}
 
@@ -409,8 +413,9 @@
 	 *         connection in place.
 	 */
 	public int getPort() {
-		if (!isConnected())
-			return 0;
+		if (!isConnected()) {
+            return 0;
+        }
 		return impl.getPort();
 	}
 
@@ -567,12 +572,14 @@
 	public static synchronized void setSocketImplFactory(SocketImplFactory fac)
 			throws IOException {
 		SecurityManager security = System.getSecurityManager();
-		if (security != null)
-			security.checkSetFactory();
-		if (factory == null)
-			factory = fac;
-		else
-			throw new SocketException(Msg.getString("K0044"));
+		if (security != null) {
+            security.checkSetFactory();
+        }
+		if (factory == null) {
+            factory = fac;
+        } else {
+            throw new SocketException(Msg.getString("K0044"));
+        }
 	}
 
 	/**
@@ -587,10 +594,11 @@
 	 */
 	public synchronized void setSendBufferSize(int size) throws SocketException {
 		checkClosedAndCreate(true);
-		if (size >= 1)
-			impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
-		else
-			throw new IllegalArgumentException(Msg.getString("K0035"));
+		if (size >= 1) {
+            impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
+        } else {
+            throw new IllegalArgumentException(Msg.getString("K0035"));
+        }
 	}
 
 	/**
@@ -606,10 +614,11 @@
 	public synchronized 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"));
+		if (size >= 1) {
+            impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
+        } else {
+            throw new IllegalArgumentException(Msg.getString("K0035"));
+        }
 	}
 
 	/**
@@ -629,8 +638,9 @@
 		if (!on || 0 <= timeout) {
 			int val = on ? (65535 < timeout ? 65535 : timeout) : -1;
 			impl.setOption(SocketOptions.SO_LINGER, new Integer(val));
-		} else
-			throw new IllegalArgumentException(Msg.getString("K0045"));
+		} else {
+            throw new IllegalArgumentException(Msg.getString("K0045"));
+        }
 	}
 
 	/**
@@ -646,10 +656,11 @@
 	 */
 	public synchronized void setSoTimeout(int timeout) throws SocketException {
 		checkClosedAndCreate(true);
-		if (timeout >= 0)
-			impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
-		else
-			throw new IllegalArgumentException(Msg.getString("K0036"));
+		if (timeout >= 0) {
+            impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
+        } else {
+            throw new IllegalArgumentException(Msg.getString("K0036"));
+        }
 	}
 
 	/**
@@ -687,8 +698,9 @@
 	void startupSocket(InetAddress dstAddress, int dstPort,
 			InetAddress localAddress, int localPort, boolean streaming)
 			throws IOException {
-		if (localPort < 0 || localPort > 65535)
-			throw new IllegalArgumentException(Msg.getString("K0046"));
+		if (localPort < 0 || localPort > 65535) {
+            throw new IllegalArgumentException(Msg.getString("K0046"));
+        }
 
 		InetAddress addr = localAddress == null ? InetAddress.ANY
 				: localAddress;
@@ -716,8 +728,9 @@
 	 * @return the description
 	 */
 	public String toString() {
-		if (!isConnected())
-			return "Socket[unconnected]"; //$NON-NLS-1$
+		if (!isConnected()) {
+            return "Socket[unconnected]"; //$NON-NLS-1$
+        }
 		return impl.toString();
 	}
 
@@ -757,21 +770,25 @@
 	 *             if the socket is closed
 	 */
 	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) {
-			if (!isConnected())
-				throw new SocketException(Msg.getString("K0320"));
+			if (!isConnected()) {
+                throw new SocketException(Msg.getString("K0320"));
 			// a connected socket must be created
+            }
             
             /* return directly to fix a possible bug, if !create, should return here*/ 
             return;
 		}
-		if (isCreated)
-			return;
+		if (isCreated) {
+            return;
+        }
 		synchronized (this) {
-			if (isCreated)
-				return;
+			if (isCreated) {
+                return;
+            }
 			try {
 				impl.create(true);
 			} catch (SocketException e) {
@@ -792,8 +809,9 @@
 	 * @return the local socket address
 	 */
 	public SocketAddress getLocalSocketAddress() {
-		if (!isBound())
-			return null;
+		if (!isBound()) {
+            return null;
+        }
 		return new InetSocketAddress(getLocalAddress(), getLocalPort());
 	}
 
@@ -804,8 +822,9 @@
 	 * @return the remote socket address
 	 */
 	public SocketAddress getRemoteSocketAddress() {
-		if (!isConnected())
-			return null;
+		if (!isConnected()) {
+            return null;
+        }
 		return new InetSocketAddress(getInetAddress(), getPort());
 	}
 
@@ -853,19 +872,22 @@
 	 */
 	public void bind(SocketAddress localAddr) 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();
 		}
 
@@ -918,21 +940,26 @@
 	public void connect(SocketAddress remoteAddr, int timeout)
 			throws IOException {
 		checkClosedAndCreate(true);
-		if (timeout < 0)
-			throw new IllegalArgumentException(Msg.getString("K0036"));
-		if (isConnected())
-			throw new SocketException(Msg.getString("K0079")); //$NON-NLS-1$
-		if (remoteAddr == null)
-			throw new IllegalArgumentException(Msg.getString("K0318"));
+		if (timeout < 0) {
+            throw new IllegalArgumentException(Msg.getString("K0036"));
+        }
+		if (isConnected()) {
+            throw new SocketException(Msg.getString("K0079")); //$NON-NLS-1$
+        }
+		if (remoteAddr == null) {
+            throw new IllegalArgumentException(Msg.getString("K0318"));
+        }
 
-		if (!(remoteAddr instanceof InetSocketAddress))
-			throw new IllegalArgumentException(Msg.getString(
+		if (!(remoteAddr instanceof InetSocketAddress)) {
+            throw new IllegalArgumentException(Msg.getString(
 					"K0316", remoteAddr.getClass())); //$NON-NLS-1$
+        }
 		InetSocketAddress inetAddr = (InetSocketAddress) remoteAddr;
 		InetAddress addr;
-		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$
+        }
 		int port = inetAddr.getPort();
 
 		checkDestination(addr, port);
@@ -1049,8 +1076,9 @@
 	 */
 	public void setTrafficClass(int value) throws SocketException {
 		checkClosedAndCreate(true);
-		if (value < 0 || value > 255)
-			throw new IllegalArgumentException();
+		if (value < 0 || value > 255) {
+            throw new IllegalArgumentException();
+        }
 		impl.setOption(SocketOptions.IP_TOS, new Integer(value));
 	}
 
@@ -1093,12 +1121,13 @@
 	}
 
 	static boolean preferIPv4Stack() {
-		String result = (String) AccessController.doPrivileged(new PriviAction(
-				"java.net.preferIPv4Stack"));
-		if ("true".equals(result))
-			return true;
-		return false;
-	}
+        String result = AccessController.doPrivileged(new PriviAction<String>(
+                "java.net.preferIPv4Stack"));
+        if ("true".equals(result)) {
+            return true;
+        }
+        return false;
+    }
 	
 	/**
 	 * if Socket is created by a SocketChannel, returns the related

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=415058&r1=415057&r2=415058&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
Sat Jun 17 13:32:31 2006
@@ -15,7 +15,6 @@
 
 package java.net;
 
-
 import java.security.Permission;
 import java.security.PermissionCollection;
 import java.util.Enumeration;
@@ -30,7 +29,7 @@
 	
 	private static final long serialVersionUID = 2787186408602843674L;
 
-	public Vector permissions = new Vector();
+	private Vector<Permission> permissions = new Vector<Permission>();
 
 	// Constructs a new instance of this class.
 	public SocketPermissionCollection() {
@@ -39,10 +38,12 @@
 
 	// Adds the argument to the collection.
 	public void add(Permission permission) {
-		if (isReadOnly())
-			throw new IllegalStateException();
-		if (!(permission instanceof SocketPermission))
-			throw new IllegalArgumentException(permission.toString());
+		if (isReadOnly()) {
+            throw new IllegalStateException();
+        }
+		if (!(permission instanceof SocketPermission)) {
+            throw new IllegalArgumentException(permission.toString());
+        }
 		permissions.addElement(permission);
 	}
 
@@ -56,8 +57,9 @@
 	 * if <code>permission</code> is the subset of this collection.
 	 * */
 	public boolean implies(Permission permission) {
-		if (!(permission instanceof SocketPermission))
-			return false;
+		if (!(permission instanceof SocketPermission)) {
+            return false;
+        }
 		SocketPermission sp, argPerm = (SocketPermission) permission;
 		int pmask = argPerm.actionsMask;
 		int allMask = 0;
@@ -65,17 +67,21 @@
 		while ((i < count) && ((allMask & pmask) != pmask)) {
 			sp = (SocketPermission) permissions.elementAt(i);
 			if (sp.checkHost(argPerm)) {
-				if ((sp.actionsMask & SocketPermission.SP_RESOLVE) == SocketPermission.SP_RESOLVE)
-					allMask |= SocketPermission.SP_RESOLVE;
+				if ((sp.actionsMask & SocketPermission.SP_RESOLVE) == SocketPermission.SP_RESOLVE)
{
+                    allMask |= SocketPermission.SP_RESOLVE;
+                }
 				// Only set flags if the port range and host can be implied
 				if ((argPerm.portMin >= sp.portMin)
 						&& (argPerm.portMax <= sp.portMax)) {
-					if ((sp.actionsMask & SocketPermission.SP_CONNECT) == SocketPermission.SP_CONNECT)
-						allMask |= SocketPermission.SP_CONNECT;
-					if ((sp.actionsMask & SocketPermission.SP_ACCEPT) == SocketPermission.SP_ACCEPT)
-						allMask |= SocketPermission.SP_ACCEPT;
-					if ((sp.actionsMask & SocketPermission.SP_LISTEN) == SocketPermission.SP_LISTEN)
-						allMask |= SocketPermission.SP_LISTEN;
+					if ((sp.actionsMask & SocketPermission.SP_CONNECT) == SocketPermission.SP_CONNECT)
{
+                        allMask |= SocketPermission.SP_CONNECT;
+                    }
+					if ((sp.actionsMask & SocketPermission.SP_ACCEPT) == SocketPermission.SP_ACCEPT)
{
+                        allMask |= SocketPermission.SP_ACCEPT;
+                    }
+					if ((sp.actionsMask & SocketPermission.SP_LISTEN) == SocketPermission.SP_LISTEN)
{
+                        allMask |= SocketPermission.SP_LISTEN;
+                    }
 				}
 			}
 			++i;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java?rev=415058&r1=415057&r2=415058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
Sat Jun 17 13:32:31 2006
@@ -131,11 +131,13 @@
 	 */
 	public static synchronized void setURLStreamHandlerFactory(
 			URLStreamHandlerFactory streamFactory) {
-		if (streamHandlerFactory != null)
-			throw new Error(Msg.getString("K004b")); //$NON-NLS-1$
+		if (streamHandlerFactory != null) {
+            throw new Error(Msg.getString("K004b")); //$NON-NLS-1$
+        }
 		SecurityManager sm = System.getSecurityManager();
-		if (sm != null)
-			sm.checkSetFactory();
+		if (sm != null) {
+            sm.checkSetFactory();
+        }
 		streamHandlers.clear();
 		streamHandlerFactory = streamFactory;
 	}
@@ -230,8 +232,9 @@
 			throws MalformedURLException {
 		if (handler != null) {
 			SecurityManager sm = System.getSecurityManager();
-			if (sm != null)
-				sm.checkPermission(specifyStreamHandlerPermission);
+			if (sm != null) {
+                sm.checkPermission(specifyStreamHandlerPermission);
+            }
 			strmHandler = handler;
 		}
 
@@ -241,7 +244,7 @@
 		spec = spec.trim();
 
 		// The spec includes a protocol if it includes a colon character
-		// before the first occurance of a slash character. Note that,
+		// before the first occurrence of a slash character. Note that,
 		// "protocol" is the field which holds this URLs protocol.
 		int index;
 		try {
@@ -256,9 +259,10 @@
 				if (protocol.indexOf('/') >= 0) {
 					protocol = null;
 					index = -1;
-				} else
-					// Ignore case in protocol names.
+				} else {
+                    // Ignore case in protocol names.
 					protocol = protocol.toLowerCase();
+                }
 			}
 		}
 
@@ -274,31 +278,35 @@
 							.getAuthority(), context.getUserInfo(), cPath,
 							context.getQuery(), null);
 				}
-				if (strmHandler == null)
-					strmHandler = context.strmHandler;
+				if (strmHandler == null) {
+                    strmHandler = context.strmHandler;
+                }
 			}
 		} else {
 			// If the spec did not include a protocol, then the context
 			// *must* be specified. Fill in the receiver's slots from the
 			// values in the context, but still allow them to be over-ridden
 			// by the values in the ("relative") spec.
-			if (context == null)
-				throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
+			if (context == null) {
+                throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
 						"K00d8", spec)); //$NON-NLS-1$
+            }
 			set(context.getProtocol(), context.getHost(), context.getPort(),
 					context.getAuthority(), context.getUserInfo(), context
 							.getPath(), context.getQuery(), null);
-			if (strmHandler == null)
-				strmHandler = context.strmHandler;
+			if (strmHandler == null) {
+                strmHandler = context.strmHandler;
+            }
 		}
 
 		// If the stream handler has not been determined, set it
 		// to the default for the specified protocol.
 		if (strmHandler == null) {
 			setupStreamHandler();
-			if (strmHandler == null)
-				throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
+			if (strmHandler == null) {
+                throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
 						"K00b3", protocol)); //$NON-NLS-1$
+            }
 		}
 
 		// Let the handler parse the URL. If the handler throws
@@ -315,9 +323,10 @@
 			throw new MalformedURLException(e.toString());
 		}
 
-		if (port < -1)
-			throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
+		if (port < -1) {
+            throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
 					"K0325", port)); //$NON-NLS-1$
+        }
 	}
 
 	/**
@@ -380,9 +389,10 @@
 	 */
 	public URL(String protocol, String host, int port, String file,
 			URLStreamHandler handler) throws MalformedURLException {
-		if (port < -1)
-			throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
+		if (port < -1) {
+            throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
 					"K0325", port)); //$NON-NLS-1$
+        }
 
 		if (host != null && host.indexOf(":") != -1 && host.charAt(0) != '[') {
//$NON-NLS-1$
 			host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
@@ -393,7 +403,7 @@
 		this.port = port;
 
 		// Set the fields from the arguments. Handle the case where the
-		// passed in "file" includes both a file and a ref part.
+		// passed in "file" includes both a file and a reference part.
 		int index = -1;
 		index = file.indexOf("#", file.lastIndexOf("/")); //$NON-NLS-1$ //$NON-NLS-2$
 		if (index >= 0) {
@@ -409,13 +419,15 @@
 		// receiver's protocol if the handler was null.
 		if (handler == null) {
 			setupStreamHandler();
-			if (strmHandler == null)
-				throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
+			if (strmHandler == null) {
+                throw new MalformedURLException(org.apache.harmony.luni.util.Msg.getString(
 						"K00b3", protocol)); //$NON-NLS-1$
+            }
 		} else {
 			SecurityManager sm = System.getSecurityManager();
-			if (sm != null)
-				sm.checkPermission(specifyStreamHandlerPermission);
+			if (sm != null) {
+                sm.checkPermission(specifyStreamHandlerPermission);
+            }
 			strmHandler = handler;
 		}
 	}
@@ -424,8 +436,9 @@
 		int index;
 		if (host != null && host.length() > 0) {
 			authority = host;
-			if (port != -1)
-				authority = authority + ":" + port; //$NON-NLS-1$
+			if (port != -1) {
+                authority = authority + ":" + port; //$NON-NLS-1$
+            }
 		}
 		if (fixHost) {
 			if (host != null && (index = host.lastIndexOf('@')) > -1) {
@@ -465,8 +478,9 @@
 	 */
 	protected void set(String protocol, String host, int port, String file,
 			String ref) {
-		if (this.protocol == null) // The protocol cannot be changed
-			this.protocol = protocol;
+		if (this.protocol == null) {
+            this.protocol = protocol;
+        }
 		this.host = host;
 		this.file = file;
 		this.port = port;
@@ -478,7 +492,7 @@
 	/**
 	 * Compares the argument to the receiver, and answers true if they represent
 	 * the same URL. Two URLs are equal if they have the same file, host, port,
-	 * protocol, and ref components.
+	 * protocol, and reference components.
 	 * 
 	 * @param o
 	 *            the object to compare with this URL.
@@ -488,12 +502,15 @@
 	 * @see #hashCode
 	 */
 	public boolean equals(Object o) {
-		if (o == null)
-			return false;
-		if (this == o)
-			return true;
-		if (this.getClass() != o.getClass())
-			return false;
+		if (o == null) {
+            return false;
+        }
+		if (this == o) {
+            return true;
+        }
+		if (this.getClass() != o.getClass()) {
+            return false;
+        }
 		return strmHandler.equals(this, (URL) o);
 	}
 
@@ -515,8 +532,9 @@
 	 * @return the hashcode for hashtable indexing
 	 */
 	public int hashCode() {
-		if (hashCode == 0)
-			hashCode = strmHandler.hashCode(this);
+		if (hashCode == 0) {
+            hashCode = strmHandler.hashCode(this);
+        }
 		return hashCode;
 	}
 
@@ -533,9 +551,10 @@
 	void setupStreamHandler() {
 		// Check for a cached (previously looked up) handler for
 		// the requested protocol.
-		strmHandler = (URLStreamHandler) streamHandlers.get(protocol);
-		if (strmHandler != null)
-			return;
+		strmHandler = streamHandlers.get(protocol);
+		if (strmHandler != null) {
+            return;
+        }
 
 		// If there is a stream handler factory, then attempt to
 		// use it to create the handler.
@@ -549,8 +568,8 @@
 
 		// Check if there is a list of packages which can provide handlers.
 		// If so, then walk this list looking for an applicable one.
-		String packageList = (String) AccessController
-				.doPrivileged(new PriviAction("java.protocol.handler.pkgs")); //$NON-NLS-1$
+		String packageList = AccessController
+				.doPrivileged(new PriviAction<String>("java.protocol.handler.pkgs")); //$NON-NLS-1$
 		if (packageList != null) {
 			StringTokenizer st = new StringTokenizer(packageList, "|"); //$NON-NLS-1$
 			while (st.hasMoreTokens()) {
@@ -583,7 +602,7 @@
 	 * @return The object of the resource pointed by this URL.
 	 * 
 	 * @throws IOException
-	 *             If an error occured obtaining the content.
+	 *             If an error occurred obtaining the content.
 	 */
 	public final Object getContent() throws IOException {
 		return openConnection().getContent();
@@ -598,7 +617,7 @@
 	 *         content does not match a specified content type.
 	 * 
 	 * @throws IOException
-	 *             If an error occured obtaining the content.
+	 *             If an error occurred obtaining the content.
 	 */
 	public final Object getContent(Class[] types) throws IOException {
 		return openConnection().getContent(types);
@@ -686,8 +705,9 @@
 	 * @see URLStreamHandler#toExternalForm(URL)
 	 */
 	public String toExternalForm() {
-		if (strmHandler == null)
-			return "unknown protocol(" + protocol + ")://" + host + file;
+		if (strmHandler == null) {
+            return "unknown protocol(" + protocol + ")://" + host + file;
+        }
 		return strmHandler.toExternalForm(this);
 	}
 
@@ -706,12 +726,13 @@
 			throws java.io.IOException {
 		try {
 			stream.defaultReadObject();
-			if (host != null && authority == null)
-				fixURL(true);
-			else if (authority != null) {
+			if (host != null && authority == null) {
+                fixURL(true);
+            } else if (authority != null) {
 				int index;
-				if ((index = authority.lastIndexOf('@')) > -1)
-					userInfo = authority.substring(0, index);
+				if ((index = authority.lastIndexOf('@')) > -1) {
+                    userInfo = authority.substring(0, index);
+                }
 				if (file != null && (index = file.indexOf('?')) > -1) {
 					query = file.substring(index + 1);
 					path = file.substring(0, index);
@@ -720,9 +741,10 @@
 				}
 			}
 			setupStreamHandler();
-			if (strmHandler == null)
-				throw new IOException(org.apache.harmony.luni.util.Msg.getString("K00b3", //$NON-NLS-1$
+			if (strmHandler == null) {
+                throw new IOException(org.apache.harmony.luni.util.Msg.getString("K00b3",
//$NON-NLS-1$
 						protocol));
+            }
 		} catch (ClassNotFoundException e) {
 			throw new java.io.IOException(e.toString());
 		}
@@ -746,8 +768,6 @@
 		s.defaultWriteObject();
 	}
 
-	// Slot accessors follow...
-
 	/**
 	 * Answers the file component of this URL.
 	 * 
@@ -859,10 +879,11 @@
 			String ref) {
 		String file = path;
 		if (query != null && !query.equals("")) { //$NON-NLS-1$
-			if (file != null)
-				file = file + "?" + query; //$NON-NLS-1$
-			else
-				file = "?" + query; //$NON-NLS-1$
+			if (file != null) {
+                file = file + "?" + query; //$NON-NLS-1$
+            } else {
+                file = "?" + query; //$NON-NLS-1$
+            }
 		}
 		set(protocol, host, port, file, ref);
 		this.authority = authority;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java?rev=415058&r1=415057&r2=415058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
Sat Jun 17 13:32:31 2006
@@ -57,16 +57,15 @@
 
     URL[] urls, orgUrls;
 
-    private IdentityHashMap<URL, JarFile> resCache = new IdentityHashMap<URL, JarFile>(
-            32);
+    private IdentityHashMap<URL, JarFile> resCache = new IdentityHashMap<URL, JarFile>(32);
 
     private URLStreamHandlerFactory factory;
 
     HashMap<URL, URL[]> extensions;
 
-    Hashtable[] indexes;
+    Hashtable<String, URL[]>[] indexes;
 
-    private AccessControlContext currentContext = null;
+    private AccessControlContext currentContext;
 
     static class SubURLClassLoader extends URLClassLoader {
         // The subclass that overwrites the loadClass() method
@@ -83,7 +82,7 @@
         /**
          * Overrides the loadClass() of <code>ClassLoader</code>. It calls
          * the security manager's <code>checkPackageAccess()</code> before
-         * attempting toload the class.
+         * attempting to load the class.
          * 
          * @return java.lang.Class the Class object.
          * @param className
@@ -178,7 +177,7 @@
         URL[] newPath = new URL[urlArray.length + 1];
         System.arraycopy(urlArray, 0, newPath, 0, urlArray.length);
         newPath[urlArray.length] = url;
-        Hashtable[] newIndexes = new Hashtable[indexes.length + 1];
+        Hashtable<String, URL[]>[] newIndexes = new Hashtable[indexes.length + 1];
         System.arraycopy(indexes, 0, newIndexes, 0, indexes.length);
         indexes = newIndexes;
         return newPath;
@@ -191,7 +190,7 @@
      *         resource.
      * @param name
      *            java.lang.String the name of the requested resource
-     * @exception java.io.IOException
+     * @throws IOException
      *                thrown if an IO Exception occurs while attempting to
      *                connect
      */
@@ -277,7 +276,7 @@
      *            element, if false a Class should be returned.
      */
     Object findInIndex(int i, String name, Vector<URL> resources, boolean url) {
-        Hashtable index = indexes[i];
+        Hashtable<String, URL[]> index = indexes[i];
         if (index != null) {
             int pos = name.lastIndexOf("/");
             // only keep the directory part of the resource
@@ -285,12 +284,12 @@
             String indexedName = (pos > 0) ? name.substring(0, pos) : name;
             URL[] jarURLs;
             if (resources != null) {
-                jarURLs = (URL[]) index.get(indexedName);
+                jarURLs = index.get(indexedName);
                 if (jarURLs != null) {
                     findResources(jarURLs, name, resources);
                 }
             } else if (url) {
-                jarURLs = (URL[]) index.get(indexedName);
+                jarURLs = index.get(indexedName);
                 if (jarURLs != null) {
                     return findResourceImpl(jarURLs, name);
                 }
@@ -300,17 +299,17 @@
                 int position;
                 if ((position = partialName.lastIndexOf('/')) != -1) {
                     String packageName = partialName.substring(0, position);
-                    jarURLs = (URL[]) index.get(packageName);
+                    jarURLs = index.get(packageName);
                 } else {
                     String className = partialName.substring(0, partialName
                             .length())
                             + ".class";
-                    jarURLs = (URL[]) index.get(className);
+                    jarURLs = index.get(className);
                 }
                 if (jarURLs != null) {
-                    Class c = findClassImpl(jarURLs, clsName);
+                    Class<?> c = findClassImpl(jarURLs, clsName);
                     // InvalidJarException is thrown when a mapping for a class
-                    // is not valid, ie we cant find the class by following the
+                    // is not valid, i.e. we can't find the class by following the
                     // mapping.
                     if (c == null) {
                         throw new InvalidJarIndexException();
@@ -604,9 +603,9 @@
      */
     protected Class<?> findClass(final String clsName)
             throws ClassNotFoundException {
-        Class cls = AccessController.doPrivileged(
-                new PrivilegedAction<Class>() {
-                    public Class run() {
+        Class<?> cls = AccessController.doPrivileged(
+                new PrivilegedAction<Class<?>>() {
+                    public Class<?> run() {
                         return findClassImpl(urls, clsName);
                     }
                 }, currentContext);
@@ -926,13 +925,13 @@
         return newURLs;
     }
 
-    /*
-     * @param in java.io.InputStream the stream to read lines from @return
-     * ArrayList a list of String lines
+    /**
+     * @param in InputStream the stream to read lines from 
+     * @return List a list of String lines
      */
-    private ArrayList readLines(InputStream in) throws IOException {
+    private List<String> readLines(InputStream in) throws IOException {
         byte[] buff = new byte[144];
-        ArrayList<String> lines = new ArrayList<String>();
+        List<String> lines = new ArrayList<String>();
         int pos = 0;
         int next;
         while ((next = in.read()) != -1) {
@@ -968,12 +967,12 @@
                 file, null);
     }
 
-    /*
-     * @param searchURLs java.net.URL[] the URLs to search in @param clsName
-     * java.lang.String the class name to be found @return Class the class found
-     * or null if not found
+    /**
+     * @param searchURLs java.net.URL[] the URLs to search in
+     * @param clsName java.lang.String the class name to be found
+     * @return Class the class found or null if not found
      */
-    Class findClassImpl(URL[] searchURLs, String clsName) {
+    Class<?> findClassImpl(URL[] searchURLs, String clsName) {
         boolean readAvailable = false;
         boolean findInExtensions = searchURLs == urls;
         final String name = new StringBuffer(clsName.replace('.', '/')).append(
@@ -1124,7 +1123,7 @@
                 if ((jf != null) && findInExtensions) {
                     if (indexes[i] != null) {
                         try {
-                            Class c = (Class) findInIndex(i, clsName, null,
+                            Class<?> c = (Class<?>) findInIndex(i, clsName, null,
                                     false);
                             if (c != null) {
                                 return c;
@@ -1133,7 +1132,7 @@
                             // Ignore misleading/wrong jar index
                         }
                     } else {
-                        Class c = (Class) findInExtensions(explore(
+                        Class<?> c = (Class<?>) findInExtensions(explore(
                                 searchURLs[i], i), clsName, i, null, false);
                         if (c != null) {
                             return c;
@@ -1151,9 +1150,9 @@
      * @param indexNumber
      *            int the index in extensions to consider
      * 
-     * @return URL[] the URLs of bundled extensions that have been found (ie the
+     * @return URL[] the URLs of bundled extensions that have been found (i.e. the
      *         URL of jar files in the class-path attribute), or null if none.
-     *         if an INDEX.LIST has been found, an zero-lengthed array is
+     *         if an INDEX.LIST has been found, an empty array is
      *         returned
      */
     URL[] explore(URL url, int indexNumber) {
@@ -1181,9 +1180,9 @@
                     Hashtable<String, URL[]> index = new Hashtable<String, URL[]>(
                             15);
                     InputStream indexIS = jf.getInputStream(ze);
-                    List lines = readLines(indexIS);
+                    List<String> lines = readLines(indexIS);
                     indexIS.close();
-                    ListIterator iterator = lines.listIterator();
+                    ListIterator<String> iterator = lines.listIterator();
                     // Ignore the 2 first lines (index version)
                     iterator.next();
                     iterator.next();
@@ -1200,10 +1199,10 @@
                             .getHost(), fileURL.getPort(), parentFile);
                     while (iterator.hasNext()) {
                         URL jar = new URL("jar:" + parentURL.toExternalForm()
-                                + "/" + (String) iterator.next() + "!/");
+                                + "/" + iterator.next() + "!/");
                         String resource = null;
                         while (iterator.hasNext()
-                                && !(resource = (String) iterator.next())
+                                && !(resource = iterator.next())
                                         .equals("")) {
                             if (index.containsKey(resource)) {
                                 URL[] jars = index.get(resource);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java?rev=415058&r1=415057&r2=415058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
Sat Jun 17 13:32:31 2006
@@ -43,8 +43,6 @@
 
 	private String contentType;
 
-	private static String defaultRequestProperty = ""; // initial default value
-
 	private static boolean defaultAllowUserInteraction = false;
 
 	private static boolean defaultUseCaches = true;
@@ -55,8 +53,6 @@
 
 	protected long ifModifiedSince;
 
-	private String requestProperty = defaultRequestProperty;
-
 	protected boolean useCaches = defaultUseCaches;
 
 	protected boolean connected = false;
@@ -130,7 +126,7 @@
 	 * @return a non-null object
 	 * 
 	 * @throws IOException
-	 *             if an IO error occured
+	 *             if an IO error occurred
 	 * 
 	 * @see ContentHandler
 	 * @see ContentHandlerFactory
@@ -139,14 +135,18 @@
 	 * 
 	 */
 	public Object getContent() throws java.io.IOException {
-		if (!connected)
-			connect();
+		if (!connected) {
+            connect();
+        }
 
-		if ((contentType = getContentType()) == null)
-			if ((contentType = guessContentTypeFromName(url.getFile())) == null)
-				contentType = guessContentTypeFromStream(getInputStream());
-		if (contentType != null)
-			return getContentHandler(contentType).getContent(this);
+		if ((contentType = getContentType()) == null) {
+            if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
+                contentType = guessContentTypeFromStream(getInputStream());
+            }
+        }
+		if (contentType != null) {
+            return getContentHandler(contentType).getContent(this);
+        }
 		return null;
 	}
 
@@ -163,17 +163,21 @@
 	 *         the content does not match a specified content type.
 	 * 
 	 * @throws IOException
-	 *             If an error occured obtaining the content.
+	 *             If an error occurred obtaining the content.
 	 */
 	public Object getContent(Class[] types) throws IOException {
-		if (!connected)
-			connect();
+		if (!connected) {
+            connect();
+        }
 
-		if ((contentType = getContentType()) == null)
-			if ((contentType = guessContentTypeFromName(url.getFile())) == null)
-				contentType = guessContentTypeFromStream(getInputStream());
-		if (contentType != null)
-			return getContentHandler(contentType).getContent(this, types);
+		if ((contentType = getContentType()) == null) {
+            if ((contentType = guessContentTypeFromName(url.getFile())) == null) {
+                contentType = guessContentTypeFromStream(getInputStream());
+            }
+        }
+		if (contentType != null) {
+            return getContentHandler(contentType).getContent(this, types);
+        }
 		return null;
 	}
 
@@ -203,28 +207,30 @@
 
 		// if there's a cached content handler, use it
 		Object cHandler = contentHandlers.get(type);
-		if (cHandler != null)
-			return (ContentHandler) cHandler;
+		if (cHandler != null) {
+            return (ContentHandler) cHandler;
+        }
 
 		if (contentHandlerFactory != null) {
 			cHandler = contentHandlerFactory.createContentHandler(type);
-			if (!(cHandler instanceof ContentHandler))
-				throw new UnknownServiceException();
+			if (!(cHandler instanceof ContentHandler)) {
+                throw new UnknownServiceException();
+            }
 			contentHandlers.put(type, cHandler);
 			return (ContentHandler) cHandler;
 		}
 
 		// search through the package list for the right class for the Content
 		// Type
-		String packageList = (String) AccessController
-				.doPrivileged(new PriviAction("java.content.handler.pkgs"));
+		String packageList = AccessController
+				.doPrivileged(new PriviAction<String>("java.content.handler.pkgs"));
 		if (packageList != null) {
 			final StringTokenizer st = new StringTokenizer(packageList, "|");
 			while (st.countTokens() > 0) {
 				try {
-					Class cl = Class.forName(st.nextToken() + "." + typeString,
+					Class<?> cl = Class.forName(st.nextToken() + "." + typeString,
 							true, ClassLoader.getSystemClassLoader());
-					cHandler = (ContentHandler) cl.newInstance();
+					cHandler = cl.newInstance();
 				} catch (Exception e) {
 				}
 			}
@@ -246,8 +252,9 @@
 			});
 		}
 		if (cHandler != null) {
-			if (!(cHandler instanceof ContentHandler))
-				throw new UnknownServiceException();
+			if (!(cHandler instanceof ContentHandler)) {
+                throw new UnknownServiceException();
+            }
 			contentHandlers.put(type, cHandler); // if we got the handler,
 			// cache it for next time
 			return (ContentHandler) cHandler;
@@ -422,7 +429,7 @@
 	 * @since 1.4
 	 */
 	public Map<String, List<String>> getHeaderFields() {
-		return Collections.EMPTY_MAP;
+		return Collections.emptyMap();
 	}
 
 	/**
@@ -435,7 +442,7 @@
 	 * @since 1.4
 	 */
 	public Map<String, List<String>> getRequestProperties() {
-		return Collections.EMPTY_MAP;
+		return Collections.emptyMap();
 	}
 
 	/**
@@ -494,8 +501,9 @@
 	 */
 	public long getHeaderFieldDate(String field, long defaultValue) {
 		String date = getHeaderField(field);
-		if (date == null)
-			return defaultValue;
+		if (date == null) {
+            return defaultValue;
+        }
 		return Util.parseDate(date);
 	}
 
@@ -583,8 +591,9 @@
 	 * @see #getExpiration
 	 */
 	public long getLastModified() {
-		if (lastModified != -1)
-			return lastModified;
+		if (lastModified != -1) {
+            return lastModified;
+        }
 		return lastModified = getHeaderFieldDate("Last-Modified", 0);
 	}
 
@@ -649,7 +658,7 @@
 	/**
 	 * Answers the <code>URL</code> of this connection
 	 * 
-	 * @return the url of this conneciton
+	 * @return the URL of this connection
 	 * 
 	 * @see URL
 	 * @see #URLConnection(URL)
@@ -669,7 +678,7 @@
 
 	/**
 	 * Determines the MIME type of the file specified by the
-	 * <code> string </code> url, using the filename extension. Any fragment
+	 * <code> string </code> URL, using the filename extension. Any fragment
 	 * identifier is removed before processing.
 	 * 
 	 * @param url
@@ -699,19 +708,24 @@
 	 */
 	public static String guessContentTypeFromStream(InputStream is)
 			throws IOException {
-		if (!is.markSupported())
-			return null;
+		if (!is.markSupported()) {
+            return null;
+        }
 		is.mark(4);
 		char[] chars = new char[4];
-		for (int i = 0; i < chars.length; i++)
-			chars[i] = (char) is.read();
+		for (int i = 0; i < chars.length; i++) {
+            chars[i] = (char) is.read();
+        }
 		is.reset();
-		if ((chars[0] == 'P') && (chars[1] == 'K'))
-			return "application/zip";
-		if ((chars[0] == 'G') && (chars[1] == 'I'))
-			return "image/gif";
-		if (new String(chars).trim().startsWith("<"))
-			return "text/html";
+		if ((chars[0] == 'P') && (chars[1] == 'K')) {
+            return "application/zip";
+        }
+		if ((chars[0] == 'G') && (chars[1] == 'I')) {
+            return "image/gif";
+        }
+		if (new String(chars).trim().startsWith("<")) {
+            return "text/html";
+        }
 		return null;
 	}
 
@@ -728,8 +742,9 @@
 		for (int i = 0; i < typeStringBuffer.length(); i++) {
 			// if non-alphanumeric, replace it with '_'
 			char c = typeStringBuffer.charAt(i);
-			if (!(Character.isLetter(c) || Character.isDigit(c) || c == '.'))
-				typeStringBuffer.setCharAt(i, '_');
+			if (!(Character.isLetter(c) || Character.isDigit(c) || c == '.')) {
+                typeStringBuffer.setCharAt(i, '_');
+            }
 		}
 		return typeStringBuffer.toString();
 	}
@@ -755,7 +770,7 @@
 	/**
 	 * Sets the current content handler factory to be
 	 * <code>contentFactory</code>. It can only do so with the permission of
-	 * the security manager. The ContentFactory can only be specified ince
+	 * the security manager. The ContentFactory can only be specified once
 	 * during the lifetime of an application.
 	 * 
 	 * @param contentFactory
@@ -772,11 +787,13 @@
 	 */
 	public static synchronized void setContentHandlerFactory(
 			ContentHandlerFactory contentFactory) {
-		if (contentHandlerFactory != null)
-			throw new Error(Msg.getString("K004e"));
+		if (contentHandlerFactory != null) {
+            throw new Error(Msg.getString("K004e"));
+        }
 		SecurityManager sManager = System.getSecurityManager();
-		if (sManager != null)
-			sManager.checkSetFactory();
+		if (sManager != null) {
+            sManager.checkSetFactory();
+        }
 		contentHandlerFactory = contentFactory;
 	}
 
@@ -806,7 +823,7 @@
 	}
 
 	/**
-	 * Set whether caches are used by deafult. Existing URLConnections are
+	 * Set whether caches are used by default. Existing URLConnections are
 	 * unaffected.
 	 * 
 	 * @param newValue
@@ -879,8 +896,9 @@
 	 */
 	public static void setFileNameMap(FileNameMap map) {
 		SecurityManager manager = System.getSecurityManager();
-		if (manager != null)
-			manager.checkSetFactory();
+		if (manager != null) {
+            manager.checkSetFactory();
+        }
 		fileNameMap = map;
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?rev=415058&r1=415057&r2=415058&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
Sat Jun 17 13:32:31 2006
@@ -978,7 +978,7 @@
     }
 
     private static int deepHashCodeElement(Object element) {
-        Class cl;
+        Class<?> cl;
         if (element == null) {
             return 0;
         }
@@ -1271,7 +1271,7 @@
     }
 
     private static boolean deepEqualsElements(Object e1, Object e2) {
-        Class cl1, cl2;
+        Class<?> cl1, cl2;
 
         if (e1 == e2) {
             return true;
@@ -2784,12 +2784,12 @@
                 sb.append("null");
             } else {
                 // get the Class of the current element
-                Class elemClass = elem.getClass();
+                Class<?> elemClass = elem.getClass();
                 if (elemClass.isArray()) {
                     // element is an array type
 
                     // get the declared Class of the array (element)
-                    Class elemElemClass = elemClass.getComponentType();
+                    Class<?> elemElemClass = elemClass.getComponentType();
                     if (elemElemClass.isPrimitive()) {
                         // element is a primitive array
                         if (boolean.class.equals(elemElemClass)) {



Mime
View raw message