jdk/src/share/classes/java/net/URLConnection.java
changeset 19069 1d9cb0d080e3
parent 18156 edb590d448c5
child 21334 c60dfce46a77
child 21278 ef8a3a2a72f2
equal deleted inserted replaced
19068:f2358d18923a 19069:1d9cb0d080e3
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    38 import java.security.AccessController;
    38 import java.security.AccessController;
    39 import sun.security.util.SecurityConstants;
    39 import sun.security.util.SecurityConstants;
    40 import sun.net.www.MessageHeader;
    40 import sun.net.www.MessageHeader;
    41 
    41 
    42 /**
    42 /**
    43  * The abstract class <code>URLConnection</code> is the superclass
    43  * The abstract class {@code URLConnection} is the superclass
    44  * of all classes that represent a communications link between the
    44  * of all classes that represent a communications link between the
    45  * application and a URL. Instances of this class can be used both to
    45  * application and a URL. Instances of this class can be used both to
    46  * read from and to write to the resource referenced by the URL. In
    46  * read from and to write to the resource referenced by the URL. In
    47  * general, creating a connection to a URL is a multistep process:
    47  * general, creating a connection to a URL is a multistep process:
    48  * <p>
    48  * <p>
    49  * <center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time.">
    49  * <center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time.">
    50  * <tr><th><code>openConnection()</code></th>
    50  * <tr><th>{@code openConnection()}</th>
    51  *     <th><code>connect()</code></th></tr>
    51  *     <th>{@code connect()}</th></tr>
    52  * <tr><td>Manipulate parameters that affect the connection to the remote
    52  * <tr><td>Manipulate parameters that affect the connection to the remote
    53  *         resource.</td>
    53  *         resource.</td>
    54  *     <td>Interact with the resource; query header fields and
    54  *     <td>Interact with the resource; query header fields and
    55  *         contents.</td></tr>
    55  *         contents.</td></tr>
    56  * </table>
    56  * </table>
    57  * ----------------------------&gt;
    57  * ----------------------------&gt;
    58  * <br>time</center>
    58  * <br>time</center>
    59  *
    59  *
    60  * <ol>
    60  * <ol>
    61  * <li>The connection object is created by invoking the
    61  * <li>The connection object is created by invoking the
    62  *     <code>openConnection</code> method on a URL.
    62  *     {@code openConnection} method on a URL.
    63  * <li>The setup parameters and general request properties are manipulated.
    63  * <li>The setup parameters and general request properties are manipulated.
    64  * <li>The actual connection to the remote object is made, using the
    64  * <li>The actual connection to the remote object is made, using the
    65  *    <code>connect</code> method.
    65  *    {@code connect} method.
    66  * <li>The remote object becomes available. The header fields and the contents
    66  * <li>The remote object becomes available. The header fields and the contents
    67  *     of the remote object can be accessed.
    67  *     of the remote object can be accessed.
    68  * </ol>
    68  * </ol>
    69  * <p>
    69  * <p>
    70  * The setup parameters are modified using the following methods:
    70  * The setup parameters are modified using the following methods:
    71  * <ul>
    71  * <ul>
    72  *   <li><code>setAllowUserInteraction</code>
    72  *   <li>{@code setAllowUserInteraction}
    73  *   <li><code>setDoInput</code>
    73  *   <li>{@code setDoInput}
    74  *   <li><code>setDoOutput</code>
    74  *   <li>{@code setDoOutput}
    75  *   <li><code>setIfModifiedSince</code>
    75  *   <li>{@code setIfModifiedSince}
    76  *   <li><code>setUseCaches</code>
    76  *   <li>{@code setUseCaches}
    77  * </ul>
    77  * </ul>
    78  * <p>
    78  * <p>
    79  * and the general request properties are modified using the method:
    79  * and the general request properties are modified using the method:
    80  * <ul>
    80  * <ul>
    81  *   <li><code>setRequestProperty</code>
    81  *   <li>{@code setRequestProperty}
    82  * </ul>
    82  * </ul>
    83  * <p>
    83  * <p>
    84  * Default values for the <code>AllowUserInteraction</code> and
    84  * Default values for the {@code AllowUserInteraction} and
    85  * <code>UseCaches</code> parameters can be set using the methods
    85  * {@code UseCaches} parameters can be set using the methods
    86  * <code>setDefaultAllowUserInteraction</code> and
    86  * {@code setDefaultAllowUserInteraction} and
    87  * <code>setDefaultUseCaches</code>.
    87  * {@code setDefaultUseCaches}.
    88  * <p>
    88  * <p>
    89  * Each of the above <code>set</code> methods has a corresponding
    89  * Each of the above {@code set} methods has a corresponding
    90  * <code>get</code> method to retrieve the value of the parameter or
    90  * {@code get} method to retrieve the value of the parameter or
    91  * general request property. The specific parameters and general
    91  * general request property. The specific parameters and general
    92  * request properties that are applicable are protocol specific.
    92  * request properties that are applicable are protocol specific.
    93  * <p>
    93  * <p>
    94  * The following methods are used to access the header fields and
    94  * The following methods are used to access the header fields and
    95  * the contents after the connection is made to the remote object:
    95  * the contents after the connection is made to the remote object:
    96  * <ul>
    96  * <ul>
    97  *   <li><code>getContent</code>
    97  *   <li>{@code getContent}
    98  *   <li><code>getHeaderField</code>
    98  *   <li>{@code getHeaderField}
    99  *   <li><code>getInputStream</code>
    99  *   <li>{@code getInputStream}
   100  *   <li><code>getOutputStream</code>
   100  *   <li>{@code getOutputStream}
   101  * </ul>
   101  * </ul>
   102  * <p>
   102  * <p>
   103  * Certain header fields are accessed frequently. The methods:
   103  * Certain header fields are accessed frequently. The methods:
   104  * <ul>
   104  * <ul>
   105  *   <li><code>getContentEncoding</code>
   105  *   <li>{@code getContentEncoding}
   106  *   <li><code>getContentLength</code>
   106  *   <li>{@code getContentLength}
   107  *   <li><code>getContentType</code>
   107  *   <li>{@code getContentType}
   108  *   <li><code>getDate</code>
   108  *   <li>{@code getDate}
   109  *   <li><code>getExpiration</code>
   109  *   <li>{@code getExpiration}
   110  *   <li><code>getLastModifed</code>
   110  *   <li>{@code getLastModifed}
   111  * </ul>
   111  * </ul>
   112  * <p>
   112  * <p>
   113  * provide convenient access to these fields. The
   113  * provide convenient access to these fields. The
   114  * <code>getContentType</code> method is used by the
   114  * {@code getContentType} method is used by the
   115  * <code>getContent</code> method to determine the type of the remote
   115  * {@code getContent} method to determine the type of the remote
   116  * object; subclasses may find it convenient to override the
   116  * object; subclasses may find it convenient to override the
   117  * <code>getContentType</code> method.
   117  * {@code getContentType} method.
   118  * <p>
   118  * <p>
   119  * In the common case, all of the pre-connection parameters and
   119  * In the common case, all of the pre-connection parameters and
   120  * general request properties can be ignored: the pre-connection
   120  * general request properties can be ignored: the pre-connection
   121  * parameters and request properties default to sensible values. For
   121  * parameters and request properties default to sensible values. For
   122  * most clients of this interface, there are only two interesting
   122  * most clients of this interface, there are only two interesting
   123  * methods: <code>getInputStream</code> and <code>getContent</code>,
   123  * methods: {@code getInputStream} and {@code getContent},
   124  * which are mirrored in the <code>URL</code> class by convenience methods.
   124  * which are mirrored in the {@code URL} class by convenience methods.
   125  * <p>
   125  * <p>
   126  * More information on the request properties and header fields of
   126  * More information on the request properties and header fields of
   127  * an <code>http</code> connection can be found at:
   127  * an {@code http} connection can be found at:
   128  * <blockquote><pre>
   128  * <blockquote><pre>
   129  * <a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a>
   129  * <a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a>
   130  * </pre></blockquote>
   130  * </pre></blockquote>
   131  *
   131  *
   132  * Invoking the <tt>close()</tt> methods on the <tt>InputStream</tt> or <tt>OutputStream</tt> of an
   132  * Invoking the {@code close()} methods on the {@code InputStream} or {@code OutputStream} of an
   133  * <tt>URLConnection</tt> after a request may free network resources associated with this
   133  * {@code URLConnection} after a request may free network resources associated with this
   134  * instance, unless particular protocol specifications specify different behaviours
   134  * instance, unless particular protocol specifications specify different behaviours
   135  * for it.
   135  * for it.
   136  *
   136  *
   137  * @author  James Gosling
   137  * @author  James Gosling
   138  * @see     java.net.URL#openConnection()
   138  * @see     java.net.URL#openConnection()
   162    /**
   162    /**
   163      * The URL represents the remote object on the World Wide Web to
   163      * The URL represents the remote object on the World Wide Web to
   164      * which this connection is opened.
   164      * which this connection is opened.
   165      * <p>
   165      * <p>
   166      * The value of this field can be accessed by the
   166      * The value of this field can be accessed by the
   167      * <code>getURL</code> method.
   167      * {@code getURL} method.
   168      * <p>
   168      * <p>
   169      * The default value of this variable is the value of the URL
   169      * The default value of this variable is the value of the URL
   170      * argument in the <code>URLConnection</code> constructor.
   170      * argument in the {@code URLConnection} constructor.
   171      *
   171      *
   172      * @see     java.net.URLConnection#getURL()
   172      * @see     java.net.URLConnection#getURL()
   173      * @see     java.net.URLConnection#url
   173      * @see     java.net.URLConnection#url
   174      */
   174      */
   175     protected URL url;
   175     protected URL url;
   176 
   176 
   177    /**
   177    /**
   178      * This variable is set by the <code>setDoInput</code> method. Its
   178      * This variable is set by the {@code setDoInput} method. Its
   179      * value is returned by the <code>getDoInput</code> method.
   179      * value is returned by the {@code getDoInput} method.
   180      * <p>
   180      * <p>
   181      * A URL connection can be used for input and/or output. Setting the
   181      * A URL connection can be used for input and/or output. Setting the
   182      * <code>doInput</code> flag to <code>true</code> indicates that
   182      * {@code doInput} flag to {@code true} indicates that
   183      * the application intends to read data from the URL connection.
   183      * the application intends to read data from the URL connection.
   184      * <p>
   184      * <p>
   185      * The default value of this field is <code>true</code>.
   185      * The default value of this field is {@code true}.
   186      *
   186      *
   187      * @see     java.net.URLConnection#getDoInput()
   187      * @see     java.net.URLConnection#getDoInput()
   188      * @see     java.net.URLConnection#setDoInput(boolean)
   188      * @see     java.net.URLConnection#setDoInput(boolean)
   189      */
   189      */
   190     protected boolean doInput = true;
   190     protected boolean doInput = true;
   191 
   191 
   192    /**
   192    /**
   193      * This variable is set by the <code>setDoOutput</code> method. Its
   193      * This variable is set by the {@code setDoOutput} method. Its
   194      * value is returned by the <code>getDoOutput</code> method.
   194      * value is returned by the {@code getDoOutput} method.
   195      * <p>
   195      * <p>
   196      * A URL connection can be used for input and/or output. Setting the
   196      * A URL connection can be used for input and/or output. Setting the
   197      * <code>doOutput</code> flag to <code>true</code> indicates
   197      * {@code doOutput} flag to {@code true} indicates
   198      * that the application intends to write data to the URL connection.
   198      * that the application intends to write data to the URL connection.
   199      * <p>
   199      * <p>
   200      * The default value of this field is <code>false</code>.
   200      * The default value of this field is {@code false}.
   201      *
   201      *
   202      * @see     java.net.URLConnection#getDoOutput()
   202      * @see     java.net.URLConnection#getDoOutput()
   203      * @see     java.net.URLConnection#setDoOutput(boolean)
   203      * @see     java.net.URLConnection#setDoOutput(boolean)
   204      */
   204      */
   205     protected boolean doOutput = false;
   205     protected boolean doOutput = false;
   206 
   206 
   207     private static boolean defaultAllowUserInteraction = false;
   207     private static boolean defaultAllowUserInteraction = false;
   208 
   208 
   209    /**
   209    /**
   210      * If <code>true</code>, this <code>URL</code> is being examined in
   210      * If {@code true}, this {@code URL} is being examined in
   211      * a context in which it makes sense to allow user interactions such
   211      * a context in which it makes sense to allow user interactions such
   212      * as popping up an authentication dialog. If <code>false</code>,
   212      * as popping up an authentication dialog. If {@code false},
   213      * then no user interaction is allowed.
   213      * then no user interaction is allowed.
   214      * <p>
   214      * <p>
   215      * The value of this field can be set by the
   215      * The value of this field can be set by the
   216      * <code>setAllowUserInteraction</code> method.
   216      * {@code setAllowUserInteraction} method.
   217      * Its value is returned by the
   217      * Its value is returned by the
   218      * <code>getAllowUserInteraction</code> method.
   218      * {@code getAllowUserInteraction} method.
   219      * Its default value is the value of the argument in the last invocation
   219      * Its default value is the value of the argument in the last invocation
   220      * of the <code>setDefaultAllowUserInteraction</code> method.
   220      * of the {@code setDefaultAllowUserInteraction} method.
   221      *
   221      *
   222      * @see     java.net.URLConnection#getAllowUserInteraction()
   222      * @see     java.net.URLConnection#getAllowUserInteraction()
   223      * @see     java.net.URLConnection#setAllowUserInteraction(boolean)
   223      * @see     java.net.URLConnection#setAllowUserInteraction(boolean)
   224      * @see     java.net.URLConnection#setDefaultAllowUserInteraction(boolean)
   224      * @see     java.net.URLConnection#setDefaultAllowUserInteraction(boolean)
   225      */
   225      */
   226     protected boolean allowUserInteraction = defaultAllowUserInteraction;
   226     protected boolean allowUserInteraction = defaultAllowUserInteraction;
   227 
   227 
   228     private static boolean defaultUseCaches = true;
   228     private static boolean defaultUseCaches = true;
   229 
   229 
   230    /**
   230    /**
   231      * If <code>true</code>, the protocol is allowed to use caching
   231      * If {@code true}, the protocol is allowed to use caching
   232      * whenever it can. If <code>false</code>, the protocol must always
   232      * whenever it can. If {@code false}, the protocol must always
   233      * try to get a fresh copy of the object.
   233      * try to get a fresh copy of the object.
   234      * <p>
   234      * <p>
   235      * This field is set by the <code>setUseCaches</code> method. Its
   235      * This field is set by the {@code setUseCaches} method. Its
   236      * value is returned by the <code>getUseCaches</code> method.
   236      * value is returned by the {@code getUseCaches} method.
   237      * <p>
   237      * <p>
   238      * Its default value is the value given in the last invocation of the
   238      * Its default value is the value given in the last invocation of the
   239      * <code>setDefaultUseCaches</code> method.
   239      * {@code setDefaultUseCaches} method.
   240      *
   240      *
   241      * @see     java.net.URLConnection#setUseCaches(boolean)
   241      * @see     java.net.URLConnection#setUseCaches(boolean)
   242      * @see     java.net.URLConnection#getUseCaches()
   242      * @see     java.net.URLConnection#getUseCaches()
   243      * @see     java.net.URLConnection#setDefaultUseCaches(boolean)
   243      * @see     java.net.URLConnection#setDefaultUseCaches(boolean)
   244      */
   244      */
   250      * <p>
   250      * <p>
   251      * A nonzero value gives a time as the number of milliseconds since
   251      * A nonzero value gives a time as the number of milliseconds since
   252      * January 1, 1970, GMT. The object is fetched only if it has been
   252      * January 1, 1970, GMT. The object is fetched only if it has been
   253      * modified more recently than that time.
   253      * modified more recently than that time.
   254      * <p>
   254      * <p>
   255      * This variable is set by the <code>setIfModifiedSince</code>
   255      * This variable is set by the {@code setIfModifiedSince}
   256      * method. Its value is returned by the
   256      * method. Its value is returned by the
   257      * <code>getIfModifiedSince</code> method.
   257      * {@code getIfModifiedSince} method.
   258      * <p>
   258      * <p>
   259      * The default value of this field is <code>0</code>, indicating
   259      * The default value of this field is {@code 0}, indicating
   260      * that the fetching must always occur.
   260      * that the fetching must always occur.
   261      *
   261      *
   262      * @see     java.net.URLConnection#getIfModifiedSince()
   262      * @see     java.net.URLConnection#getIfModifiedSince()
   263      * @see     java.net.URLConnection#setIfModifiedSince(long)
   263      * @see     java.net.URLConnection#setIfModifiedSince(long)
   264      */
   264      */
   265     protected long ifModifiedSince = 0;
   265     protected long ifModifiedSince = 0;
   266 
   266 
   267    /**
   267    /**
   268      * If <code>false</code>, this connection object has not created a
   268      * If {@code false}, this connection object has not created a
   269      * communications link to the specified URL. If <code>true</code>,
   269      * communications link to the specified URL. If {@code true},
   270      * the communications link has been established.
   270      * the communications link has been established.
   271      */
   271      */
   272     protected boolean connected = false;
   272     protected boolean connected = false;
   273 
   273 
   274     /**
   274     /**
   318 
   318 
   319     /**
   319     /**
   320      * Sets the FileNameMap.
   320      * Sets the FileNameMap.
   321      * <p>
   321      * <p>
   322      * If there is a security manager, this method first calls
   322      * If there is a security manager, this method first calls
   323      * the security manager's <code>checkSetFactory</code> method
   323      * the security manager's {@code checkSetFactory} method
   324      * to ensure the operation is allowed.
   324      * to ensure the operation is allowed.
   325      * This could result in a SecurityException.
   325      * This could result in a SecurityException.
   326      *
   326      *
   327      * @param map the FileNameMap to be set
   327      * @param map the FileNameMap to be set
   328      * @exception  SecurityException  if a security manager exists and its
   328      * @exception  SecurityException  if a security manager exists and its
   329      *             <code>checkSetFactory</code> method doesn't allow the operation.
   329      *             {@code checkSetFactory} method doesn't allow the operation.
   330      * @see        SecurityManager#checkSetFactory
   330      * @see        SecurityManager#checkSetFactory
   331      * @see #getFileNameMap()
   331      * @see #getFileNameMap()
   332      * @since 1.2
   332      * @since 1.2
   333      */
   333      */
   334     public static void setFileNameMap(FileNameMap map) {
   334     public static void setFileNameMap(FileNameMap map) {
   339 
   339 
   340     /**
   340     /**
   341      * Opens a communications link to the resource referenced by this
   341      * Opens a communications link to the resource referenced by this
   342      * URL, if such a connection has not already been established.
   342      * URL, if such a connection has not already been established.
   343      * <p>
   343      * <p>
   344      * If the <code>connect</code> method is called when the connection
   344      * If the {@code connect} method is called when the connection
   345      * has already been opened (indicated by the <code>connected</code>
   345      * has already been opened (indicated by the {@code connected}
   346      * field having the value <code>true</code>), the call is ignored.
   346      * field having the value {@code true}), the call is ignored.
   347      * <p>
   347      * <p>
   348      * URLConnection objects go through two phases: first they are
   348      * URLConnection objects go through two phases: first they are
   349      * created, then they are connected.  After being created, and
   349      * created, then they are connected.  After being created, and
   350      * before being connected, various options can be specified
   350      * before being connected, various options can be specified
   351      * (e.g., doInput and UseCaches).  After connecting, it is an
   351      * (e.g., doInput and UseCaches).  After connecting, it is an
   373 
   373 
   374      * <p> Some non-standard implmentation of this method may ignore
   374      * <p> Some non-standard implmentation of this method may ignore
   375      * the specified timeout. To see the connect timeout set, please
   375      * the specified timeout. To see the connect timeout set, please
   376      * call getConnectTimeout().
   376      * call getConnectTimeout().
   377      *
   377      *
   378      * @param timeout an <code>int</code> that specifies the connect
   378      * @param timeout an {@code int} that specifies the connect
   379      *               timeout value in milliseconds
   379      *               timeout value in milliseconds
   380      * @throws IllegalArgumentException if the timeout parameter is negative
   380      * @throws IllegalArgumentException if the timeout parameter is negative
   381      *
   381      *
   382      * @see #getConnectTimeout()
   382      * @see #getConnectTimeout()
   383      * @see #connect()
   383      * @see #connect()
   394      * Returns setting for connect timeout.
   394      * Returns setting for connect timeout.
   395      * <p>
   395      * <p>
   396      * 0 return implies that the option is disabled
   396      * 0 return implies that the option is disabled
   397      * (i.e., timeout of infinity).
   397      * (i.e., timeout of infinity).
   398      *
   398      *
   399      * @return an <code>int</code> that indicates the connect timeout
   399      * @return an {@code int} that indicates the connect timeout
   400      *         value in milliseconds
   400      *         value in milliseconds
   401      * @see #setConnectTimeout(int)
   401      * @see #setConnectTimeout(int)
   402      * @see #connect()
   402      * @see #connect()
   403      * @since 1.5
   403      * @since 1.5
   404      */
   404      */
   416      *
   416      *
   417      *<p> Some non-standard implementation of this method ignores the
   417      *<p> Some non-standard implementation of this method ignores the
   418      * specified timeout. To see the read timeout set, please call
   418      * specified timeout. To see the read timeout set, please call
   419      * getReadTimeout().
   419      * getReadTimeout().
   420      *
   420      *
   421      * @param timeout an <code>int</code> that specifies the timeout
   421      * @param timeout an {@code int} that specifies the timeout
   422      * value to be used in milliseconds
   422      * value to be used in milliseconds
   423      * @throws IllegalArgumentException if the timeout parameter is negative
   423      * @throws IllegalArgumentException if the timeout parameter is negative
   424      *
   424      *
   425      * @see #getReadTimeout()
   425      * @see #getReadTimeout()
   426      * @see InputStream#read()
   426      * @see InputStream#read()
   435 
   435 
   436     /**
   436     /**
   437      * Returns setting for read timeout. 0 return implies that the
   437      * Returns setting for read timeout. 0 return implies that the
   438      * option is disabled (i.e., timeout of infinity).
   438      * option is disabled (i.e., timeout of infinity).
   439      *
   439      *
   440      * @return an <code>int</code> that indicates the read timeout
   440      * @return an {@code int} that indicates the read timeout
   441      *         value in milliseconds
   441      *         value in milliseconds
   442      *
   442      *
   443      * @see #setReadTimeout(int)
   443      * @see #setReadTimeout(int)
   444      * @see InputStream#read()
   444      * @see InputStream#read()
   445      * @since 1.5
   445      * @since 1.5
   457     protected URLConnection(URL url) {
   457     protected URLConnection(URL url) {
   458         this.url = url;
   458         this.url = url;
   459     }
   459     }
   460 
   460 
   461     /**
   461     /**
   462      * Returns the value of this <code>URLConnection</code>'s <code>URL</code>
   462      * Returns the value of this {@code URLConnection}'s {@code URL}
   463      * field.
   463      * field.
   464      *
   464      *
   465      * @return  the value of this <code>URLConnection</code>'s <code>URL</code>
   465      * @return  the value of this {@code URLConnection}'s {@code URL}
   466      *          field.
   466      *          field.
   467      * @see     java.net.URLConnection#url
   467      * @see     java.net.URLConnection#url
   468      */
   468      */
   469     public URL getURL() {
   469     public URL getURL() {
   470         return url;
   470         return url;
   471     }
   471     }
   472 
   472 
   473     /**
   473     /**
   474      * Returns the value of the <code>content-length</code> header field.
   474      * Returns the value of the {@code content-length} header field.
   475      * <P>
   475      * <P>
   476      * <B>Note</B>: {@link #getContentLengthLong() getContentLengthLong()}
   476      * <B>Note</B>: {@link #getContentLengthLong() getContentLengthLong()}
   477      * should be preferred over this method, since it returns a {@code long}
   477      * should be preferred over this method, since it returns a {@code long}
   478      * instead and is therefore more portable.</P>
   478      * instead and is therefore more portable.</P>
   479      *
   479      *
   487             return -1;
   487             return -1;
   488         return (int) l;
   488         return (int) l;
   489     }
   489     }
   490 
   490 
   491     /**
   491     /**
   492      * Returns the value of the <code>content-length</code> header field as a
   492      * Returns the value of the {@code content-length} header field as a
   493      * long.
   493      * long.
   494      *
   494      *
   495      * @return  the content length of the resource that this connection's URL
   495      * @return  the content length of the resource that this connection's URL
   496      *          references, or <code>-1</code> if the content length is
   496      *          references, or {@code -1} if the content length is
   497      *          not known.
   497      *          not known.
   498      * @since 7.0
   498      * @since 7.0
   499      */
   499      */
   500     public long getContentLengthLong() {
   500     public long getContentLengthLong() {
   501         return getHeaderFieldLong("content-length", -1);
   501         return getHeaderFieldLong("content-length", -1);
   502     }
   502     }
   503 
   503 
   504     /**
   504     /**
   505      * Returns the value of the <code>content-type</code> header field.
   505      * Returns the value of the {@code content-type} header field.
   506      *
   506      *
   507      * @return  the content type of the resource that the URL references,
   507      * @return  the content type of the resource that the URL references,
   508      *          or <code>null</code> if not known.
   508      *          or {@code null} if not known.
   509      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   509      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   510      */
   510      */
   511     public String getContentType() {
   511     public String getContentType() {
   512         return getHeaderField("content-type");
   512         return getHeaderField("content-type");
   513     }
   513     }
   514 
   514 
   515     /**
   515     /**
   516      * Returns the value of the <code>content-encoding</code> header field.
   516      * Returns the value of the {@code content-encoding} header field.
   517      *
   517      *
   518      * @return  the content encoding of the resource that the URL references,
   518      * @return  the content encoding of the resource that the URL references,
   519      *          or <code>null</code> if not known.
   519      *          or {@code null} if not known.
   520      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   520      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   521      */
   521      */
   522     public String getContentEncoding() {
   522     public String getContentEncoding() {
   523         return getHeaderField("content-encoding");
   523         return getHeaderField("content-encoding");
   524     }
   524     }
   525 
   525 
   526     /**
   526     /**
   527      * Returns the value of the <code>expires</code> header field.
   527      * Returns the value of the {@code expires} header field.
   528      *
   528      *
   529      * @return  the expiration date of the resource that this URL references,
   529      * @return  the expiration date of the resource that this URL references,
   530      *          or 0 if not known. The value is the number of milliseconds since
   530      *          or 0 if not known. The value is the number of milliseconds since
   531      *          January 1, 1970 GMT.
   531      *          January 1, 1970 GMT.
   532      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   532      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   534     public long getExpiration() {
   534     public long getExpiration() {
   535         return getHeaderFieldDate("expires", 0);
   535         return getHeaderFieldDate("expires", 0);
   536     }
   536     }
   537 
   537 
   538     /**
   538     /**
   539      * Returns the value of the <code>date</code> header field.
   539      * Returns the value of the {@code date} header field.
   540      *
   540      *
   541      * @return  the sending date of the resource that the URL references,
   541      * @return  the sending date of the resource that the URL references,
   542      *          or <code>0</code> if not known. The value returned is the
   542      *          or {@code 0} if not known. The value returned is the
   543      *          number of milliseconds since January 1, 1970 GMT.
   543      *          number of milliseconds since January 1, 1970 GMT.
   544      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   544      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   545      */
   545      */
   546     public long getDate() {
   546     public long getDate() {
   547         return getHeaderFieldDate("date", 0);
   547         return getHeaderFieldDate("date", 0);
   548     }
   548     }
   549 
   549 
   550     /**
   550     /**
   551      * Returns the value of the <code>last-modified</code> header field.
   551      * Returns the value of the {@code last-modified} header field.
   552      * The result is the number of milliseconds since January 1, 1970 GMT.
   552      * The result is the number of milliseconds since January 1, 1970 GMT.
   553      *
   553      *
   554      * @return  the date the resource referenced by this
   554      * @return  the date the resource referenced by this
   555      *          <code>URLConnection</code> was last modified, or 0 if not known.
   555      *          {@code URLConnection} was last modified, or 0 if not known.
   556      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   556      * @see     java.net.URLConnection#getHeaderField(java.lang.String)
   557      */
   557      */
   558     public long getLastModified() {
   558     public long getLastModified() {
   559         return getHeaderFieldDate("last-modified", 0);
   559         return getHeaderFieldDate("last-modified", 0);
   560     }
   560     }
   565      * If called on a connection that sets the same header multiple times
   565      * If called on a connection that sets the same header multiple times
   566      * with possibly different values, only the last value is returned.
   566      * with possibly different values, only the last value is returned.
   567      *
   567      *
   568      *
   568      *
   569      * @param   name   the name of a header field.
   569      * @param   name   the name of a header field.
   570      * @return  the value of the named header field, or <code>null</code>
   570      * @return  the value of the named header field, or {@code null}
   571      *          if there is no such field in the header.
   571      *          if there is no such field in the header.
   572      */
   572      */
   573     public String getHeaderField(String name) {
   573     public String getHeaderField(String name) {
   574         return null;
   574         return null;
   575     }
   575     }
   589     }
   589     }
   590 
   590 
   591     /**
   591     /**
   592      * Returns the value of the named field parsed as a number.
   592      * Returns the value of the named field parsed as a number.
   593      * <p>
   593      * <p>
   594      * This form of <code>getHeaderField</code> exists because some
   594      * This form of {@code getHeaderField} exists because some
   595      * connection types (e.g., <code>http-ng</code>) have pre-parsed
   595      * connection types (e.g., {@code http-ng}) have pre-parsed
   596      * headers. Classes for that connection type can override this method
   596      * headers. Classes for that connection type can override this method
   597      * and short-circuit the parsing.
   597      * and short-circuit the parsing.
   598      *
   598      *
   599      * @param   name      the name of the header field.
   599      * @param   name      the name of the header field.
   600      * @param   Default   the default value.
   600      * @param   Default   the default value.
   601      * @return  the value of the named field, parsed as an integer. The
   601      * @return  the value of the named field, parsed as an integer. The
   602      *          <code>Default</code> value is returned if the field is
   602      *          {@code Default} value is returned if the field is
   603      *          missing or malformed.
   603      *          missing or malformed.
   604      */
   604      */
   605     public int getHeaderFieldInt(String name, int Default) {
   605     public int getHeaderFieldInt(String name, int Default) {
   606         String value = getHeaderField(name);
   606         String value = getHeaderField(name);
   607         try {
   607         try {
   611     }
   611     }
   612 
   612 
   613     /**
   613     /**
   614      * Returns the value of the named field parsed as a number.
   614      * Returns the value of the named field parsed as a number.
   615      * <p>
   615      * <p>
   616      * This form of <code>getHeaderField</code> exists because some
   616      * This form of {@code getHeaderField} exists because some
   617      * connection types (e.g., <code>http-ng</code>) have pre-parsed
   617      * connection types (e.g., {@code http-ng}) have pre-parsed
   618      * headers. Classes for that connection type can override this method
   618      * headers. Classes for that connection type can override this method
   619      * and short-circuit the parsing.
   619      * and short-circuit the parsing.
   620      *
   620      *
   621      * @param   name      the name of the header field.
   621      * @param   name      the name of the header field.
   622      * @param   Default   the default value.
   622      * @param   Default   the default value.
   623      * @return  the value of the named field, parsed as a long. The
   623      * @return  the value of the named field, parsed as a long. The
   624      *          <code>Default</code> value is returned if the field is
   624      *          {@code Default} value is returned if the field is
   625      *          missing or malformed.
   625      *          missing or malformed.
   626      * @since 7.0
   626      * @since 7.0
   627      */
   627      */
   628     public long getHeaderFieldLong(String name, long Default) {
   628     public long getHeaderFieldLong(String name, long Default) {
   629         String value = getHeaderField(name);
   629         String value = getHeaderField(name);
   636     /**
   636     /**
   637      * Returns the value of the named field parsed as date.
   637      * Returns the value of the named field parsed as date.
   638      * The result is the number of milliseconds since January 1, 1970 GMT
   638      * The result is the number of milliseconds since January 1, 1970 GMT
   639      * represented by the named field.
   639      * represented by the named field.
   640      * <p>
   640      * <p>
   641      * This form of <code>getHeaderField</code> exists because some
   641      * This form of {@code getHeaderField} exists because some
   642      * connection types (e.g., <code>http-ng</code>) have pre-parsed
   642      * connection types (e.g., {@code http-ng}) have pre-parsed
   643      * headers. Classes for that connection type can override this method
   643      * headers. Classes for that connection type can override this method
   644      * and short-circuit the parsing.
   644      * and short-circuit the parsing.
   645      *
   645      *
   646      * @param   name     the name of the header field.
   646      * @param   name     the name of the header field.
   647      * @param   Default   a default value.
   647      * @param   Default   a default value.
   648      * @return  the value of the field, parsed as a date. The value of the
   648      * @return  the value of the field, parsed as a date. The value of the
   649      *          <code>Default</code> argument is returned if the field is
   649      *          {@code Default} argument is returned if the field is
   650      *          missing or malformed.
   650      *          missing or malformed.
   651      */
   651      */
   652     @SuppressWarnings("deprecation")
   652     @SuppressWarnings("deprecation")
   653     public long getHeaderFieldDate(String name, long Default) {
   653     public long getHeaderFieldDate(String name, long Default) {
   654         String value = getHeaderField(name);
   654         String value = getHeaderField(name);
   657         } catch (Exception e) { }
   657         } catch (Exception e) { }
   658         return Default;
   658         return Default;
   659     }
   659     }
   660 
   660 
   661     /**
   661     /**
   662      * Returns the key for the <code>n</code><sup>th</sup> header field.
   662      * Returns the key for the {@code n}<sup>th</sup> header field.
   663      * It returns <code>null</code> if there are fewer than <code>n+1</code> fields.
   663      * It returns {@code null} if there are fewer than {@code n+1} fields.
   664      *
   664      *
   665      * @param   n   an index, where {@code n>=0}
   665      * @param   n   an index, where {@code n>=0}
   666      * @return  the key for the <code>n</code><sup>th</sup> header field,
   666      * @return  the key for the {@code n}<sup>th</sup> header field,
   667      *          or <code>null</code> if there are fewer than <code>n+1</code>
   667      *          or {@code null} if there are fewer than {@code n+1}
   668      *          fields.
   668      *          fields.
   669      */
   669      */
   670     public String getHeaderFieldKey(int n) {
   670     public String getHeaderFieldKey(int n) {
   671         return null;
   671         return null;
   672     }
   672     }
   673 
   673 
   674     /**
   674     /**
   675      * Returns the value for the <code>n</code><sup>th</sup> header field.
   675      * Returns the value for the {@code n}<sup>th</sup> header field.
   676      * It returns <code>null</code> if there are fewer than
   676      * It returns {@code null} if there are fewer than
   677      * <code>n+1</code>fields.
   677      * {@code n+1}fields.
   678      * <p>
   678      * <p>
   679      * This method can be used in conjunction with the
   679      * This method can be used in conjunction with the
   680      * {@link #getHeaderFieldKey(int) getHeaderFieldKey} method to iterate through all
   680      * {@link #getHeaderFieldKey(int) getHeaderFieldKey} method to iterate through all
   681      * the headers in the message.
   681      * the headers in the message.
   682      *
   682      *
   683      * @param   n   an index, where {@code n>=0}
   683      * @param   n   an index, where {@code n>=0}
   684      * @return  the value of the <code>n</code><sup>th</sup> header field
   684      * @return  the value of the {@code n}<sup>th</sup> header field
   685      *          or <code>null</code> if there are fewer than <code>n+1</code> fields
   685      *          or {@code null} if there are fewer than {@code n+1} fields
   686      * @see     java.net.URLConnection#getHeaderFieldKey(int)
   686      * @see     java.net.URLConnection#getHeaderFieldKey(int)
   687      */
   687      */
   688     public String getHeaderField(int n) {
   688     public String getHeaderField(int n) {
   689         return null;
   689         return null;
   690     }
   690     }
   691 
   691 
   692     /**
   692     /**
   693      * Retrieves the contents of this URL connection.
   693      * Retrieves the contents of this URL connection.
   694      * <p>
   694      * <p>
   695      * This method first determines the content type of the object by
   695      * This method first determines the content type of the object by
   696      * calling the <code>getContentType</code> method. If this is
   696      * calling the {@code getContentType} method. If this is
   697      * the first time that the application has seen that specific content
   697      * the first time that the application has seen that specific content
   698      * type, a content handler for that content type is created:
   698      * type, a content handler for that content type is created:
   699      * <ol>
   699      * <ol>
   700      * <li>If the application has set up a content handler factory instance
   700      * <li>If the application has set up a content handler factory instance
   701      *     using the <code>setContentHandlerFactory</code> method, the
   701      *     using the {@code setContentHandlerFactory} method, the
   702      *     <code>createContentHandler</code> method of that instance is called
   702      *     {@code createContentHandler} method of that instance is called
   703      *     with the content type as an argument; the result is a content
   703      *     with the content type as an argument; the result is a content
   704      *     handler for that content type.
   704      *     handler for that content type.
   705      * <li>If no content handler factory has yet been set up, or if the
   705      * <li>If no content handler factory has yet been set up, or if the
   706      *     factory's <code>createContentHandler</code> method returns
   706      *     factory's {@code createContentHandler} method returns
   707      *     <code>null</code>, then the application loads the class named:
   707      *     {@code null}, then the application loads the class named:
   708      *     <blockquote><pre>
   708      *     <blockquote><pre>
   709      *         sun.net.www.content.&lt;<i>contentType</i>&gt;
   709      *         sun.net.www.content.&lt;<i>contentType</i>&gt;
   710      *     </pre></blockquote>
   710      *     </pre></blockquote>
   711      *     where &lt;<i>contentType</i>&gt; is formed by taking the
   711      *     where &lt;<i>contentType</i>&gt; is formed by taking the
   712      *     content-type string, replacing all slash characters with a
   712      *     content-type string, replacing all slash characters with a
   713      *     <code>period</code> ('.'), and all other non-alphanumeric characters
   713      *     {@code period} ('.'), and all other non-alphanumeric characters
   714      *     with the underscore character '<code>_</code>'. The alphanumeric
   714      *     with the underscore character '{@code _}'. The alphanumeric
   715      *     characters are specifically the 26 uppercase ASCII letters
   715      *     characters are specifically the 26 uppercase ASCII letters
   716      *     '<code>A</code>' through '<code>Z</code>', the 26 lowercase ASCII
   716      *     '{@code A}' through '{@code Z}', the 26 lowercase ASCII
   717      *     letters '<code>a</code>' through '<code>z</code>', and the 10 ASCII
   717      *     letters '{@code a}' through '{@code z}', and the 10 ASCII
   718      *     digits '<code>0</code>' through '<code>9</code>'. If the specified
   718      *     digits '{@code 0}' through '{@code 9}'. If the specified
   719      *     class does not exist, or is not a subclass of
   719      *     class does not exist, or is not a subclass of
   720      *     <code>ContentHandler</code>, then an
   720      *     {@code ContentHandler}, then an
   721      *     <code>UnknownServiceException</code> is thrown.
   721      *     {@code UnknownServiceException} is thrown.
   722      * </ol>
   722      * </ol>
   723      *
   723      *
   724      * @return     the object fetched. The <code>instanceof</code> operator
   724      * @return     the object fetched. The {@code instanceof} operator
   725      *               should be used to determine the specific kind of object
   725      *               should be used to determine the specific kind of object
   726      *               returned.
   726      *               returned.
   727      * @exception  IOException              if an I/O error occurs while
   727      * @exception  IOException              if an I/O error occurs while
   728      *               getting the content.
   728      *               getting the content.
   729      * @exception  UnknownServiceException  if the protocol does not support
   729      * @exception  UnknownServiceException  if the protocol does not support
   741     }
   741     }
   742 
   742 
   743     /**
   743     /**
   744      * Retrieves the contents of this URL connection.
   744      * Retrieves the contents of this URL connection.
   745      *
   745      *
   746      * @param classes the <code>Class</code> array
   746      * @param classes the {@code Class} array
   747      * indicating the requested types
   747      * indicating the requested types
   748      * @return     the object fetched that is the first match of the type
   748      * @return     the object fetched that is the first match of the type
   749      *               specified in the classes array. null if none of
   749      *               specified in the classes array. null if none of
   750      *               the requested types are supported.
   750      *               the requested types are supported.
   751      *               The <code>instanceof</code> operator should be used to
   751      *               The {@code instanceof} operator should be used to
   752      *               determine the specific kind of object returned.
   752      *               determine the specific kind of object returned.
   753      * @exception  IOException              if an I/O error occurs while
   753      * @exception  IOException              if an I/O error occurs while
   754      *               getting the content.
   754      *               getting the content.
   755      * @exception  UnknownServiceException  if the protocol does not support
   755      * @exception  UnknownServiceException  if the protocol does not support
   756      *               the content type.
   756      *               the content type.
   771     /**
   771     /**
   772      * Returns a permission object representing the permission
   772      * Returns a permission object representing the permission
   773      * necessary to make the connection represented by this
   773      * necessary to make the connection represented by this
   774      * object. This method returns null if no permission is
   774      * object. This method returns null if no permission is
   775      * required to make the connection. By default, this method
   775      * required to make the connection. By default, this method
   776      * returns <code>java.security.AllPermission</code>. Subclasses
   776      * returns {@code java.security.AllPermission}. Subclasses
   777      * should override this method and return the permission
   777      * should override this method and return the permission
   778      * that best represents the permission required to make a
   778      * that best represents the permission required to make a
   779      * a connection to the URL. For example, a <code>URLConnection</code>
   779      * a connection to the URL. For example, a {@code URLConnection}
   780      * representing a <code>file:</code> URL would return a
   780      * representing a {@code file:} URL would return a
   781      * <code>java.io.FilePermission</code> object.
   781      * {@code java.io.FilePermission} object.
   782      *
   782      *
   783      * <p>The permission returned may dependent upon the state of the
   783      * <p>The permission returned may dependent upon the state of the
   784      * connection. For example, the permission before connecting may be
   784      * connection. For example, the permission before connecting may be
   785      * different from that after connecting. For example, an HTTP
   785      * different from that after connecting. For example, an HTTP
   786      * sever, say foo.com, may redirect the connection to a different
   786      * sever, say foo.com, may redirect the connection to a different
   842     public OutputStream getOutputStream() throws IOException {
   842     public OutputStream getOutputStream() throws IOException {
   843         throw new UnknownServiceException("protocol doesn't support output");
   843         throw new UnknownServiceException("protocol doesn't support output");
   844     }
   844     }
   845 
   845 
   846     /**
   846     /**
   847      * Returns a <code>String</code> representation of this URL connection.
   847      * Returns a {@code String} representation of this URL connection.
   848      *
   848      *
   849      * @return  a string representation of this <code>URLConnection</code>.
   849      * @return  a string representation of this {@code URLConnection}.
   850      */
   850      */
   851     public String toString() {
   851     public String toString() {
   852         return this.getClass().getName() + ":" + url;
   852         return this.getClass().getName() + ":" + url;
   853     }
   853     }
   854 
   854 
   855     /**
   855     /**
   856      * Sets the value of the <code>doInput</code> field for this
   856      * Sets the value of the {@code doInput} field for this
   857      * <code>URLConnection</code> to the specified value.
   857      * {@code URLConnection} to the specified value.
   858      * <p>
   858      * <p>
   859      * A URL connection can be used for input and/or output.  Set the DoInput
   859      * A URL connection can be used for input and/or output.  Set the DoInput
   860      * flag to true if you intend to use the URL connection for input,
   860      * flag to true if you intend to use the URL connection for input,
   861      * false if not.  The default is true.
   861      * false if not.  The default is true.
   862      *
   862      *
   870             throw new IllegalStateException("Already connected");
   870             throw new IllegalStateException("Already connected");
   871         doInput = doinput;
   871         doInput = doinput;
   872     }
   872     }
   873 
   873 
   874     /**
   874     /**
   875      * Returns the value of this <code>URLConnection</code>'s
   875      * Returns the value of this {@code URLConnection}'s
   876      * <code>doInput</code> flag.
   876      * {@code doInput} flag.
   877      *
   877      *
   878      * @return  the value of this <code>URLConnection</code>'s
   878      * @return  the value of this {@code URLConnection}'s
   879      *          <code>doInput</code> flag.
   879      *          {@code doInput} flag.
   880      * @see     #setDoInput(boolean)
   880      * @see     #setDoInput(boolean)
   881      */
   881      */
   882     public boolean getDoInput() {
   882     public boolean getDoInput() {
   883         return doInput;
   883         return doInput;
   884     }
   884     }
   885 
   885 
   886     /**
   886     /**
   887      * Sets the value of the <code>doOutput</code> field for this
   887      * Sets the value of the {@code doOutput} field for this
   888      * <code>URLConnection</code> to the specified value.
   888      * {@code URLConnection} to the specified value.
   889      * <p>
   889      * <p>
   890      * A URL connection can be used for input and/or output.  Set the DoOutput
   890      * A URL connection can be used for input and/or output.  Set the DoOutput
   891      * flag to true if you intend to use the URL connection for output,
   891      * flag to true if you intend to use the URL connection for output,
   892      * false if not.  The default is false.
   892      * false if not.  The default is false.
   893      *
   893      *
   900             throw new IllegalStateException("Already connected");
   900             throw new IllegalStateException("Already connected");
   901         doOutput = dooutput;
   901         doOutput = dooutput;
   902     }
   902     }
   903 
   903 
   904     /**
   904     /**
   905      * Returns the value of this <code>URLConnection</code>'s
   905      * Returns the value of this {@code URLConnection}'s
   906      * <code>doOutput</code> flag.
   906      * {@code doOutput} flag.
   907      *
   907      *
   908      * @return  the value of this <code>URLConnection</code>'s
   908      * @return  the value of this {@code URLConnection}'s
   909      *          <code>doOutput</code> flag.
   909      *          {@code doOutput} flag.
   910      * @see     #setDoOutput(boolean)
   910      * @see     #setDoOutput(boolean)
   911      */
   911      */
   912     public boolean getDoOutput() {
   912     public boolean getDoOutput() {
   913         return doOutput;
   913         return doOutput;
   914     }
   914     }
   915 
   915 
   916     /**
   916     /**
   917      * Set the value of the <code>allowUserInteraction</code> field of
   917      * Set the value of the {@code allowUserInteraction} field of
   918      * this <code>URLConnection</code>.
   918      * this {@code URLConnection}.
   919      *
   919      *
   920      * @param   allowuserinteraction   the new value.
   920      * @param   allowuserinteraction   the new value.
   921      * @throws IllegalStateException if already connected
   921      * @throws IllegalStateException if already connected
   922      * @see     #getAllowUserInteraction()
   922      * @see     #getAllowUserInteraction()
   923      */
   923      */
   926             throw new IllegalStateException("Already connected");
   926             throw new IllegalStateException("Already connected");
   927         allowUserInteraction = allowuserinteraction;
   927         allowUserInteraction = allowuserinteraction;
   928     }
   928     }
   929 
   929 
   930     /**
   930     /**
   931      * Returns the value of the <code>allowUserInteraction</code> field for
   931      * Returns the value of the {@code allowUserInteraction} field for
   932      * this object.
   932      * this object.
   933      *
   933      *
   934      * @return  the value of the <code>allowUserInteraction</code> field for
   934      * @return  the value of the {@code allowUserInteraction} field for
   935      *          this object.
   935      *          this object.
   936      * @see     #setAllowUserInteraction(boolean)
   936      * @see     #setAllowUserInteraction(boolean)
   937      */
   937      */
   938     public boolean getAllowUserInteraction() {
   938     public boolean getAllowUserInteraction() {
   939         return allowUserInteraction;
   939         return allowUserInteraction;
   940     }
   940     }
   941 
   941 
   942     /**
   942     /**
   943      * Sets the default value of the
   943      * Sets the default value of the
   944      * <code>allowUserInteraction</code> field for all future
   944      * {@code allowUserInteraction} field for all future
   945      * <code>URLConnection</code> objects to the specified value.
   945      * {@code URLConnection} objects to the specified value.
   946      *
   946      *
   947      * @param   defaultallowuserinteraction   the new value.
   947      * @param   defaultallowuserinteraction   the new value.
   948      * @see     #getDefaultAllowUserInteraction()
   948      * @see     #getDefaultAllowUserInteraction()
   949      */
   949      */
   950     public static void setDefaultAllowUserInteraction(boolean defaultallowuserinteraction) {
   950     public static void setDefaultAllowUserInteraction(boolean defaultallowuserinteraction) {
   951         defaultAllowUserInteraction = defaultallowuserinteraction;
   951         defaultAllowUserInteraction = defaultallowuserinteraction;
   952     }
   952     }
   953 
   953 
   954     /**
   954     /**
   955      * Returns the default value of the <code>allowUserInteraction</code>
   955      * Returns the default value of the {@code allowUserInteraction}
   956      * field.
   956      * field.
   957      * <p>
   957      * <p>
   958      * Ths default is "sticky", being a part of the static state of all
   958      * Ths default is "sticky", being a part of the static state of all
   959      * URLConnections.  This flag applies to the next, and all following
   959      * URLConnections.  This flag applies to the next, and all following
   960      * URLConnections that are created.
   960      * URLConnections that are created.
   961      *
   961      *
   962      * @return  the default value of the <code>allowUserInteraction</code>
   962      * @return  the default value of the {@code allowUserInteraction}
   963      *          field.
   963      *          field.
   964      * @see     #setDefaultAllowUserInteraction(boolean)
   964      * @see     #setDefaultAllowUserInteraction(boolean)
   965      */
   965      */
   966     public static boolean getDefaultAllowUserInteraction() {
   966     public static boolean getDefaultAllowUserInteraction() {
   967         return defaultAllowUserInteraction;
   967         return defaultAllowUserInteraction;
   968     }
   968     }
   969 
   969 
   970     /**
   970     /**
   971      * Sets the value of the <code>useCaches</code> field of this
   971      * Sets the value of the {@code useCaches} field of this
   972      * <code>URLConnection</code> to the specified value.
   972      * {@code URLConnection} to the specified value.
   973      * <p>
   973      * <p>
   974      * Some protocols do caching of documents.  Occasionally, it is important
   974      * Some protocols do caching of documents.  Occasionally, it is important
   975      * to be able to "tunnel through" and ignore the caches (e.g., the
   975      * to be able to "tunnel through" and ignore the caches (e.g., the
   976      * "reload" button in a browser).  If the UseCaches flag on a connection
   976      * "reload" button in a browser).  If the UseCaches flag on a connection
   977      * is true, the connection is allowed to use whatever caches it can.
   977      * is true, the connection is allowed to use whatever caches it can.
   978      *  If false, caches are to be ignored.
   978      *  If false, caches are to be ignored.
   979      *  The default value comes from DefaultUseCaches, which defaults to
   979      *  The default value comes from DefaultUseCaches, which defaults to
   980      * true.
   980      * true.
   981      *
   981      *
   982      * @param usecaches a <code>boolean</code> indicating whether
   982      * @param usecaches a {@code boolean} indicating whether
   983      * or not to allow caching
   983      * or not to allow caching
   984      * @throws IllegalStateException if already connected
   984      * @throws IllegalStateException if already connected
   985      * @see #getUseCaches()
   985      * @see #getUseCaches()
   986      */
   986      */
   987     public void setUseCaches(boolean usecaches) {
   987     public void setUseCaches(boolean usecaches) {
   989             throw new IllegalStateException("Already connected");
   989             throw new IllegalStateException("Already connected");
   990         useCaches = usecaches;
   990         useCaches = usecaches;
   991     }
   991     }
   992 
   992 
   993     /**
   993     /**
   994      * Returns the value of this <code>URLConnection</code>'s
   994      * Returns the value of this {@code URLConnection}'s
   995      * <code>useCaches</code> field.
   995      * {@code useCaches} field.
   996      *
   996      *
   997      * @return  the value of this <code>URLConnection</code>'s
   997      * @return  the value of this {@code URLConnection}'s
   998      *          <code>useCaches</code> field.
   998      *          {@code useCaches} field.
   999      * @see #setUseCaches(boolean)
   999      * @see #setUseCaches(boolean)
  1000      */
  1000      */
  1001     public boolean getUseCaches() {
  1001     public boolean getUseCaches() {
  1002         return useCaches;
  1002         return useCaches;
  1003     }
  1003     }
  1004 
  1004 
  1005     /**
  1005     /**
  1006      * Sets the value of the <code>ifModifiedSince</code> field of
  1006      * Sets the value of the {@code ifModifiedSince} field of
  1007      * this <code>URLConnection</code> to the specified value.
  1007      * this {@code URLConnection} to the specified value.
  1008      *
  1008      *
  1009      * @param   ifmodifiedsince   the new value.
  1009      * @param   ifmodifiedsince   the new value.
  1010      * @throws IllegalStateException if already connected
  1010      * @throws IllegalStateException if already connected
  1011      * @see     #getIfModifiedSince()
  1011      * @see     #getIfModifiedSince()
  1012      */
  1012      */
  1015             throw new IllegalStateException("Already connected");
  1015             throw new IllegalStateException("Already connected");
  1016         ifModifiedSince = ifmodifiedsince;
  1016         ifModifiedSince = ifmodifiedsince;
  1017     }
  1017     }
  1018 
  1018 
  1019     /**
  1019     /**
  1020      * Returns the value of this object's <code>ifModifiedSince</code> field.
  1020      * Returns the value of this object's {@code ifModifiedSince} field.
  1021      *
  1021      *
  1022      * @return  the value of this object's <code>ifModifiedSince</code> field.
  1022      * @return  the value of this object's {@code ifModifiedSince} field.
  1023      * @see #setIfModifiedSince(long)
  1023      * @see #setIfModifiedSince(long)
  1024      */
  1024      */
  1025     public long getIfModifiedSince() {
  1025     public long getIfModifiedSince() {
  1026         return ifModifiedSince;
  1026         return ifModifiedSince;
  1027     }
  1027     }
  1028 
  1028 
  1029    /**
  1029    /**
  1030      * Returns the default value of a <code>URLConnection</code>'s
  1030      * Returns the default value of a {@code URLConnection}'s
  1031      * <code>useCaches</code> flag.
  1031      * {@code useCaches} flag.
  1032      * <p>
  1032      * <p>
  1033      * Ths default is "sticky", being a part of the static state of all
  1033      * Ths default is "sticky", being a part of the static state of all
  1034      * URLConnections.  This flag applies to the next, and all following
  1034      * URLConnections.  This flag applies to the next, and all following
  1035      * URLConnections that are created.
  1035      * URLConnections that are created.
  1036      *
  1036      *
  1037      * @return  the default value of a <code>URLConnection</code>'s
  1037      * @return  the default value of a {@code URLConnection}'s
  1038      *          <code>useCaches</code> flag.
  1038      *          {@code useCaches} flag.
  1039      * @see     #setDefaultUseCaches(boolean)
  1039      * @see     #setDefaultUseCaches(boolean)
  1040      */
  1040      */
  1041     public boolean getDefaultUseCaches() {
  1041     public boolean getDefaultUseCaches() {
  1042         return defaultUseCaches;
  1042         return defaultUseCaches;
  1043     }
  1043     }
  1044 
  1044 
  1045    /**
  1045    /**
  1046      * Sets the default value of the <code>useCaches</code> field to the
  1046      * Sets the default value of the {@code useCaches} field to the
  1047      * specified value.
  1047      * specified value.
  1048      *
  1048      *
  1049      * @param   defaultusecaches   the new value.
  1049      * @param   defaultusecaches   the new value.
  1050      * @see     #getDefaultUseCaches()
  1050      * @see     #getDefaultUseCaches()
  1051      */
  1051      */
  1061      * legally have multiple instances with the same key
  1061      * legally have multiple instances with the same key
  1062      * to use a comma-seperated list syntax which enables multiple
  1062      * to use a comma-seperated list syntax which enables multiple
  1063      * properties to be appended into a single property.
  1063      * properties to be appended into a single property.
  1064      *
  1064      *
  1065      * @param   key     the keyword by which the request is known
  1065      * @param   key     the keyword by which the request is known
  1066      *                  (e.g., "<code>Accept</code>").
  1066      *                  (e.g., "{@code Accept}").
  1067      * @param   value   the value associated with it.
  1067      * @param   value   the value associated with it.
  1068      * @throws IllegalStateException if already connected
  1068      * @throws IllegalStateException if already connected
  1069      * @throws NullPointerException if key is <CODE>null</CODE>
  1069      * @throws NullPointerException if key is <CODE>null</CODE>
  1070      * @see #getRequestProperty(java.lang.String)
  1070      * @see #getRequestProperty(java.lang.String)
  1071      */
  1071      */
  1085      * Adds a general request property specified by a
  1085      * Adds a general request property specified by a
  1086      * key-value pair.  This method will not overwrite
  1086      * key-value pair.  This method will not overwrite
  1087      * existing values associated with the same key.
  1087      * existing values associated with the same key.
  1088      *
  1088      *
  1089      * @param   key     the keyword by which the request is known
  1089      * @param   key     the keyword by which the request is known
  1090      *                  (e.g., "<code>Accept</code>").
  1090      *                  (e.g., "{@code Accept}").
  1091      * @param   value  the value associated with it.
  1091      * @param   value  the value associated with it.
  1092      * @throws IllegalStateException if already connected
  1092      * @throws IllegalStateException if already connected
  1093      * @throws NullPointerException if key is null
  1093      * @throws NullPointerException if key is null
  1094      * @see #getRequestProperties()
  1094      * @see #getRequestProperties()
  1095      * @since 1.4
  1095      * @since 1.4
  1149         return requests.getHeaders(null);
  1149         return requests.getHeaders(null);
  1150     }
  1150     }
  1151 
  1151 
  1152     /**
  1152     /**
  1153      * Sets the default value of a general request property. When a
  1153      * Sets the default value of a general request property. When a
  1154      * <code>URLConnection</code> is created, it is initialized with
  1154      * {@code URLConnection} is created, it is initialized with
  1155      * these properties.
  1155      * these properties.
  1156      *
  1156      *
  1157      * @param   key     the keyword by which the request is known
  1157      * @param   key     the keyword by which the request is known
  1158      *                  (e.g., "<code>Accept</code>").
  1158      *                  (e.g., "{@code Accept}").
  1159      * @param   value   the value associated with the key.
  1159      * @param   value   the value associated with the key.
  1160      *
  1160      *
  1161      * @see java.net.URLConnection#setRequestProperty(java.lang.String,java.lang.String)
  1161      * @see java.net.URLConnection#setRequestProperty(java.lang.String,java.lang.String)
  1162      *
  1162      *
  1163      * @deprecated The instance specific setRequestProperty method
  1163      * @deprecated The instance specific setRequestProperty method
  1195      * The ContentHandler factory.
  1195      * The ContentHandler factory.
  1196      */
  1196      */
  1197     static ContentHandlerFactory factory;
  1197     static ContentHandlerFactory factory;
  1198 
  1198 
  1199     /**
  1199     /**
  1200      * Sets the <code>ContentHandlerFactory</code> of an
  1200      * Sets the {@code ContentHandlerFactory} of an
  1201      * application. It can be called at most once by an application.
  1201      * application. It can be called at most once by an application.
  1202      * <p>
  1202      * <p>
  1203      * The <code>ContentHandlerFactory</code> instance is used to
  1203      * The {@code ContentHandlerFactory} instance is used to
  1204      * construct a content handler from a content type
  1204      * construct a content handler from a content type
  1205      * <p>
  1205      * <p>
  1206      * If there is a security manager, this method first calls
  1206      * If there is a security manager, this method first calls
  1207      * the security manager's <code>checkSetFactory</code> method
  1207      * the security manager's {@code checkSetFactory} method
  1208      * to ensure the operation is allowed.
  1208      * to ensure the operation is allowed.
  1209      * This could result in a SecurityException.
  1209      * This could result in a SecurityException.
  1210      *
  1210      *
  1211      * @param      fac   the desired factory.
  1211      * @param      fac   the desired factory.
  1212      * @exception  Error  if the factory has already been defined.
  1212      * @exception  Error  if the factory has already been defined.
  1213      * @exception  SecurityException  if a security manager exists and its
  1213      * @exception  SecurityException  if a security manager exists and its
  1214      *             <code>checkSetFactory</code> method doesn't allow the operation.
  1214      *             {@code checkSetFactory} method doesn't allow the operation.
  1215      * @see        java.net.ContentHandlerFactory
  1215      * @see        java.net.ContentHandlerFactory
  1216      * @see        java.net.URLConnection#getContent()
  1216      * @see        java.net.URLConnection#getContent()
  1217      * @see        SecurityManager#checkSetFactory
  1217      * @see        SecurityManager#checkSetFactory
  1218      */
  1218      */
  1219     public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
  1219     public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
  1372 
  1372 
  1373     /**
  1373     /**
  1374      * Tries to determine the content type of an object, based
  1374      * Tries to determine the content type of an object, based
  1375      * on the specified "file" component of a URL.
  1375      * on the specified "file" component of a URL.
  1376      * This is a convenience method that can be used by
  1376      * This is a convenience method that can be used by
  1377      * subclasses that override the <code>getContentType</code> method.
  1377      * subclasses that override the {@code getContentType} method.
  1378      *
  1378      *
  1379      * @param   fname   a filename.
  1379      * @param   fname   a filename.
  1380      * @return  a guess as to what the content type of the object is,
  1380      * @return  a guess as to what the content type of the object is,
  1381      *          based upon its file name.
  1381      *          based upon its file name.
  1382      * @see     java.net.URLConnection#getContentType()
  1382      * @see     java.net.URLConnection#getContentType()
  1387 
  1387 
  1388     /**
  1388     /**
  1389      * Tries to determine the type of an input stream based on the
  1389      * Tries to determine the type of an input stream based on the
  1390      * characters at the beginning of the input stream. This method can
  1390      * characters at the beginning of the input stream. This method can
  1391      * be used by subclasses that override the
  1391      * be used by subclasses that override the
  1392      * <code>getContentType</code> method.
  1392      * {@code getContentType} method.
  1393      * <p>
  1393      * <p>
  1394      * Ideally, this routine would not be needed. But many
  1394      * Ideally, this routine would not be needed. But many
  1395      * <code>http</code> servers return the incorrect content type; in
  1395      * {@code http} servers return the incorrect content type; in
  1396      * addition, there are many nonstandard extensions. Direct inspection
  1396      * addition, there are many nonstandard extensions. Direct inspection
  1397      * of the bytes to determine the content type is often more accurate
  1397      * of the bytes to determine the content type is often more accurate
  1398      * than believing the content type claimed by the <code>http</code> server.
  1398      * than believing the content type claimed by the {@code http} server.
  1399      *
  1399      *
  1400      * @param      is   an input stream that supports marks.
  1400      * @param      is   an input stream that supports marks.
  1401      * @return     a guess at the content type, or <code>null</code> if none
  1401      * @return     a guess at the content type, or {@code null} if none
  1402      *             can be determined.
  1402      *             can be determined.
  1403      * @exception  IOException  if an I/O error occurs while reading the
  1403      * @exception  IOException  if an I/O error occurs while reading the
  1404      *               input stream.
  1404      *               input stream.
  1405      * @see        java.io.InputStream#mark(int)
  1405      * @see        java.io.InputStream#mark(int)
  1406      * @see        java.io.InputStream#markSupported()
  1406      * @see        java.io.InputStream#markSupported()