summaryrefslogtreecommitdiffstats
path: root/libjava/gnu/java/net/protocol/file/Connection.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/gnu/java/net/protocol/file/Connection.java')
-rw-r--r--libjava/gnu/java/net/protocol/file/Connection.java66
1 files changed, 46 insertions, 20 deletions
diff --git a/libjava/gnu/java/net/protocol/file/Connection.java b/libjava/gnu/java/net/protocol/file/Connection.java
index 650d9f21853..4da6e882c00 100644
--- a/libjava/gnu/java/net/protocol/file/Connection.java
+++ b/libjava/gnu/java/net/protocol/file/Connection.java
@@ -50,6 +50,9 @@ import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
/**
* This subclass of java.net.URLConnection models a URLConnection via
@@ -62,9 +65,11 @@ import java.security.Permission;
public class Connection extends URLConnection
{
/**
- * Default permission for a file
+ * HTTP-style DateFormat, used to format the last-modified header.
*/
- private static final String DEFAULT_PERMISSION = "read";
+ private static SimpleDateFormat dateFormat
+ = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
+ new Locale ("En", "Us", "Unix"));
/**
* This is a File object for this connection
@@ -82,18 +87,11 @@ public class Connection extends URLConnection
private OutputStream outputStream;
/**
- * FilePermission to read the file
- */
- private FilePermission permission;
-
- /**
* Calls superclass constructor to initialize.
*/
public Connection(URL url)
{
super (url);
-
- permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
}
/**
@@ -156,45 +154,73 @@ public class Connection extends URLConnection
}
/**
- * Get the last modified time of the resource.
- *
- * @return the time since epoch that the resource was modified.
+ * Get an http-style header field. Just handle a few common ones.
*/
- public long getLastModified()
+ public String getHeaderField(String field)
{
try
{
if (!connected)
connect();
- return file.lastModified();
+ if (field.equals("content-type"))
+ return guessContentTypeFromName(file.getName());
+ else if (field.equals("content-length"))
+ return Long.toString(file.length());
+ else if (field.equals("last-modified"))
+ {
+ synchronized (dateFormat)
+ {
+ return dateFormat.format(new Date(file.lastModified()));
+ }
+ }
}
catch (IOException e)
{
- return -1;
+ // Fall through.
}
+ return null;
}
/**
* Get the length of content.
- *
* @return the length of the content.
*/
public int getContentLength()
{
try
{
+ if (!connected)
+ connect();
+
+ return (int) file.length();
+ }
+ catch (IOException e)
+ {
+ return -1;
+ }
+ }
+
+ /**
+ * Get the last modified time of the resource.
+ *
+ * @return the time since epoch that the resource was modified.
+ */
+ public long getLastModified()
+ {
+ try
+ {
if (!connected)
connect();
-
- return (int) file.length();
+
+ return file.lastModified();
}
catch (IOException e)
{
return -1;
}
}
-
+
/**
* This method returns a <code>Permission</code> object representing the
* permissions required to access this URL. This method returns a
@@ -205,6 +231,6 @@ public class Connection extends URLConnection
*/
public Permission getPermission() throws IOException
{
- return permission;
+ return new FilePermission(getURL().getFile(), "read");
}
}
OpenPOWER on IntegriCloud