classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: gnu.java.net.protocol.jar Connection patch from libgcj


From: Mark Wielaard
Subject: [cp-patches] FYI: gnu.java.net.protocol.jar Connection patch from libgcj
Date: Thu, 17 Nov 2005 19:00:35 +0100

Hi,

This imports a small change from libgcj. It brings us a little closer to
merging these classes. But not that much because we actually need a
slightly different implementation that initializes the DateFormat lazily
because of bootstrap concerns (DateFormat uses regex, regex uses
ResourceBundles, ResourceBundles uses jar connections, ...).

2004-11-17  Bryce McKinlay  <address@hidden>

       * gnu/java/net/protocol/jar/Connection.java (getHeaderField):
       Implemented.
       (getLastModified): Implemented.

Committed,

Mark
Index: gnu/java/net/protocol/jar/Connection.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/net/protocol/jar/Connection.java,v
retrieving revision 1.11
diff -u -r1.11 Connection.java
--- gnu/java/net/protocol/jar/Connection.java   17 Nov 2005 10:58:47 -0000      
1.11
+++ gnu/java/net/protocol/jar/Connection.java   17 Nov 2005 17:55:43 -0000
@@ -47,7 +47,10 @@
 import java.net.ProtocolException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Hashtable;
+import java.util.Locale;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.zip.ZipFile;
@@ -60,6 +63,12 @@
  */
 public final class Connection extends JarURLConnection
 {
+  /**
+   * HTTP-style DateFormat, used to format the last-modified header.
+   * Lazy initialized since jar files are used during bootstrapping.
+   */
+  private static SimpleDateFormat dateFormat;
+
   private JarFile jar_file;
   private JarEntry jar_entry;
   private URL jar_url;
@@ -167,11 +176,58 @@
     return jar_file;
   }
 
+  public String getHeaderField(String field)
+  {
+    try
+      {
+       if (!connected)
+         connect();
+
+       if (field.equals("content-type"))
+          return guessContentTypeFromName(getJarEntry().getName());
+       else if (field.equals("content-length"))
+          return Long.toString(getJarEntry().getSize());
+       else if (field.equals("last-modified"))
+         {
+           // Both creating and manipulating dateFormat need synchronization.
+           synchronized (this.getClass())
+             {
+               if (dateFormat == null)
+                 dateFormat = new SimpleDateFormat
+                   ("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
+                    new Locale ("En", "Us", "Unix"));
+
+               return dateFormat.format(new Date(getJarEntry().getTime()));
+             }
+         }
+      }
+    catch (IOException e)
+      {
+        // Fall through.
+      }
+    return null;
+  }
+
   public int getContentLength()
   {
     if (!connected)
       return -1;
 
     return (int) jar_entry.getSize();
+  }
+
+  public long getLastModified()
+  {
+    if (!connected)
+      return -1;
+
+    try
+      {
+       return getJarEntry().getTime();
+      }
+    catch (IOException e)
+      {
+       return -1;
+      }
   }
 }

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]