Commit eecbcf54 by Bryce McKinlay Committed by Bryce McKinlay

URLConnection.java (position): New field.

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'.

From-SVN: r85033
parent c9092111
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'.
2004-07-20 Bryce McKinlay <mckinlay@redhat.com> 2004-07-20 Bryce McKinlay <mckinlay@redhat.com>
PR libgcj/16591 PR libgcj/16591
......
...@@ -165,11 +165,12 @@ public abstract class URLConnection ...@@ -165,11 +165,12 @@ public abstract class URLConnection
protected URL url; protected URL url;
private static Hashtable handlers = new Hashtable(); private static Hashtable handlers = new Hashtable();
private static SimpleDateFormat dateFormat1; private static SimpleDateFormat[] dateFormats;
private static SimpleDateFormat dateFormat2;
private static SimpleDateFormat dateFormat3;
private static boolean dateformats_initialized; 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. * Creates a URL connection to a given URL. A real connection is not made.
* Use #connect to do this. * Use #connect to do this.
...@@ -366,19 +367,24 @@ public abstract class URLConnection ...@@ -366,19 +367,24 @@ public abstract class URLConnection
{ {
if (! dateformats_initialized) if (! dateformats_initialized)
initializeDateFormats(); initializeDateFormats();
if (position == null)
position = new ParsePosition(0);
long result = defaultValue; long result = defaultValue;
String str = getHeaderField(name); String str = getHeaderField(name);
if (str != null) if (str != null)
{ {
Date date; for (int i = 0; i < dateFormats.length; i++)
if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null) {
result = date.getTime(); SimpleDateFormat df = dateFormats[i];
else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null) position.setIndex(0);
result = date.getTime(); position.setErrorIndex(0);
else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null) Date date = df.parse(str, position);
result = date.getTime(); if (date != null)
return date.getTime();
}
} }
return result; return result;
...@@ -1040,17 +1046,18 @@ public abstract class URLConnection ...@@ -1040,17 +1046,18 @@ public abstract class URLConnection
// We don't put these in a static initializer, because it creates problems // We don't put these in a static initializer, because it creates problems
// with initializer co-dependency: SimpleDateFormat's constructors eventually // with initializer co-dependency: SimpleDateFormat's constructors eventually
// depend on URLConnection (via the java.text.*Symbols classes). // depend on URLConnection (via the java.text.*Symbols classes).
private synchronized void initializeDateFormats() private static synchronized void initializeDateFormats()
{ {
if (dateformats_initialized) if (dateformats_initialized)
return; return;
Locale locale = new Locale("En", "Us", "Unix"); 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); 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); 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; dateformats_initialized = true;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment