/[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.16 by mkoch, Tue May 27 08:21:03 2003 UTC revision 1.17 by mkoch, Sat Jun 7 21:19:02 2003 UTC
# Line 226  public abstract class URLConnection Line 226  public abstract class URLConnection
226     */     */
227    public String getContentType()    public String getContentType()
228    {    {
229      String type = getHeaderField("content-type");      return getHeaderField("content-type");
     if (type == null)  
       type = guessContentTypeFromName(getURL().getFile());  
   
     return(type);  
230    }    }
231    
232    /**    /**
# Line 363  public abstract class URLConnection Line 359  public abstract class URLConnection
359     * be the number of seconds since midnight 1/1/1970 GMT or the default     * be the number of seconds since midnight 1/1/1970 GMT or the default
360     * value if the field is not present or cannot be converted to a date.     * value if the field is not present or cannot be converted to a date.
361     *     *
362     * @param key The header field key to lookup     * @param name The name of the header field
363     * @param def The default value if the header field is not found     * @param defaultValue The default date if the header field is not found
364     * or can't be converted.     * or can't be converted.
365       *
366       * @return Returns the date value of the header filed or the default value
367       * if the field is missing or malformed
368     */     */
369    public long getHeaderFieldDate(String key, long def)    public long getHeaderFieldDate (String name, long defaultValue)
370    {    {
371      String value = getHeaderField(key);      String str = getHeaderField (name);
372      if (value == null)      
373        return(def);      if (str == null)
374          return defaultValue;
375        
376      // This needs to change since Date(String) is deprecated, but DateFormat      // This needs to change since Date(String) is deprecated, but DateFormat
377      // doesn't seem to be working for some reason      // doesn't seem to be working for some reason
378      //DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);      //DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
379      //df.setLenient(true);      //df.setLenient(true);
380    
381      //Date d = df.parse(value, new ParsePosition(0));      //Date d = df.parse(value, new ParsePosition(0));
382      Date d = new Date(value);      Date d = new Date (str);
383    
384      if (d == null)      if (d == null)
385        return(def);        return defaultValue;
386                
387      return(d.getTime() / 1000);      return (d.getTime() / 1000);
388    }    }
389    
390    /**    /**
# Line 398  public abstract class URLConnection Line 398  public abstract class URLConnection
398     * @return The header field key or null if index is past the end     * @return The header field key or null if index is past the end
399     * of the headers.     * of the headers.
400     */     */
401    public String getHeaderFieldKey(int index)    public String getHeaderFieldKey (int index)
402    {    {
403      // Subclasses for specific protocols override this.      // Subclasses for specific protocols override this.
404      return null;      return null;
# Line 463  public abstract class URLConnection Line 463  public abstract class URLConnection
463    }    }
464    
465    /**    /**
466       * Retrieves the content of this URLConnection
467       *
468       * @exception IOException If an error occurs
469       * @exception UnknownServiceException If the protocol does not support the
470       * content type
471       */
472      public Object getContent(Class[] classes) throws IOException
473      {
474        // FIXME: implement this
475        return getContent ();
476      }
477    
478      /**
479     * This method returns a <code>Permission</code> object representing the     * This method returns a <code>Permission</code> object representing the
480     * permissions required to access this URL.  This method returns     * permissions required to access this URL.  This method returns
481     * <code>java.security.AllPermission</code> by default.  Subclasses should     * <code>java.security.AllPermission</code> by default.  Subclasses should
# Line 527  public abstract class URLConnection Line 540  public abstract class URLConnection
540     * Returns the value of a flag indicating whether or not input is going     * Returns the value of a flag indicating whether or not input is going
541     * to be done for this connection.  This default to true unless the     * to be done for this connection.  This default to true unless the
542     * doOutput flag is set to false, in which case this defaults to false.     * doOutput flag is set to false, in which case this defaults to false.
543       *
544       * @param input <code>true</code> if input is to be done,
545       * <code>false</code> otherwise
546     *     *
547     * @param input true if input is to be done, false otherwise     * @exception IllegalStateException If already connected
548     */     */
549    public void setDoInput(boolean input)    public void setDoInput(boolean input)
550    {    {
# Line 630  public abstract class URLConnection Line 646  public abstract class URLConnection
646     * Sets a boolean flag indicating whether or not caching will be used     * Sets a boolean flag indicating whether or not caching will be used
647     * (if possible) to store data downloaded via the connection.     * (if possible) to store data downloaded via the connection.
648     *     *
649     * @param use_cache true if caching should be used if possible,     * @param usecaches The new value
    * false otherwise.  
650     *     *
651     * @exception IllegalStateException If already connected     * @exception IllegalStateException If already connected
652     */     */
653    public void setUseCaches(boolean use_caches)    public void setUseCaches(boolean usecaches)
654    {    {
655      useCaches = use_caches;      if (connected)
656          throw new IllegalStateException ("Already connected");
657    
658        useCaches = usecaches;
659    }    }
660    
661    /**    /**
# Line 658  public abstract class URLConnection Line 676  public abstract class URLConnection
676     * passed should  be 0 if this feature is to be disabled or the time expressed     * passed should  be 0 if this feature is to be disabled or the time expressed
677     * as the number of seconds since midnight 1/1/1970 GMT otherwise.     * as the number of seconds since midnight 1/1/1970 GMT otherwise.
678     *     *
679     * @param modified_since The new ifModifiedSince value     * @param ifmodifiedsince The new value in milliseconds
680       * since January 1, 1970 GMT
681     *     *
682     * @exception IllegalStateException If already connected     * @exception IllegalStateException If already connected
683     */     */
684    public void setIfModifiedSince(long modified_since)    public void setIfModifiedSince(long ifmodifiedsince)
685    {    {
686      ifModifiedSince = modified_since;      if (connected)
687          throw new IllegalStateException ("Already connected");
688    
689        ifModifiedSince = ifmodifiedsince;
690    }    }
691    
692    /**    /**
# Line 682  public abstract class URLConnection Line 704  public abstract class URLConnection
704    }    }
705    
706    /**    /**
707     * Sets the default value used to determine whether or not caching     * Returns the default value used to determine whether or not caching
708     * of documents will be done when possible.     * of documents will be done when possible.
709     *     *
710     * @param use true to use caches if possible by default, false otherwise     * @return true if caches will be used, false otherwise
711     */     */
712    public synchronized void setDefaultUseCaches(boolean use)    public boolean getDefaultUseCaches()
713    {    {
714      defaultUseCaches = use;      return defaultUseCaches;
715    }    }
716    
717    /**    /**
718     * Returns the default value used to determine whether or not caching     * Sets the default value used to determine whether or not caching
719     * of documents will be done when possible.     * of documents will be done when possible.
720     *     *
721     * @return true if caches will be used, false otherwise     * @param use true to use caches if possible by default, false otherwise
    *  
    * @see URLConnection#getRequestProperty(String key)  
    * @see URLConnection#addRequestProperty(String key, String value)  
722     */     */
723    public boolean getDefaultUseCaches()    public void setDefaultUseCaches(boolean defaultusecaches)
724    {    {
725      return defaultUseCaches;      defaultUseCaches = defaultusecaches;
726    }    }
727    
728    /**    /**
# Line 723  public abstract class URLConnection Line 742  public abstract class URLConnection
742    }    }
743    
744    /**    /**
745       * Sets the value of the named request property
746       *
747       * @param key Key of the property to add
748       * @param value Value of the Property to add
749       *
750       * @exception IllegalStateException If already connected
751       * @exception NullPointerException If key is null
752       *
753       * @see URLConnection#getRequestProperty(String key)
754       * @see URLConnection#setRequestProperty(String key, String value)
755       *
756       * @since 1.4
757       */
758      public void addRequestProperty(String key, String value)
759      {
760        if (connected)
761          throw new IllegalStateException ("Already connected");
762    
763        if (getRequestProperty (key) == null)
764          {
765            setRequestProperty (key, value);
766          }
767      }
768    
769      /**
770     * Returns the value of the named request property.     * Returns the value of the named request property.
771     *     *
772     * @param key The name of the property     * @param key The name of the property

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

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