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.*URLConnection


Hi list,


I commited the attached patch to make java.net.JarURLConnection and 
java.net.URLConnection more equal to classpath's version.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2261
diff -u -b -B -r1.2261 ChangeLog
--- ChangeLog	13 Oct 2003 05:03:38 -0000	1.2261
+++ ChangeLog	13 Oct 2003 05:28:15 -0000
@@ -1,5 +1,25 @@
 2003-10-13  Michael Koch  <konqueror@gmx.de>
 
+	* java/net/JarURLConnection.java
+	(jarFileURL): Added dcoumentation.
+	(jarFileURLConnection): Reformated documentation.
+	(entryName): Renamed from "element", documentation rewritten.
+	(connectionCache): Renamed from "conn_cache", documentation
+	reformated.
+	(JarURLConnection): Check URL protocol.
+	(getEntryName): Use entryName.
+	(connect): Use connectionCache.
+	(getInputStream): Use entryName, fixed comment.
+	(getJarEntry): Use entryName.
+	(getHeaders): Use entryName.
+	* java/net/URLConnection.java
+	(addRequestProperty): Fixed documentation.
+	(setDefaultRequestProptery): Added comment that it does nothing since
+	JDK 1.3.
+	(getDefaultRequestProperty): Likewise.
+
+2003-10-13  Michael Koch  <konqueror@gmx.de>
+
 	* java/net/java/net/URLStreamHandlerFactory.java
 	(createURLStreamHandler): Removed redundant "public" modifier.
 	* java/sql/DatabaseMetaData.java:
Index: java/net/JarURLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/JarURLConnection.java,v
retrieving revision 1.16
diff -u -b -B -r1.16 JarURLConnection.java
--- java/net/JarURLConnection.java	22 Sep 2003 05:48:32 -0000	1.16
+++ java/net/JarURLConnection.java	13 Oct 2003 05:28:16 -0000
@@ -1,5 +1,5 @@
 /* JarURLConnection.java -- Class for manipulating remote jar files
-   Copyright (C) 1998 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -50,6 +50,7 @@
 import java.util.zip.ZipEntry;
 import java.util.Map;
 import java.util.Vector;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.security.cert.Certificate;
 
@@ -80,19 +81,29 @@
  */
 public abstract class JarURLConnection extends URLConnection
 {
-  // three different ways to say the same thing
+  /**
+   * This is the actual URL that points the remote jar file.  This is parsed
+   * out of the jar URL by the constructor.
+   */
   private final URL jarFileURL;
 
-  /** The connection to the jar file itself. A JarURLConnection
+  /**
+   * The connection to the jar file itself. A JarURLConnection
    *  can represent an entry in a jar file or an entire jar file.  In
-   *  either case this describes just the jar file itself. */
+   * either case this describes just the jar file itself.
+   */
   protected URLConnection jarFileURLConnection;
 
-  // If this is a connection to a jar file element this is set, otherwise null.
-  private final String element;
+  /**
+   * This is the jar file "entry name" or portion after the "!/" in the
+   * URL which represents the pathname inside the actual jar file.
+   */
+  private final String entryName;
 
-  // Cached JarURLConnection's 
-  static Hashtable conn_cache = new Hashtable();
+  /**
+   * Cached JarURLConnection objects .
+   */
+  static HashMap connectionCache = new HashMap();
 
   /**
    * Creates a JarURLConnection from an URL object
@@ -108,6 +119,9 @@
   {
     super (url);
 
+    if (!url.getProtocol().equals ("jar"))
+      throw new MalformedURLException (url + ": Not jar protocol.");
+
     String spec = url.getFile();
     int bang = spec.indexOf ("!/");
     if (bang == -1)
@@ -116,8 +130,8 @@
     // Extract the url for the jar itself.
     jarFileURL = new URL (spec.substring (0, bang));
 
-    // Get the name of the element, if any.
-    element = (spec.length() == (bang + 2) ? null : spec.substring (bang + 2));
+    // Get the name of the entry, if any.
+    entryName = spec.length() == (bang + 2) ? null : spec.substring (bang + 2);
   }
 
   /**
@@ -140,7 +154,7 @@
    */
   public String getEntryName ()
   {
-    return element;
+    return entryName;
   }
 
   public synchronized void connect() throws IOException
@@ -151,14 +165,14 @@
 
     if (getUseCaches())
       {
-	jarFileURLConnection = (URLConnection) conn_cache.get (jarFileURL);
+	jarFileURLConnection = (URLConnection) connectionCache.get (jarFileURL);
 
 	if (jarFileURLConnection == null)
 	  {
 	    jarFileURLConnection = jarFileURL.openConnection ();
 	    jarFileURLConnection.setUseCaches (true);
 	    jarFileURLConnection.connect ();
-	    conn_cache.put (jarFileURL, jarFileURLConnection);
+	    connectionCache.put (jarFileURL, jarFileURLConnection);
 	  }
       }
     else
@@ -178,7 +192,7 @@
     if (! doInput)
       throw new ProtocolException("Can't open InputStream if doInput is false");
 
-    if (element == null)
+    if (entryName == null)
       {
 	// This is a JarURLConnection for the entire jar file.  
 
@@ -187,7 +201,7 @@
 	return new JarInputStream(jar_is);
       }
 
-    // Reaching this point, we're looking for an element of a jar file.
+    // Reaching this point, we're looking for an entry of a jar file.
 
     JarFile jarfile = null;
 
@@ -195,7 +209,7 @@
       {
 	jarfile = getJarFile ();
       }
-    catch (java.io.IOException x)
+    catch (IOException x)
       {
 	/* ignore */
       }
@@ -203,7 +217,8 @@
     if (jarfile != null)
       {
 	// this is the easy way...
-	ZipEntry entry = jarfile.getEntry(element);
+	ZipEntry entry = jarfile.getEntry (entryName);
+        
 	if (entry != null)
 	  return jarfile.getInputStream (entry);
 	else
@@ -220,7 +235,7 @@
 	     ent != null; 
 	     ent = zis.getNextEntry ())
 	  {
-	    if (element.equals (ent.getName ()))
+	    if (entryName.equals (ent.getName()))
 	      {
 		int size = (int)ent.getSize();
 		byte[] data = new byte[size];
@@ -244,7 +259,7 @@
   {
     JarFile jarfile = null;
 
-    if (element == null)
+    if (entryName == null)
       return null;
 
     if (! doInput)
@@ -269,7 +284,7 @@
 	     ent != null; 
 	     ent = zis.getNextEntry ())
 	  {
-	    if (element.equals (ent.getName ()))
+	    if (entryName.equals (ent.getName()))
 	      {
 		return new JarEntry (ent);
 	      }
@@ -278,7 +293,7 @@
 
     else
       {
-	return jarfile.getJarEntry (element);
+	return jarfile.getJarEntry (entryName);
       }
 
     return null;
@@ -398,7 +413,7 @@
     // Add the only header we know about right now:  Content-length.
     long len = -1;
 
-    if (element == null)
+    if (entryName == null)
       if (jarFileURLConnection != null)
 	len = jarFileURLConnection.getContentLength ();
     else
Index: java/net/URLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLConnection.java,v
retrieving revision 1.24
diff -u -b -B -r1.24 URLConnection.java
--- java/net/URLConnection.java	2 Oct 2003 15:17:13 -0000	1.24
+++ java/net/URLConnection.java	13 Oct 2003 05:28:16 -0000
@@ -726,7 +726,7 @@
 
   /**
    * Adds a new request property by a key/value pair.
-   * This method does not overwrite* existing properties with the same key.
+   * This method does not overwrite existing properties with the same key.
    *
    * @param key Key of the property to add
    * @param value Value of the Property to add
@@ -800,14 +800,14 @@
    * @param key The request property name the default is being set for
    * @param value The value to set the default to
    *
-   * @deprecated 1.3 The method setRequestProperty should be used instead
+   * @deprecated 1.3 The method setRequestProperty should be used instead.
+   * This method does nothing now.
    *
    * @see URLConnectionr#setRequestProperty(String key, String value)
    */
-  public static void setDefaultRequestProperty(String key, String value)
+  public static void setDefaultRequestProperty (String key, String value)
   {
-    // Do nothing unless overridden by subclasses that support setting
-    // default request properties.
+    // This method does nothing since JDK 1.3.
   }
 
   /**
@@ -819,13 +819,14 @@
    *
    * @return The value of the default property or null if not available
    * 
-   * @deprecated 1.3 The method getRequestProperty should be used instead
+   * @deprecated 1.3 The method getRequestProperty should be used instead.
+   * This method does nothing now.
    *
    * @see URLConnection#getRequestProperty(String key)
    */
   public static String getDefaultRequestProperty(String key)
   {
-    // Overridden by subclasses that support default request properties.
+    // This method does nothing since JDK 1.3.
     return null;
   }
 

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