summaryrefslogtreecommitdiffstats
path: root/libjava/java/net/URLConnection.java
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-22 01:33:11 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-22 01:33:11 +0000
commit4bed831ea2e22d2a38eb7ca75ff4257235ba36bc (patch)
tree1a0a199fd7f987eaa9b486b3e315675dc3166189 /libjava/java/net/URLConnection.java
parent0fb7aaf2e359f4d9fc974068d15c6504f8492562 (diff)
downloadppe42-gcc-4bed831ea2e22d2a38eb7ca75ff4257235ba36bc.tar.gz
ppe42-gcc-4bed831ea2e22d2a38eb7ca75ff4257235ba36bc.zip
2004-07-21 Bryce McKinlay <mckinlay@redhat.com>
* java/net/URLConnection.java (position): New field. (dateFormat1, dateFormat2, dateFormat3): Removed. (dateFormats): New field. (getHeaderFieldDate): Use new dateFormats array. Re-use parsePosition each time instead of re-allocating. (initializeDateFormats): Initialize 'dateFormats'. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85033 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net/URLConnection.java')
-rw-r--r--libjava/java/net/URLConnection.java35
1 files changed, 21 insertions, 14 deletions
diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java
index 867a53450c8..7b5f6a5dd18 100644
--- a/libjava/java/net/URLConnection.java
+++ b/libjava/java/net/URLConnection.java
@@ -165,11 +165,12 @@ public abstract class URLConnection
protected URL url;
private static Hashtable handlers = new Hashtable();
- private static SimpleDateFormat dateFormat1;
- private static SimpleDateFormat dateFormat2;
- private static SimpleDateFormat dateFormat3;
+ private static SimpleDateFormat[] dateFormats;
private static boolean dateformats_initialized;
+ /* Cached ParsePosition, used when parsing dates. */
+ private ParsePosition position;
+
/**
* Creates a URL connection to a given URL. A real connection is not made.
* Use #connect to do this.
@@ -366,19 +367,24 @@ public abstract class URLConnection
{
if (! dateformats_initialized)
initializeDateFormats();
+
+ if (position == null)
+ position = new ParsePosition(0);
long result = defaultValue;
String str = getHeaderField(name);
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();
+ for (int i = 0; i < dateFormats.length; i++)
+ {
+ SimpleDateFormat df = dateFormats[i];
+ position.setIndex(0);
+ position.setErrorIndex(0);
+ Date date = df.parse(str, position);
+ if (date != null)
+ return date.getTime();
+ }
}
return result;
@@ -1040,17 +1046,18 @@ public abstract class URLConnection
// 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()
+ private static synchronized void initializeDateFormats()
{
if (dateformats_initialized)
return;
Locale locale = new Locale("En", "Us", "Unix");
- dateFormat1 =
+ dateFormats = new SimpleDateFormat[3];
+ dateFormats[0] =
new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);
- dateFormat2 =
+ dateFormats[1] =
new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);
- dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
+ dateFormats[2] = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
dateformats_initialized = true;
}
}
OpenPOWER on IntegriCloud