This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.net cleanup


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I commited the attached patch to clean up java.net a bit more.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+8dK3WSOgCCdjSDsRAiU4AJ0a5fkD8Zk+7PRsbmkfiZEY1dF4ZACfTNyG
dkuVcWps45Fw4Xg2qm2CtCs=
=4jzY
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1966
diff -u -b -B -r1.1966 ChangeLog
--- ChangeLog	19 Jun 2003 14:46:19 -0000	1.1966
+++ ChangeLog	19 Jun 2003 15:06:17 -0000
@@ -1,5 +1,23 @@
 2003-06-19  Michael Koch  <konqueror@gmx.de>
 
+	* java/net/HttpURLConnection.java,
+	java/net/Inet4Address.java,
+	java/net/Inet6Address.java,
+	java/net/SocketImpl.java,
+	java/net/URLClassLoader.java:
+	Reworked import statements.
+	* java/net/InetAddress.java
+	(getByAddress): Simplified.
+	* java/net/ServerSocket.java
+	(ServerSocket): Moved special handling during bind operation to
+	bind().
+	(bind): Handle different cases when trying to bind a socket.
+	* java/net/URLConnection.java
+	(getHeaderFieldDate): Merged with classpath.
+	(getHeaderFieldInt): Likewise.
+
+2003-06-19  Michael Koch  <konqueror@gmx.de>
+
 	* java/util/zip/InflaterInputStream.java
 	(InflaterInputStream): Throw NullPointerException if in is null (as
 	JDK does).
Index: java/net/HttpURLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/HttpURLConnection.java,v
retrieving revision 1.11
diff -u -b -B -r1.11 HttpURLConnection.java
--- java/net/HttpURLConnection.java	2 Mar 2003 20:11:12 -0000	1.11
+++ java/net/HttpURLConnection.java	19 Jun 2003 15:06:19 -0000
@@ -1,7 +1,6 @@
-// HttpURLConnection.java - Subclass of communications links using
-//			Hypertext Transfer Protocol.
-
-/* Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation
+/* HttpURLConnection.java - Subclass of communications links using
+                            Hypertext Transfer Protocol.
+   Copyright (C) 1998, 1999, 2000, 2002, 2003  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -37,9 +36,12 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
-import java.io.*;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.PushbackInputStream;
 import java.security.Permission;
 
 /*
Index: java/net/Inet4Address.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/Inet4Address.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 Inet4Address.java
--- java/net/Inet4Address.java	19 Jun 2003 01:19:27 -0000	1.3
+++ java/net/Inet4Address.java	19 Jun 2003 15:06:19 -0000
@@ -35,9 +35,9 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
-import java.io.IOException;
 import java.io.ObjectStreamException;
 import java.util.Arrays;
 
Index: java/net/Inet6Address.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/Inet6Address.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 Inet6Address.java
--- java/net/Inet6Address.java	19 Jun 2003 01:19:27 -0000	1.3
+++ java/net/Inet6Address.java	19 Jun 2003 15:06:19 -0000
@@ -35,9 +35,9 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
-import java.io.IOException;
 import java.util.Arrays;
 
 /**
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/InetAddress.java,v
retrieving revision 1.16
diff -u -b -B -r1.16 InetAddress.java
--- java/net/InetAddress.java	18 Jun 2003 08:09:48 -0000	1.16
+++ java/net/InetAddress.java	19 Jun 2003 15:06:19 -0000
@@ -92,15 +92,15 @@
     // FIXME: implement this
   }
 	  
-  private void readObject(ObjectInputStream ois)
+  private void readObject (ObjectInputStream ois)
     throws IOException, ClassNotFoundException
   {
-    ois.defaultReadObject();
-    addr = new byte[4];
-    addr[3] = (byte) address;
+    ois.defaultReadObject ();
+    addr = new byte [4];
+    addr [3] = (byte) address;
     
     for (int i = 2; i >= 0; --i)
-      addr[i] = (byte) (address >>= 8);
+      addr [i] = (byte) (address >>= 8);
     
     // Ignore family from serialized data.  Since the saved address is 32 bits
     // the deserialized object will have an IPv4 address i.e. AF_INET family.
@@ -110,7 +110,7 @@
     family = getFamily (addr);
   }
 
-  private void writeObject(ObjectOutputStream oos) throws IOException
+  private void writeObject (ObjectOutputStream oos) throws IOException
   {
     // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
     // or a 16 byte IPv6 address.
@@ -118,9 +118,9 @@
     int i = len - 4;
     
     for (; i < len; i++)
-      address = address << 8 | (((int) addr[i]) & 0xFF);
+      address = address << 8 | (((int) addr [i]) & 0xFF);
     
-    oos.defaultWriteObject();
+    oos.defaultWriteObject ();
   }
 
   private static native int getFamily (byte[] address);
@@ -144,10 +144,10 @@
     int len = addr.length;
     
     if (len == 4)
-      return (addr[0] & 0xF0) == 0xE0;
+      return (addr [0] & 0xF0) == 0xE0;
     
     if (len == 16)
-      return addr[0] == (byte) 0xFF;
+      return addr [0] == (byte) 0xFF;
     
     return false;
   }
@@ -174,7 +174,7 @@
     // This is the IPv4 implementation.
     // Any class derived from InetAddress should override this.
     
-    return addr[0] == 0x7F;
+    return addr [0] == 0x7F;
   }
 
   /**
@@ -202,7 +202,7 @@
     // Any class derived from InetAddress should override this.
 
     // 10.0.0.0/8
-    if (addr[0] == 0x0A)
+    if (addr [0] == 0x0A)
       return true;
 
     // XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:
@@ -263,9 +263,9 @@
     if (!isMulticastAddress ())
       return false;
 
-    return (addr[0] == 0xE0
-	    && addr[1] == 0x00
-	    && addr[2] == 0x00);
+    return (addr [0] == 0xE0
+	    && addr [1] == 0x00
+	    && addr [2] == 0x00);
   }
 
   /**
@@ -340,26 +340,26 @@
   {
     // An experiment shows that JDK1.2 returns a different byte array each
     // time.  This makes sense, in terms of security.
-    return (byte[]) addr.clone();
+    return (byte[]) addr.clone ();
   }
 
   /* Helper function due to a CNI limitation.  */
   private static InetAddress[] allocArray (int count)
   {
-    return new InetAddress[count];
+    return new InetAddress [count];
   }
 
   /* Helper function due to a CNI limitation.  */
   private static SecurityException checkConnect (String hostname)
   {
-    SecurityManager s = System.getSecurityManager();
+    SecurityManager s = System.getSecurityManager ();
     
     if (s == null)
       return null;
     
     try
       {
-	s.checkConnect(hostname, -1);
+	s.checkConnect (hostname, -1);
 	return null;
       }
     catch (SecurityException ex)
@@ -375,7 +375,7 @@
    */
   public String getHostAddress ()
   {
-    StringBuffer sbuf = new StringBuffer(40);
+    StringBuffer sbuf = new StringBuffer (40);
     int len = addr.length;
     int i = 0;
     if (len == 16)
@@ -383,37 +383,37 @@
 	for (;  ;  i += 2)
 	  {
 	    if (i >= 16)
-	      return sbuf.toString();
-	    int x = ((addr[i] & 0xFF) << 8) | (addr[i+1] & 0xFF);
-	    boolean empty = sbuf.length() == 0;
+	      return sbuf.toString ();
+	    int x = ((addr [i] & 0xFF) << 8) | (addr [i + 1] & 0xFF);
+	    boolean empty = sbuf.length () == 0;
 	    if (empty)
 	      {
 		if (i == 10 && x == 0xFFFF)
 		  { // IPv4-mapped IPv6 address.
-		    sbuf.append(":FFFF:");
+		    sbuf.append (":FFFF:");
 		    break;  // Continue as IPv4 address;
 		  }
 		else if (i == 12)
 		  { // IPv4-compatible IPv6 address.
-		    sbuf.append(':');
+		    sbuf.append (':');
 		    break;  // Continue as IPv4 address.
 		  }
 		else if (i > 0)
-		  sbuf.append("::");
+		  sbuf.append ("::");
 	      }
 	    else
-	      sbuf.append(':');
+	      sbuf.append (':');
 	    if (x != 0 || i >= 14)
-	      sbuf.append(Integer.toHexString(x).toUpperCase());
+	      sbuf.append (Integer.toHexString (x).toUpperCase ());
 	  }
       }
     for ( ;  ; )
       {
-	sbuf.append(addr[i] & 0xFF);
+	sbuf.append (addr[i] & 0xFF);
 	i++;
 	if (i == len)
 	  break;
-	sbuf.append('.');
+	sbuf.append ('.');
       }
     
     return sbuf.toString();
@@ -422,7 +422,7 @@
   /**
    * Returns a hashcode of the InetAddress
    */
-  public int hashCode()
+  public int hashCode ()
   {
     // There hashing algorithm is not specified, but a simple experiment
     // shows that it is equal to the address, as a 32-bit big-endian integer.
@@ -467,10 +467,10 @@
   /**
    * Returns then <code>InetAddress</code> as string
    */
-  public String toString()
+  public String toString ()
   {
     String result;
-    String address = getHostAddress();
+    String address = getHostAddress ();
     
     if (hostName != null)
       result = hostName + "/" + address;
@@ -492,16 +492,10 @@
    *
    * @since 1.4
    */
-  public static InetAddress getByAddress(byte[] addr)
+  public static InetAddress getByAddress (byte[] addr)
     throws UnknownHostException
   {
-    if (addr.length != 4 && addr.length != 16)
-      throw new UnknownHostException ("IP address has illegal length");
-
-    if (addr.length == 4)
-      return new Inet4Address (addr, null);
-      
-    return new Inet6Address (addr, null);
+    return getByAddress (null, addr);
   }
 
   /**
@@ -553,7 +547,7 @@
    
     // Default to current host if necessary
     if (hostname == null)
-      return getLocalHost();
+      return getLocalHost ();
 
     // Assume that the host string is an IP address
     byte[] address = aton (hostname);
@@ -563,13 +557,13 @@
           return new Inet4Address (address, null);
         else if (address.length == 16)
           {
-	    if ((address[10] == 0xFF) && (address[11] == 0xFF))
+	    if ((address [10] == 0xFF) && (address [11] == 0xFF))
 	      {
-		byte[] ip4addr = new byte[4];
-		ip4addr[0] = address[12];
-		ip4addr[1] = address[13];
-		ip4addr[2] = address[14];
-		ip4addr[3] = address[15];
+		byte[] ip4addr = new byte [4];
+		ip4addr [0] = address [12];
+		ip4addr [1] = address [13];
+		ip4addr [2] = address [14];
+		ip4addr [3] = address [15];
 		return new Inet4Address (ip4addr, null);
 	      }
             return new Inet6Address (address, null);
@@ -580,7 +574,7 @@
    
     // Try to resolve the host by DNS
     InetAddress[] addresses = getAllByName (hostname);
-    return addresses[0];
+    return addresses [0];
   }
 
   /**
@@ -603,8 +597,8 @@
     byte[] address = aton (hostname);
     if (address != null)
       {
-	InetAddress[] result = new InetAddress[1];
-	result[0] = new InetAddress(address, null);
+	InetAddress[] result = new InetAddress [1];
+	result [0] = new InetAddress (address, null);
 	return result;
       }
    
@@ -612,10 +606,10 @@
     return lookup (hostname, null, true);
   }
 
-  static final byte[] zeros = {0,0,0,0};
+  static final byte[] zeros = { 0, 0, 0, 0 };
   
   /* dummy InetAddress, used to bind socket to any (all) network interfaces */
-  static final InetAddress ANY_IF = new InetAddress(zeros, null);
+  static final InetAddress ANY_IF = new InetAddress (zeros, null);
     
   private static final byte[] localhostAddress = { 127, 0, 0, 1 };
 
@@ -629,28 +623,28 @@
    * @exception UnknownHostException If no IP address for the host could
    * be found
    */
-  public static InetAddress getLocalHost() throws UnknownHostException
+  public static InetAddress getLocalHost () throws UnknownHostException
   {
-    SecurityManager s = System.getSecurityManager();
+    SecurityManager s = System.getSecurityManager ();
     
     // Experimentation shows that JDK1.2 does cache the result.
     // However, if there is a security manager, and the cached result
     // is other than "localhost", we need to check again.
     if (localhost == null
 	|| (s != null && localhost.addr != localhostAddress))
-      getLocalHost(s);
+      getLocalHost (s);
     
     return localhost;
   }
 
-  private static synchronized void getLocalHost(SecurityManager s)
+  private static synchronized void getLocalHost (SecurityManager s)
     throws UnknownHostException
   {
     // Check the localhost cache again, now that we've synchronized.
     if (s == null && localhost != null)
       return;
     
-    String hostname = getLocalHostname();
+    String hostname = getLocalHostname ();
     
     if (s != null)
       {
@@ -664,7 +658,7 @@
 	  {
 	    // This is wrong, if the name returned from getLocalHostname()
 	    // is not a fully qualified name.  FIXME.
-	    s.checkConnect(hostname, -1);
+	    s.checkConnect (hostname, -1);
 	  }
 	catch (SecurityException ex)
 	  {
@@ -676,8 +670,8 @@
       {
 	try
 	  {
-	    localhost = new InetAddress(null, null);
-	    lookup(hostname, localhost, false);
+	    localhost = new InetAddress (null, null);
+	    lookup (hostname, localhost, false);
 	  }
 	catch (Exception ex)
 	  {
Index: java/net/ServerSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/ServerSocket.java,v
retrieving revision 1.21
diff -u -b -B -r1.21 ServerSocket.java
--- java/net/ServerSocket.java	2 May 2003 09:27:58 -0000	1.21
+++ java/net/ServerSocket.java	19 Jun 2003 15:06:19 -0000
@@ -157,57 +157,11 @@
     if (impl == null)
       throw new IOException("Cannot initialize Socket implementation");
 
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkListen(port);
-
-    if (bindAddr == null)
-      bindAddr = InetAddress.ANY_IF;
-
     // create socket
     impl.create(true);
 
-    // bind to address/port
-    try
-      {
-        impl.bind(bindAddr, port);
-      }
-    catch (IOException exception)
-      {
-        impl.close();
-        throw exception;
-      }
-    catch (RuntimeException exception)
-      {
-        impl.close();
-        throw exception;
-      }
-    catch (Error error)
-      {
-        impl.close();
-        throw error;
-      }
-
-    // listen on socket
-    try
-      {
-        impl.listen(backlog);
-      }
-    catch (IOException exception)
-      {
-        impl.close();
-        throw exception;
-      }
-    catch (RuntimeException exception)
-      {
-        impl.close();
-        throw exception;
-      }
-    catch (Error error)
-      {
-        impl.close();
-        throw error;
-      }
+    // bind/listen socket
+    bind (new InetSocketAddress (bindAddr, port), backlog);
   }
 
   /**
@@ -258,8 +212,47 @@
     if (s != null)
       s.checkListen (tmp.getPort ());
 
+    // bind to address/port
+    try
+      {
     impl.bind (tmp.getAddress (), tmp.getPort ());
+      }
+    catch (IOException exception)
+      {
+        impl.close();
+        throw exception;
+      }
+    catch (RuntimeException exception)
+      {
+        impl.close();
+        throw exception;
+      }
+    catch (Error error)
+      {
+        impl.close();
+        throw error;
+      }
+
+    // listen on socket
+    try
+      {
     impl.listen(backlog);
+  }
+    catch (IOException exception)
+      {
+        impl.close();
+        throw exception;
+      }
+    catch (RuntimeException exception)
+      {
+        impl.close();
+        throw exception;
+      }
+    catch (Error error)
+      {
+        impl.close();
+        throw error;
+      }
   }
   
   /**
Index: java/net/SocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/SocketImpl.java,v
retrieving revision 1.14
diff -u -b -B -r1.14 SocketImpl.java
--- java/net/SocketImpl.java	8 Jun 2003 09:25:54 -0000	1.14
+++ java/net/SocketImpl.java	19 Jun 2003 15:06:19 -0000
@@ -1,5 +1,6 @@
 /* SocketImpl.java -- Abstract socket implementation class
-   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -35,9 +36,13 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.net;
 
-import java.io.*;
+import java.io.FileDescriptor;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
 
 /* Written using on-line Java Platform 1.2 API Specification.
  * Believed complete and correct.
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.13
diff -u -b -B -r1.13 URLClassLoader.java
--- java/net/URLClassLoader.java	2 Jan 2003 09:34:34 -0000	1.13
+++ java/net/URLClassLoader.java	19 Jun 2003 15:06:19 -0000
@@ -41,8 +42,6 @@
 import java.io.EOFException;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FilterInputStream;
 import java.io.FilePermission;
 import java.io.InputStream;
 import java.io.IOException;
@@ -60,7 +59,6 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
-import java.util.zip.ZipException;
 
 /**
  * A secure class loader that can load classes and resources from
Index: java/net/URLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLConnection.java,v
retrieving revision 1.21
diff -u -b -B -r1.21 URLConnection.java
--- java/net/URLConnection.java	18 Jun 2003 08:09:48 -0000	1.21
+++ java/net/URLConnection.java	19 Jun 2003 15:06:19 -0000
@@ -331,20 +331,19 @@
    */
   public int getHeaderFieldInt(String name, int defaultValue)
   {
-    String str = getHeaderField(name);
-    int result = defaultValue;
+    String value = getHeaderField (name);
+    
+    if (value == null)
+      return defaultValue;
     
     try
       {
-	if (str != null)
-	  result = Integer.parseInt (str);
+        return Integer.parseInt (value);
       }
     catch (NumberFormatException e) 
       { 
-	; // Do nothing; defaultValue is the default.
+        return defaultValue;
       }
-    
-    return result;
   }
 
   /**
@@ -353,27 +352,32 @@
    * value if the field is not present or cannot be converted to a date.
    *
    * @param name The name of the header field
-   * @param val The dafault date
+   * @param defaultValue The default date if the header field is not found
+   * or can't be converted.
    *
    * @return Returns the date value of the header filed or the default value
    * if the field is missing or malformed
    */
-  public long getHeaderFieldDate(String name, long val)
+  public long getHeaderFieldDate (String name, long defaultValue)
   {
     if (! dateformats_initialized)
-      initializeDateFormats();
-    String str = getHeaderField(name);
+      initializeDateFormats ();
+    
+    long result = defaultValue;
+    String str = getHeaderField (name);
+    
     if (str != null)
       {
         Date date;
-	if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
-	  val = date.getTime();
-	else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
-	  val = date.getTime();
-	else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
-	  val = date.getTime();
+	if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null)
+	  result = date.getTime ();
+	else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null)
+	  result = date.getTime ();
+	else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null)
+	  result = date.getTime ();
       }
-    return val;
+    
+    return result;
   }
 
   /**
@@ -387,7 +391,7 @@
    * @return The header field key or null if index is past the end
    * of the headers.
    */
-  public String getHeaderFieldKey(int index)
+  public String getHeaderFieldKey (int index)
   {
     // Subclasses for specific protocols override this.
     return null;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]