/[classpath]/classpath/gnu/java/net/protocol/jar/Connection.java
ViewVC logotype

Diff of /classpath/gnu/java/net/protocol/jar/Connection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by mark, Thu Nov 17 10:58:47 2005 UTC revision 1.12 by mark, Thu Nov 17 18:00:59 2005 UTC
# Line 47  import java.net.MalformedURLException; Line 47  import java.net.MalformedURLException;
47  import java.net.ProtocolException;  import java.net.ProtocolException;
48  import java.net.URL;  import java.net.URL;
49  import java.net.URLConnection;  import java.net.URLConnection;
50    import java.text.SimpleDateFormat;
51    import java.util.Date;
52  import java.util.Hashtable;  import java.util.Hashtable;
53    import java.util.Locale;
54  import java.util.jar.JarEntry;  import java.util.jar.JarEntry;
55  import java.util.jar.JarFile;  import java.util.jar.JarFile;
56  import java.util.zip.ZipFile;  import java.util.zip.ZipFile;
# Line 60  import java.util.zip.ZipFile; Line 63  import java.util.zip.ZipFile;
63   */   */
64  public final class Connection extends JarURLConnection  public final class Connection extends JarURLConnection
65  {  {
66      /**
67       * HTTP-style DateFormat, used to format the last-modified header.
68       * Lazy initialized since jar files are used during bootstrapping.
69       */
70      private static SimpleDateFormat dateFormat;
71    
72    private JarFile jar_file;    private JarFile jar_file;
73    private JarEntry jar_entry;    private JarEntry jar_entry;
74    private URL jar_url;    private URL jar_url;
# Line 167  public final class Connection extends Ja Line 176  public final class Connection extends Ja
176      return jar_file;      return jar_file;
177    }    }
178    
179      public String getHeaderField(String field)
180      {
181        try
182          {
183            if (!connected)
184              connect();
185    
186            if (field.equals("content-type"))
187              return guessContentTypeFromName(getJarEntry().getName());
188            else if (field.equals("content-length"))
189              return Long.toString(getJarEntry().getSize());
190            else if (field.equals("last-modified"))
191              {
192                // Both creating and manipulating dateFormat need synchronization.
193                synchronized (this.getClass())
194                  {
195                    if (dateFormat == null)
196                      dateFormat = new SimpleDateFormat
197                        ("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
198                         new Locale ("En", "Us", "Unix"));
199    
200                    return dateFormat.format(new Date(getJarEntry().getTime()));
201                  }
202              }
203          }
204        catch (IOException e)
205          {
206            // Fall through.
207          }
208        return null;
209      }
210    
211    public int getContentLength()    public int getContentLength()
212    {    {
213      if (!connected)      if (!connected)
# Line 174  public final class Connection extends Ja Line 215  public final class Connection extends Ja
215    
216      return (int) jar_entry.getSize();      return (int) jar_entry.getSize();
217    }    }
218    
219      public long getLastModified()
220      {
221        if (!connected)
222          return -1;
223    
224        try
225          {
226            return getJarEntry().getTime();
227          }
228        catch (IOException e)
229          {
230            return -1;
231          }
232      }
233  }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26