OSDN Git Service

2005-07-13 Andrew Haley <aph@redhat.com>
authoraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jul 2005 18:20:10 +0000 (18:20 +0000)
committeraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jul 2005 18:20:10 +0000 (18:20 +0000)
        * gnu/java/net/protocol/file/Connection.java (unquote): New
        method.
        (connect): Unquote filename.
        gnu/java/net/protocol/jar/Connection.java (getInputStream):
        Likewise.
        (getJarFile): Likewise.

        * java/net/URLConnection.java (getContentHandler): Guard cast with
        instaceof.

        * java/net/URL.java (URL): If the file part of a spec is absolute,
        ignore the file part of its context.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102029 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/gnu/java/net/protocol/file/Connection.java
libjava/gnu/java/net/protocol/jar/Connection.java
libjava/java/net/URL.java
libjava/java/net/URLConnection.java

index f26d6ea..3f22405 100644 (file)
@@ -1,3 +1,18 @@
+2005-07-14  Andrew Haley  <aph@redhat.com>
+
+        * gnu/java/net/protocol/file/Connection.java (unquote): New
+        method.
+        (connect): Unquote filename.
+        gnu/java/net/protocol/jar/Connection.java (getInputStream):
+        Likewise.  
+        (getJarFile): Likewise.
+
+        * java/net/URLConnection.java (getContentHandler): Guard cast with
+        instaceof.
+
+        * java/net/URL.java (URL): If the file part of a spec is absolute,
+        ignore the file part of its context.
+
 2005-07-14  Aaron Luchko  <aluchko@redhat.com>
 
        * gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java:
index 52bd048..8e4a413 100644 (file)
@@ -59,6 +59,7 @@ import java.security.Permission;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
+import java.net.MalformedURLException;
 
 /**
  * This subclass of java.net.URLConnection models a URLConnection via
@@ -125,6 +126,54 @@ public class Connection extends URLConnection
   }
   
   /**
+   * Unquote "%" + hex quotes characters
+   *
+   * @param str The string to unquote or null.
+   *
+   * @return The unquoted string or null if str was null.
+   *
+   * @exception MalformedURLException If the given string contains invalid
+   * escape sequences.
+   *
+   * Sadly the same as URI.unquote, but there's nothing we can do to
+   * make it accessible.
+   *
+   */
+  public static String unquote(String str) throws MalformedURLException
+  {
+    if (str == null)
+      return null;
+    byte[] buf = new byte[str.length()];
+    int pos = 0;
+    for (int i = 0; i < str.length(); i++)
+      {
+       char c = str.charAt(i);
+       if (c > 127)
+         throw new MalformedURLException(str + " : Invalid character");
+       if (c == '%')
+         {
+           if (i + 2 >= str.length())
+             throw new MalformedURLException(str + " : Invalid quoted character");
+           int hi = Character.digit(str.charAt(++i), 16);
+           int lo = Character.digit(str.charAt(++i), 16);
+           if (lo < 0 || hi < 0)
+             throw new MalformedURLException(str + " : Invalid quoted character");
+           buf[pos++] = (byte) (hi * 16 + lo);
+         }
+       else
+         buf[pos++] = (byte) c;
+      }
+    try
+      {
+       return new String(buf, 0, pos, "utf-8");
+      }
+    catch (java.io.UnsupportedEncodingException x2)
+      {
+       throw (Error) new InternalError().initCause(x2);
+      }
+  }
+
+  /**
    * "Connects" to the file by opening it.
    */
   public void connect() throws IOException
@@ -134,7 +183,7 @@ public class Connection extends URLConnection
       return;
     
     // If not connected, then file needs to be openned.
-    file = new File (getURL().getFile());
+    file = new File (unquote(getURL().getFile()));
 
     if (! file.isDirectory())
       {
index 8ec35cc..34df183 100644 (file)
@@ -151,7 +151,8 @@ public final class Connection extends JarURLConnection
     if (jarfile != null)
       {
        // this is the easy way...
-       ZipEntry entry = jarfile.getEntry(getEntryName());
+       ZipEntry entry = jarfile.getEntry
+         (gnu.java.net.protocol.file.Connection.unquote(getEntryName()));
         
        if (entry != null)
          return jarfile.getInputStream (entry);
@@ -164,12 +165,14 @@ public final class Connection extends JarURLConnection
        JarInputStream zis = new JarInputStream(
                        jarFileURLConnection.getInputStream ());
 
+       String entryName = gnu.java.net.protocol.file.Connection.unquote(getEntryName());
+
        // This is hideous, we're doing a linear search...
        for (ZipEntry entry = zis.getNextEntry(); 
             entry != null; 
             entry = zis.getNextEntry())
          {
-           if (getEntryName().equals(entry.getName()))
+           if (entryName.equals(entry.getName()))
              {
                int size = (int) entry.getSize();
                byte[] data = new byte[size];
@@ -203,12 +206,14 @@ public final class Connection extends JarURLConnection
            jar_file = (JarFile) file_cache.get (jarFileURL);
            if (jar_file == null)
              {
-               jar_file = new JarFile (jarFileURL.getFile());
+               jar_file = new JarFile 
+                 (gnu.java.net.protocol.file.Connection.unquote(jarFileURL.getFile()));
                file_cache.put (jarFileURL, jar_file);
              }
          }
        else
-         jar_file = new JarFile (jarFileURL.getFile());
+         jar_file = new JarFile 
+           (gnu.java.net.protocol.file.Connection.unquote(jarFileURL.getFile()));
       }
     else
       {
index a136556..0ae7c1c 100644 (file)
@@ -408,10 +408,7 @@ public final class URL implements Serializable
            // The 1.2 doc specifically says these are copied to the new URL.
            host = context.host;
            port = context.port;
-           file = context.file;
             userInfo = context.userInfo;
-           if (file == null || file.length() == 0)
-             file = "/";
            authority = context.authority;
          }
       }
@@ -423,10 +420,13 @@ public final class URL implements Serializable
        protocol = context.protocol;
        host = context.host;
        port = context.port;
-       file = context.file;
         userInfo = context.userInfo;
-       if (file == null || file.length() == 0)
-         file = "/";
+       if (spec.indexOf(":/", 1) < 0)
+         {
+           file = context.file;
+           if (file == null || file.length() == 0)
+             file = "/";
+         }
        authority = context.authority;
       }
     else // Protocol NOT specified in spec. and no context available.
index 5233a56..55b9d66 100644 (file)
@@ -983,17 +983,22 @@ public abstract class URLConnection
     if (contentType == null || contentType.equals(""))
       return null;
 
-    ContentHandler handler;
+    ContentHandler handler = null;
 
     // See if a handler has been cached for this content type.
     // For efficiency, if a content type has been searched for but not
     // found, it will be in the hash table but as the contentType String
     // instead of a ContentHandler.
-    if ((handler = (ContentHandler) handlers.get(contentType)) != null)
-      if (handler instanceof ContentHandler)
-       return handler;
-      else
-       return null;
+    {
+      Object cachedHandler;
+      if ((cachedHandler = handlers.get(contentType)) != null)
+       {
+         if (cachedHandler instanceof ContentHandler)
+           return (ContentHandler)cachedHandler;
+         else
+           return null;
+       }
+    }
 
     // If a non-default factory has been set, use it.
     if (factory != null)