summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-02-27 11:02:55 +0000
committerMichael Koch <konqueror@gmx.de>2004-02-27 11:02:55 +0000
commit35d53f8b29d5e98a6904650898ca7b1c1dbd2859 (patch)
tree285fe79d6a3d0a69570fd8942941fa29db09edb9
parent4c89093ddc3d7e8e1047b33eb715f5802a5008a4 (diff)
downloadclasspath-35d53f8b29d5e98a6904650898ca7b1c1dbd2859.tar.gz
2004-02-27 Michael Koch <konqueror@gmx.de>
* java/net/URLConnection.java (dateFormat1, dateformat2, dateformat3): New fields. (dateformats_initialized): New field for lazy initialization of date format fields. (getHeaderFieldDate): Rewritten to use DateFormat.parse() instead of the deprecated Date(String) constructor. This implementation (initializeDateFormats): New method,
-rw-r--r--ChangeLog10
-rw-r--r--java/net/URLConnection.java50
2 files changed, 46 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index dd7064a18..cdebe4b32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2004-02-27 Michael Koch <konqueror@gmx.de>
+ * java/net/URLConnection.java
+ (dateFormat1, dateformat2, dateformat3): New fields.
+ (dateformats_initialized): New field for lazy initialization of date
+ format fields.
+ (getHeaderFieldDate): Rewritten to use DateFormat.parse() instead of
+ the deprecated Date(String) constructor. This implementation
+ (initializeDateFormats): New method,
+
+2004-02-27 Michael Koch <konqueror@gmx.de>
+
* gnu/java/awt/ComponentDataBlitOp.java
(INSTANCE): Made final.
* gnu/java/awt/image/ImageDecoder.java:
diff --git a/java/net/URLConnection.java b/java/net/URLConnection.java
index cc556380e..f2f74ec95 100644
--- a/java/net/URLConnection.java
+++ b/java/net/URLConnection.java
@@ -43,6 +43,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.security.AllPermission;
import java.security.Permission;
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Hashtable;
@@ -161,6 +163,8 @@ public abstract class URLConnection
*/
protected URL url;
+ private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3;
+ private static boolean dateformats_initialized = false;
/**
* Creates a URL connection to a given URL. A real connection is not made.
@@ -352,23 +356,24 @@ public abstract class URLConnection
*/
public long getHeaderFieldDate (String name, long defaultValue)
{
+ if (! dateformats_initialized)
+ initializeDateFormats ();
+
+ long result = defaultValue;
String str = getHeaderField (name);
- if (str == null)
- return defaultValue;
+ if (str != null)
+ {
+ Date date;
+ if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
+ else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
+ else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null)
+ result = date.getTime ();
+ }
- // This needs to change since Date(String) is deprecated, but DateFormat
- // doesn't seem to be working for some reason
- //DateFormat df = DateFormat.getDateInstance (DateFormat.FULL, Locale.US);
- //df.setLenient (true);
-
- //Date date = df.parse (value, new ParsePosition (0));
- Date date = new Date (str);
-
- if (date == null)
- return defaultValue;
-
- return (date.getTime() / 1000);
+ return result;
}
/**
@@ -953,4 +958,21 @@ public abstract class URLConnection
fileNameMap = map;
}
+
+ // We don't put these in a static initializer, because it creates problems
+ // with initializer co-dependency: SimpleDateFormat's constructors eventually
+ // depend on URLConnection (via the java.text.*Symbols classes).
+ private synchronized void initializeDateFormats()
+ {
+ if (dateformats_initialized)
+ return;
+
+ Locale locale = new Locale("En", "Us", "Unix");
+ dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
+ locale);
+ dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'",
+ locale);
+ dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
+ dateformats_initialized = true;
+ }
}