summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/java/net/protocol/jar
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/net/protocol/jar')
-rw-r--r--libjava/classpath/gnu/java/net/protocol/jar/Connection.java60
1 files changed, 59 insertions, 1 deletions
diff --git a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
index e854874208a..e2a052ef581 100644
--- a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
+++ b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java
@@ -47,7 +47,10 @@ import java.net.MalformedURLException;
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 @@ import java.util.zip.ZipFile;
*/
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;
@@ -82,7 +91,9 @@ public final class Connection extends JarURLConnection
if ("file".equals (url.getProtocol()))
{
- File f = new File (url.getFile());
+ String fn = url.getFile();
+ fn = gnu.java.net.protocol.file.Connection.unquote(fn);
+ File f = new File (fn);
jf = new JarFile (f, true, ZipFile.OPEN_READ);
}
else
@@ -165,6 +176,38 @@ public final class Connection extends JarURLConnection
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)
@@ -172,4 +215,19 @@ public final class Connection extends JarURLConnection
return (int) jar_entry.getSize();
}
+
+ public long getLastModified()
+ {
+ if (!connected)
+ return -1;
+
+ try
+ {
+ return getJarEntry().getTime();
+ }
+ catch (IOException e)
+ {
+ return -1;
+ }
+ }
}
OpenPOWER on IntegriCloud