/[classpath]/classpath/java/net/URLConnection.java
ViewVC logotype

Diff of /classpath/java/net/URLConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by tromey, Fri Apr 23 21:13:20 2004 UTC revision 1.29 by bryce, Thu Jul 22 01:34:55 2004 UTC
# Line 161  public abstract class URLConnection Line 161  public abstract class URLConnection
161     */     */
162    protected URL url;    protected URL url;
163    
164    private static SimpleDateFormat dateFormat1;    private static SimpleDateFormat[] dateFormats;
   private static SimpleDateFormat dateFormat2;  
   private static SimpleDateFormat dateFormat3;  
165    private static boolean dateformats_initialized;    private static boolean dateformats_initialized;
166    
167      /* Cached ParsePosition, used when parsing dates. */
168      private ParsePosition position;
169    
170    /**    /**
171     * 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.
172     * Use #connect to do this.     * Use #connect to do this.
# Line 362  public abstract class URLConnection Line 363  public abstract class URLConnection
363    {    {
364      if (! dateformats_initialized)      if (! dateformats_initialized)
365        initializeDateFormats();        initializeDateFormats();
366        
367        if (position == null)
368          position = new ParsePosition(0);
369    
370      long result = defaultValue;      long result = defaultValue;
371      String str = getHeaderField(name);      String str = getHeaderField(name);
372    
373      if (str != null)      if (str != null)
374        {        {
375          Date date;          for (int i = 0; i < dateFormats.length; i++)
376          if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)            {
377            result = date.getTime();              SimpleDateFormat df = dateFormats[i];
378          else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)              position.setIndex(0);
379            result = date.getTime();              position.setErrorIndex(0);
380          else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)              Date date = df.parse(str, position);
381            result = date.getTime();              if (date != null)
382                  return date.getTime();
383              }
384        }        }
385    
386      return result;      return result;
# Line 965  public abstract class URLConnection Line 971  public abstract class URLConnection
971    // 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
972    // with initializer co-dependency: SimpleDateFormat's constructors eventually    // with initializer co-dependency: SimpleDateFormat's constructors eventually
973    // depend on URLConnection (via the java.text.*Symbols classes).    // depend on URLConnection (via the java.text.*Symbols classes).
974    private synchronized void initializeDateFormats()    private static synchronized void initializeDateFormats()
975    {    {
976      if (dateformats_initialized)      if (dateformats_initialized)
977        return;        return;
978    
979      Locale locale = new Locale("En", "Us", "Unix");      Locale locale = new Locale("En", "Us", "Unix");
980      dateFormat1 =      dateFormats = new SimpleDateFormat[3];
981        dateFormats[0] =
982        new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);        new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);
983      dateFormat2 =      dateFormats[1] =
984        new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);        new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);
985      dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);      dateFormats[2] = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
986      dateformats_initialized = true;      dateformats_initialized = true;
987    }    }
988  }  }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26