Source Home >> Java Source 1.6.0 >> java.net.URLConnection V 0.09
  • 0001/*
  • 0002 * @(#)URLConnection.java 1.106 06/06/28
  • 0003 *
  • 0004 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  • 0005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  • 0006 */
  • 0007
  • 0008package java.net;
  • 0009
  • 0010import java.io.IOException;
  • 0011import java.io.InputStream;
  • 0012import java.io.OutputStream;
  • 0013import java.util.Hashtable;
  • 0014import java.util.Date;
  • 0015import java.util.StringTokenizer;
  • 0016import java.util.Collections;
  • 0017import java.util.Map;
  • 0018import java.util.List;
  • 0019import java.security.Permission;
  • 0020import java.security.AccessController;
  • 0021import sun.security.util.SecurityConstants;
  • 0022import sun.net.www.MessageHeader;
  • 0023
  • 0024/**
  • 0025 * The abstract class <code>URLConnection</code> is the superclass
  • 0026 * of all classes that represent a communications link between the
  • 0027 * application and a URL. Instances of this class can be used both to
  • 0028 * read from and to write to the resource referenced by the URL. In
  • 0029 * general, creating a connection to a URL is a multistep process:
  • 0030 * <p>
  • 0031 * <center><table border=2 summary="Describes the process of creating a connection to a URL: openConnection() and connect() over time.">
  • 0032 * <tr><th><code>openConnection()</code></th>
  • 0033 * <th><code>connect()</code></th></tr>
  • 0034 * <tr><td>Manipulate parameters that affect the connection to the remote
  • 0035 * resource.</td>
  • 0036 * <td>Interact with the resource; query header fields and
  • 0037 * contents.</td></tr>
  • 0038 * </table>
  • 0039 * ---------------------------->
  • 0040 * <br>time</center>
  • 0041 *
  • 0042 * <ol>
  • 0043 * <li>The connection object is created by invoking the
  • 0044 * <code>openConnection</code> method on a URL.
  • 0045 * <li>The setup parameters and general request properties are manipulated.
  • 0046 * <li>The actual connection to the remote object is made, using the
  • 0047 * <code>connect</code> method.
  • 0048 * <li>The remote object becomes available. The header fields and the contents
  • 0049 * of the remote object can be accessed.
  • 0050 * </ol>
  • 0051 * <p>
  • 0052 * The setup parameters are modified using the following methods:
  • 0053 * <ul>
  • 0054 * <li><code>setAllowUserInteraction</code>
  • 0055 * <li><code>setDoInput</code>
  • 0056 * <li><code>setDoOutput</code>
  • 0057 * <li><code>setIfModifiedSince</code>
  • 0058 * <li><code>setUseCaches</code>
  • 0059 * </ul>
  • 0060 * <p>
  • 0061 * and the general request properties are modified using the method:
  • 0062 * <ul>
  • 0063 * <li><code>setRequestProperty</code>
  • 0064 * </ul>
  • 0065 * <p>
  • 0066 * Default values for the <code>AllowUserInteraction</code> and
  • 0067 * <code>UseCaches</code> parameters can be set using the methods
  • 0068 * <code>setDefaultAllowUserInteraction</code> and
  • 0069 * <code>setDefaultUseCaches</code>.
  • 0070 * <p>
  • 0071 * Each of the above <code>set</code> methods has a corresponding
  • 0072 * <code>get</code> method to retrieve the value of the parameter or
  • 0073 * general request property. The specific parameters and general
  • 0074 * request properties that are applicable are protocol specific.
  • 0075 * <p>
  • 0076 * The following methods are used to access the header fields and
  • 0077 * the contents after the connection is made to the remote object:
  • 0078 * <ul>
  • 0079 * <li><code>getContent</code>
  • 0080 * <li><code>getHeaderField</code>
  • 0081 * <li><code>getInputStream</code>
  • 0082 * <li><code>getOutputStream</code>
  • 0083 * </ul>
  • 0084 * <p>
  • 0085 * Certain header fields are accessed frequently. The methods:
  • 0086 * <ul>
  • 0087 * <li><code>getContentEncoding</code>
  • 0088 * <li><code>getContentLength</code>
  • 0089 * <li><code>getContentType</code>
  • 0090 * <li><code>getDate</code>
  • 0091 * <li><code>getExpiration</code>
  • 0092 * <li><code>getLastModifed</code>
  • 0093 * </ul>
  • 0094 * <p>
  • 0095 * provide convenient access to these fields. The
  • 0096 * <code>getContentType</code> method is used by the
  • 0097 * <code>getContent</code> method to determine the type of the remote
  • 0098 * object; subclasses may find it convenient to override the
  • 0099 * <code>getContentType</code> method.
  • 0100 * <p>
  • 0101 * In the common case, all of the pre-connection parameters and
  • 0102 * general request properties can be ignored: the pre-connection
  • 0103 * parameters and request properties default to sensible values. For
  • 0104 * most clients of this interface, there are only two interesting
  • 0105 * methods: <code>getInputStream</code> and <code>getContent</code>,
  • 0106 * which are mirrored in the <code>URL</code> class by convenience methods.
  • 0107 * <p>
  • 0108 * More information on the request properties and header fields of
  • 0109 * an <code>http</code> connection can be found at:
  • 0110 * <blockquote><pre>
  • 0111 * <a href="http://www.ietf.org/rfc/rfc2068.txt">http://www.ietf.org/rfc/rfc2068.txt</a>
  • 0112 * </pre></blockquote>
  • 0113 *
  • 0114 * Note about <code>fileNameMap</code>: In versions prior to JDK 1.1.6,
  • 0115 * field <code>fileNameMap</code> of <code>URLConnection</code> was public.
  • 0116 * In JDK 1.1.6 and later, <code>fileNameMap</code> is private; accessor
  • 0117 * and mutator methods {@link #getFileNameMap() getFileNameMap} and
  • 0118 * {@link #setFileNameMap(java.net.FileNameMap) setFileNameMap} are added
  • 0119 * to access it. This change is also described on the <a href=
  • 0120 * "http://java.sun.com/products/jdk/1.2/compatibility.html">
  • 0121 * Compatibility</a> page.
  • 0122 *
  • 0123 * Invoking the <tt>close()</tt> methods on the <tt>InputStream</tt> or <tt>OutputStream</tt> of an
  • 0124 * <tt>URLConnection</tt> after a request may free network resources associated with this
  • 0125 * instance, unless particular protocol specifications specify different behaviours
  • 0126 * for it.
  • 0127 *
  • 0128 * @author James Gosling
  • 0129 * @version 1.106, 06/28/06
  • 0130 * @see java.net.URL#openConnection()
  • 0131 * @see java.net.URLConnection#connect()
  • 0132 * @see java.net.URLConnection#getContent()
  • 0133 * @see java.net.URLConnection#getContentEncoding()
  • 0134 * @see java.net.URLConnection#getContentLength()
  • 0135 * @see java.net.URLConnection#getContentType()
  • 0136 * @see java.net.URLConnection#getDate()
  • 0137 * @see java.net.URLConnection#getExpiration()
  • 0138 * @see java.net.URLConnection#getHeaderField(int)
  • 0139 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0140 * @see java.net.URLConnection#getInputStream()
  • 0141 * @see java.net.URLConnection#getLastModified()
  • 0142 * @see java.net.URLConnection#getOutputStream()
  • 0143 * @see java.net.URLConnection#setAllowUserInteraction(boolean)
  • 0144 * @see java.net.URLConnection#setDefaultUseCaches(boolean)
  • 0145 * @see java.net.URLConnection#setDoInput(boolean)
  • 0146 * @see java.net.URLConnection#setDoOutput(boolean)
  • 0147 * @see java.net.URLConnection#setIfModifiedSince(long)
  • 0148 * @see java.net.URLConnection#setRequestProperty(java.lang.String, java.lang.String)
  • 0149 * @see java.net.URLConnection#setUseCaches(boolean)
  • 0150 * @since JDK1.0
  • 0151 */
  • 0152public abstract class URLConnection {
  • 0153
  • 0154 /**
  • 0155 * The URL represents the remote object on the World Wide Web to
  • 0156 * which this connection is opened.
  • 0157 * <p>
  • 0158 * The value of this field can be accessed by the
  • 0159 * <code>getURL</code> method.
  • 0160 * <p>
  • 0161 * The default value of this variable is the value of the URL
  • 0162 * argument in the <code>URLConnection</code> constructor.
  • 0163 *
  • 0164 * @see java.net.URLConnection#getURL()
  • 0165 * @see java.net.URLConnection#url
  • 0166 */
  • 0167 protected URL url;
  • 0168
  • 0169 /**
  • 0170 * This variable is set by the <code>setDoInput</code> method. Its
  • 0171 * value is returned by the <code>getDoInput</code> method.
  • 0172 * <p>
  • 0173 * A URL connection can be used for input and/or output. Setting the
  • 0174 * <code>doInput</code> flag to <code>true</code> indicates that
  • 0175 * the application intends to read data from the URL connection.
  • 0176 * <p>
  • 0177 * The default value of this field is <code>true</code>.
  • 0178 *
  • 0179 * @see java.net.URLConnection#getDoInput()
  • 0180 * @see java.net.URLConnection#setDoInput(boolean)
  • 0181 */
  • 0182 protected boolean doInput = true;
  • 0183
  • 0184 /**
  • 0185 * This variable is set by the <code>setDoOutput</code> method. Its
  • 0186 * value is returned by the <code>getDoOutput</code> method.
  • 0187 * <p>
  • 0188 * A URL connection can be used for input and/or output. Setting the
  • 0189 * <code>doOutput</code> flag to <code>true</code> indicates
  • 0190 * that the application intends to write data to the URL connection.
  • 0191 * <p>
  • 0192 * The default value of this field is <code>false</code>.
  • 0193 *
  • 0194 * @see java.net.URLConnection#getDoOutput()
  • 0195 * @see java.net.URLConnection#setDoOutput(boolean)
  • 0196 */
  • 0197 protected boolean doOutput = false;
  • 0198
  • 0199 private static boolean defaultAllowUserInteraction = false;
  • 0200
  • 0201 /**
  • 0202 * If <code>true</code>, this <code>URL</code> is being examined in
  • 0203 * a context in which it makes sense to allow user interactions such
  • 0204 * as popping up an authentication dialog. If <code>false</code>,
  • 0205 * then no user interaction is allowed.
  • 0206 * <p>
  • 0207 * The value of this field can be set by the
  • 0208 * <code>setAllowUserInteraction</code> method.
  • 0209 * Its value is returned by the
  • 0210 * <code>getAllowUserInteraction</code> method.
  • 0211 * Its default value is the value of the argument in the last invocation
  • 0212 * of the <code>setDefaultAllowUserInteraction</code> method.
  • 0213 *
  • 0214 * @see java.net.URLConnection#getAllowUserInteraction()
  • 0215 * @see java.net.URLConnection#setAllowUserInteraction(boolean)
  • 0216 * @see java.net.URLConnection#setDefaultAllowUserInteraction(boolean)
  • 0217 */
  • 0218 protected boolean allowUserInteraction = defaultAllowUserInteraction;
  • 0219
  • 0220 private static boolean defaultUseCaches = true;
  • 0221
  • 0222 /**
  • 0223 * If <code>true</code>, the protocol is allowed to use caching
  • 0224 * whenever it can. If <code>false</code>, the protocol must always
  • 0225 * try to get a fresh copy of the object.
  • 0226 * <p>
  • 0227 * This field is set by the <code>setUseCaches</code> method. Its
  • 0228 * value is returned by the <code>getUseCaches</code> method.
  • 0229 * <p>
  • 0230 * Its default value is the value given in the last invocation of the
  • 0231 * <code>setDefaultUseCaches</code> method.
  • 0232 *
  • 0233 * @see java.net.URLConnection#setUseCaches(boolean)
  • 0234 * @see java.net.URLConnection#getUseCaches()
  • 0235 * @see java.net.URLConnection#setDefaultUseCaches(boolean)
  • 0236 */
  • 0237 protected boolean useCaches = defaultUseCaches;
  • 0238
  • 0239 /**
  • 0240 * Some protocols support skipping the fetching of the object unless
  • 0241 * the object has been modified more recently than a certain time.
  • 0242 * <p>
  • 0243 * A nonzero value gives a time as the number of milliseconds since
  • 0244 * January 1, 1970, GMT. The object is fetched only if it has been
  • 0245 * modified more recently than that time.
  • 0246 * <p>
  • 0247 * This variable is set by the <code>setIfModifiedSince</code>
  • 0248 * method. Its value is returned by the
  • 0249 * <code>getIfModifiedSince</code> method.
  • 0250 * <p>
  • 0251 * The default value of this field is <code>0</code>, indicating
  • 0252 * that the fetching must always occur.
  • 0253 *
  • 0254 * @see java.net.URLConnection#getIfModifiedSince()
  • 0255 * @see java.net.URLConnection#setIfModifiedSince(long)
  • 0256 */
  • 0257 protected long ifModifiedSince = 0;
  • 0258
  • 0259 /**
  • 0260 * If <code>false</code>, this connection object has not created a
  • 0261 * communications link to the specified URL. If <code>true</code>,
  • 0262 * the communications link has been established.
  • 0263 */
  • 0264 protected boolean connected = false;
  • 0265
  • 0266 /**
  • 0267 * @since 1.5
  • 0268 */
  • 0269 private int connectTimeout;
  • 0270 private int readTimeout;
  • 0271
  • 0272 /**
  • 0273 * @since 1.6
  • 0274 */
  • 0275 private MessageHeader requests;
  • 0276
  • 0277 /**
  • 0278 * @since JDK1.1
  • 0279 */
  • 0280 private static FileNameMap fileNameMap;
  • 0281
  • 0282 /**
  • 0283 * @since 1.2.2
  • 0284 */
  • 0285 private static boolean fileNameMapLoaded = false;
  • 0286
  • 0287 /**
  • 0288 * Loads filename map (a mimetable) from a data file. It will
  • 0289 * first try to load the user-specific table, defined
  • 0290 * by "content.types.user.table" property. If that fails,
  • 0291 * it tries to load the default built-in table at
  • 0292 * lib/content-types.properties under java home.
  • 0293 *
  • 0294 * @return the FileNameMap
  • 0295 * @since 1.2
  • 0296 * @see #setFileNameMap(java.net.FileNameMap)
  • 0297 */
  • 0298 public static synchronized FileNameMap getFileNameMap() {
  • 0299 if ((fileNameMap == null) && !fileNameMapLoaded) {
  • 0300 fileNameMap = sun.net.www.MimeTable.loadTable();
  • 0301 fileNameMapLoaded = true;
  • 0302 }
  • 0303
  • 0304 return new FileNameMap() {
  • 0305 private FileNameMap map = fileNameMap;
  • 0306 public String getContentTypeFor(String fileName) {
  • 0307 return map.getContentTypeFor(fileName);
  • 0308 }
  • 0309 };
  • 0310 }
  • 0311
  • 0312 /**
  • 0313 * Sets the FileNameMap.
  • 0314 * <p>
  • 0315 * If there is a security manager, this method first calls
  • 0316 * the security manager's <code>checkSetFactory</code> method
  • 0317 * to ensure the operation is allowed.
  • 0318 * This could result in a SecurityException.
  • 0319 *
  • 0320 * @param map the FileNameMap to be set
  • 0321 * @exception SecurityException if a security manager exists and its
  • 0322 * <code>checkSetFactory</code> method doesn't allow the operation.
  • 0323 * @see SecurityManager#checkSetFactory
  • 0324 * @see #getFileNameMap()
  • 0325 * @since 1.2
  • 0326 */
  • 0327 public static void setFileNameMap(FileNameMap map) {
  • 0328 SecurityManager sm = System.getSecurityManager();
  • 0329 if (sm != null) sm.checkSetFactory();
  • 0330 fileNameMap = map;
  • 0331 }
  • 0332
  • 0333 /**
  • 0334 * Opens a communications link to the resource referenced by this
  • 0335 * URL, if such a connection has not already been established.
  • 0336 * <p>
  • 0337 * If the <code>connect</code> method is called when the connection
  • 0338 * has already been opened (indicated by the <code>connected</code>
  • 0339 * field having the value <code>true</code>), the call is ignored.
  • 0340 * <p>
  • 0341 * URLConnection objects go through two phases: first they are
  • 0342 * created, then they are connected. After being created, and
  • 0343 * before being connected, various options can be specified
  • 0344 * (e.g., doInput and UseCaches). After connecting, it is an
  • 0345 * error to try to set them. Operations that depend on being
  • 0346 * connected, like getContentLength, will implicitly perform the
  • 0347 * connection, if necessary.
  • 0348 *
  • 0349 * @throws SocketTimeoutException if the timeout expires before
  • 0350 * the connection can be established
  • 0351 * @exception IOException if an I/O error occurs while opening the
  • 0352 * connection.
  • 0353 * @see java.net.URLConnection#connected
  • 0354 * @see #getConnectTimeout()
  • 0355 * @see #setConnectTimeout(int)
  • 0356 */
  • 0357 abstract public void connect() throws IOException;
  • 0358
  • 0359 /**
  • 0360 * Sets a specified timeout value, in milliseconds, to be used
  • 0361 * when opening a communications link to the resource referenced
  • 0362 * by this URLConnection. If the timeout expires before the
  • 0363 * connection can be established, a
  • 0364 * java.net.SocketTimeoutException is raised. A timeout of zero is
  • 0365 * interpreted as an infinite timeout.
  • 0366
  • 0367 * <p> Some non-standard implmentation of this method may ignore
  • 0368 * the specified timeout. To see the connect timeout set, please
  • 0369 * call getConnectTimeout().
  • 0370 *
  • 0371 * @param timeout an <code>int</code> that specifies the connect
  • 0372 * timeout value in milliseconds
  • 0373 * @throws IllegalArgumentException if the timeout parameter is negative
  • 0374 *
  • 0375 * @see #getConnectTimeout()
  • 0376 * @see #connect()
  • 0377 * @since 1.5
  • 0378 */
  • 0379 public void setConnectTimeout(int timeout) {
  • 0380 if (timeout < 0) {
  • 0381 throw new IllegalArgumentException("timeout can not be negative");
  • 0382 }
  • 0383 connectTimeout = timeout;
  • 0384 }
  • 0385
  • 0386 /**
  • 0387 * Returns setting for connect timeout.
  • 0388 * <p>
  • 0389 * 0 return implies that the option is disabled
  • 0390 * (i.e., timeout of infinity).
  • 0391 *
  • 0392 * @return an <code>int</code> that indicates the connect timeout
  • 0393 * value in milliseconds
  • 0394 * @see #setConnectTimeout(int)
  • 0395 * @see #connect()
  • 0396 * @since 1.5
  • 0397 */
  • 0398 public int getConnectTimeout() {
  • 0399 return connectTimeout;
  • 0400 }
  • 0401
  • 0402 /**
  • 0403 * Sets the read timeout to a specified timeout, in
  • 0404 * milliseconds. A non-zero value specifies the timeout when
  • 0405 * reading from Input stream when a connection is established to a
  • 0406 * resource. If the timeout expires before there is data available
  • 0407 * for read, a java.net.SocketTimeoutException is raised. A
  • 0408 * timeout of zero is interpreted as an infinite timeout.
  • 0409 *
  • 0410 *<p> Some non-standard implementation of this method ignores the
  • 0411 * specified timeout. To see the read timeout set, please call
  • 0412 * getReadTimeout().
  • 0413 *
  • 0414 * @param timeout an <code>int</code> that specifies the timeout
  • 0415 * value to be used in milliseconds
  • 0416 * @throws IllegalArgumentException if the timeout parameter is negative
  • 0417 *
  • 0418 * @see #getReadTimeout()
  • 0419 * @see InputStream#read()
  • 0420 * @since 1.5
  • 0421 */
  • 0422 public void setReadTimeout(int timeout) {
  • 0423 if (timeout < 0) {
  • 0424 throw new IllegalArgumentException("timeout can not be negative");
  • 0425 }
  • 0426 readTimeout = timeout;
  • 0427 }
  • 0428
  • 0429 /**
  • 0430 * Returns setting for read timeout. 0 return implies that the
  • 0431 * option is disabled (i.e., timeout of infinity).
  • 0432 *
  • 0433 * @return an <code>int</code> that indicates the read timeout
  • 0434 * value in milliseconds
  • 0435 *
  • 0436 * @see #setReadTimeout(int)
  • 0437 * @see InputStream#read()
  • 0438 * @since 1.5
  • 0439 */
  • 0440 public int getReadTimeout() {
  • 0441 return readTimeout;
  • 0442 }
  • 0443
  • 0444 /**
  • 0445 * Constructs a URL connection to the specified URL. A connection to
  • 0446 * the object referenced by the URL is not created.
  • 0447 *
  • 0448 * @param url the specified URL.
  • 0449 */
  • 0450 protected URLConnection(URL url) {
  • 0451 this.url = url;
  • 0452 }
  • 0453
  • 0454 /**
  • 0455 * Returns the value of this <code>URLConnection</code>'s <code>URL</code>
  • 0456 * field.
  • 0457 *
  • 0458 * @return the value of this <code>URLConnection</code>'s <code>URL</code>
  • 0459 * field.
  • 0460 * @see java.net.URLConnection#url
  • 0461 */
  • 0462 public URL getURL() {
  • 0463 return url;
  • 0464 }
  • 0465
  • 0466 /**
  • 0467 * Returns the value of the <code>content-length</code> header field.
  • 0468 *
  • 0469 * @return the content length of the resource that this connection's URL
  • 0470 * references, or <code>-1</code> if the content length is
  • 0471 * not known.
  • 0472 */
  • 0473 public int getContentLength() {
  • 0474 return getHeaderFieldInt("content-length", -1);
  • 0475 }
  • 0476
  • 0477 /**
  • 0478 * Returns the value of the <code>content-type</code> header field.
  • 0479 *
  • 0480 * @return the content type of the resource that the URL references,
  • 0481 * or <code>null</code> if not known.
  • 0482 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0483 */
  • 0484 public String getContentType() {
  • 0485 return getHeaderField("content-type");
  • 0486 }
  • 0487
  • 0488 /**
  • 0489 * Returns the value of the <code>content-encoding</code> header field.
  • 0490 *
  • 0491 * @return the content encoding of the resource that the URL references,
  • 0492 * or <code>null</code> if not known.
  • 0493 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0494 */
  • 0495 public String getContentEncoding() {
  • 0496 return getHeaderField("content-encoding");
  • 0497 }
  • 0498
  • 0499 /**
  • 0500 * Returns the value of the <code>expires</code> header field.
  • 0501 *
  • 0502 * @return the expiration date of the resource that this URL references,
  • 0503 * or 0 if not known. The value is the number of milliseconds since
  • 0504 * January 1, 1970 GMT.
  • 0505 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0506 */
  • 0507 public long getExpiration() {
  • 0508 return getHeaderFieldDate("expires", 0);
  • 0509 }
  • 0510
  • 0511 /**
  • 0512 * Returns the value of the <code>date</code> header field.
  • 0513 *
  • 0514 * @return the sending date of the resource that the URL references,
  • 0515 * or <code>0</code> if not known. The value returned is the
  • 0516 * number of milliseconds since January 1, 1970 GMT.
  • 0517 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0518 */
  • 0519 public long getDate() {
  • 0520 return getHeaderFieldDate("date", 0);
  • 0521 }
  • 0522
  • 0523 /**
  • 0524 * Returns the value of the <code>last-modified</code> header field.
  • 0525 * The result is the number of milliseconds since January 1, 1970 GMT.
  • 0526 *
  • 0527 * @return the date the resource referenced by this
  • 0528 * <code>URLConnection</code> was last modified, or 0 if not known.
  • 0529 * @see java.net.URLConnection#getHeaderField(java.lang.String)
  • 0530 */
  • 0531 public long getLastModified() {
  • 0532 return getHeaderFieldDate("last-modified", 0);
  • 0533 }
  • 0534
  • 0535 /**
  • 0536 * Returns the value of the named header field.
  • 0537 * <p>
  • 0538 * If called on a connection that sets the same header multiple times
  • 0539 * with possibly different values, only the last value is returned.
  • 0540 *
  • 0541 *
  • 0542 * @param name the name of a header field.
  • 0543 * @return the value of the named header field, or <code>null</code>
  • 0544 * if there is no such field in the header.
  • 0545 */
  • 0546 public String getHeaderField(String name) {
  • 0547 return null;
  • 0548 }
  • 0549
  • 0550 /**
  • 0551 * Returns an unmodifiable Map of the header fields.
  • 0552 * The Map keys are Strings that represent the
  • 0553 * response-header field names. Each Map value is an
  • 0554 * unmodifiable List of Strings that represents
  • 0555 * the corresponding field values.
  • 0556 *
  • 0557 * @return a Map of header fields
  • 0558 * @since 1.4
  • 0559 */
  • 0560 public Map<String,List<String>> getHeaderFields() {
  • 0561 return Collections.EMPTY_MAP;
  • 0562 }
  • 0563
  • 0564 /**
  • 0565 * Returns the value of the named field parsed as a number.
  • 0566 * <p>
  • 0567 * This form of <code>getHeaderField</code> exists because some
  • 0568 * connection types (e.g., <code>http-ng</code>) have pre-parsed
  • 0569 * headers. Classes for that connection type can override this method
  • 0570 * and short-circuit the parsing.
  • 0571 *
  • 0572 * @param name the name of the header field.
  • 0573 * @param Default the default value.
  • 0574 * @return the value of the named field, parsed as an integer. The
  • 0575 * <code>Default</code> value is returned if the field is
  • 0576 * missing or malformed.
  • 0577 */
  • 0578 public int getHeaderFieldInt(String name, int Default) {
  • 0579 String value = getHeaderField(name);
  • 0580 try {
  • 0581 return Integer.parseInt(value);
  • 0582 } catch (Exception e) { }
  • 0583 return Default;
  • 0584 }
  • 0585
  • 0586 /**
  • 0587 * Returns the value of the named field parsed as date.
  • 0588 * The result is the number of milliseconds since January 1, 1970 GMT
  • 0589 * represented by the named field.
  • 0590 * <p>
  • 0591 * This form of <code>getHeaderField</code> exists because some
  • 0592 * connection types (e.g., <code>http-ng</code>) have pre-parsed
  • 0593 * headers. Classes for that connection type can override this method
  • 0594 * and short-circuit the parsing.
  • 0595 *
  • 0596 * @param name the name of the header field.
  • 0597 * @param Default a default value.
  • 0598 * @return the value of the field, parsed as a date. The value of the
  • 0599 * <code>Default</code> argument is returned if the field is
  • 0600 * missing or malformed.
  • 0601 */
  • 0602 public long getHeaderFieldDate(String name, long Default) {
  • 0603 String value = getHeaderField(name);
  • 0604 try {
  • 0605 return Date.parse(value);
  • 0606 } catch (Exception e) { }
  • 0607 return Default;
  • 0608 }
  • 0609
  • 0610 /**
  • 0611 * Returns the key for the <code>n</code><sup>th</sup> header field.
  • 0612 * It returns <code>null</code> if there are fewer than <code>n+1</code> fields.
  • 0613 *
  • 0614 * @param n an index, where n>=0
  • 0615 * @return the key for the <code>n</code><sup>th</sup> header field,
  • 0616 * or <code>null</code> if there are fewer than <code>n+1</code>
  • 0617 * fields.
  • 0618 */
  • 0619 public String getHeaderFieldKey(int n) {
  • 0620 return null;
  • 0621 }
  • 0622
  • 0623 /**
  • 0624 * Returns the value for the <code>n</code><sup>th</sup> header field.
  • 0625 * It returns <code>null</code> if there are fewer than
  • 0626 * <code>n+1</code>fields.
  • 0627 * <p>
  • 0628 * This method can be used in conjunction with the
  • 0629 * {@link #getHeaderFieldKey(int) getHeaderFieldKey} method to iterate through all
  • 0630 * the headers in the message.
  • 0631 *
  • 0632 * @param n an index, where n>=0
  • 0633 * @return the value of the <code>n</code><sup>th</sup> header field
  • 0634 * or <code>null</code> if there are fewer than <code>n+1</code> fields
  • 0635 * @see java.net.URLConnection#getHeaderFieldKey(int)
  • 0636 */
  • 0637 public String getHeaderField(int n) {
  • 0638 return null;
  • 0639 }
  • 0640
  • 0641 /**
  • 0642 * Retrieves the contents of this URL connection.
  • 0643 * <p>
  • 0644 * This method first determines the content type of the object by
  • 0645 * calling the <code>getContentType</code> method. If this is
  • 0646 * the first time that the application has seen that specific content
  • 0647 * type, a content handler for that content type is created:
  • 0648 * <ol>
  • 0649 * <li>If the application has set up a content handler factory instance
  • 0650 * using the <code>setContentHandlerFactory</code> method, the
  • 0651 * <code>createContentHandler</code> method of that instance is called
  • 0652 * with the content type as an argument; the result is a content
  • 0653 * handler for that content type.
  • 0654 * <li>If no content handler factory has yet been set up, or if the
  • 0655 * factory's <code>createContentHandler</code> method returns
  • 0656 * <code>null</code>, then the application loads the class named:
  • 0657 * <blockquote><pre>
  • 0658 * sun.net.www.content.<<i>contentType</i>>
  • 0659 * </pre></blockquote>
  • 0660 * where <<i>contentType</i>> is formed by taking the
  • 0661 * content-type string, replacing all slash characters with a
  • 0662 * <code>period</code> ('.'), and all other non-alphanumeric characters
  • 0663 * with the underscore character '<code>_</code>'. The alphanumeric
  • 0664 * characters are specifically the 26 uppercase ASCII letters
  • 0665 * '<code>A</code>' through '<code>Z</code>', the 26 lowercase ASCII
  • 0666 * letters '<code>a</code>' through '<code>z</code>', and the 10 ASCII
  • 0667 * digits '<code>0</code>' through '<code>9</code>'. If the specified
  • 0668 * class does not exist, or is not a subclass of
  • 0669 * <code>ContentHandler</code>, then an
  • 0670 * <code>UnknownServiceException</code> is thrown.
  • 0671 * </ol>
  • 0672 *
  • 0673 * @return the object fetched. The <code>instanceof</code> operator
  • 0674 * should be used to determine the specific kind of object
  • 0675 * returned.
  • 0676 * @exception IOException if an I/O error occurs while
  • 0677 * getting the content.
  • 0678 * @exception UnknownServiceException if the protocol does not support
  • 0679 * the content type.
  • 0680 * @see java.net.ContentHandlerFactory#createContentHandler(java.lang.String)
  • 0681 * @see java.net.URLConnection#getContentType()
  • 0682 * @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory)
  • 0683 */
  • 0684 public Object getContent() throws IOException {
  • 0685 // Must call getInputStream before GetHeaderField gets called
  • 0686 // so that FileNotFoundException has a chance to be thrown up
  • 0687 // from here without being caught.
  • 0688 getInputStream();
  • 0689 return getContentHandler().getContent(this);
  • 0690 }
  • 0691
  • 0692 /**
  • 0693 * Retrieves the contents of this URL connection.
  • 0694 *
  • 0695 * @param classes the <code>Class</code> array
  • 0696 * indicating the requested types
  • 0697 * @return the object fetched that is the first match of the type
  • 0698 * specified in the classes array. null if none of
  • 0699 * the requested types are supported.
  • 0700 * The <code>instanceof</code> operator should be used to
  • 0701 * determine the specific kind of object returned.
  • 0702 * @exception IOException if an I/O error occurs while
  • 0703 * getting the content.
  • 0704 * @exception UnknownServiceException if the protocol does not support
  • 0705 * the content type.
  • 0706 * @see java.net.URLConnection#getContent()
  • 0707 * @see java.net.ContentHandlerFactory#createContentHandler(java.lang.String)
  • 0708 * @see java.net.URLConnection#getContent(java.lang.Class[])
  • 0709 * @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory)
  • 0710 * @since 1.3
  • 0711 */
  • 0712 public Object getContent(Class[] classes) throws IOException {
  • 0713 // Must call getInputStream before GetHeaderField gets called
  • 0714 // so that FileNotFoundException has a chance to be thrown up
  • 0715 // from here without being caught.
  • 0716 getInputStream();
  • 0717 return getContentHandler().getContent(this, classes);
  • 0718 }
  • 0719
  • 0720 /**
  • 0721 * Returns a permission object representing the permission
  • 0722 * necessary to make the connection represented by this
  • 0723 * object. This method returns null if no permission is
  • 0724 * required to make the connection. By default, this method
  • 0725 * returns <code>java.security.AllPermission</code>. Subclasses
  • 0726 * should override this method and return the permission
  • 0727 * that best represents the permission required to make a
  • 0728 * a connection to the URL. For example, a <code>URLConnection</code>
  • 0729 * representing a <code>file:</code> URL would return a
  • 0730 * <code>java.io.FilePermission</code> object.
  • 0731 *
  • 0732 * <p>The permission returned may dependent upon the state of the
  • 0733 * connection. For example, the permission before connecting may be
  • 0734 * different from that after connecting. For example, an HTTP
  • 0735 * sever, say foo.com, may redirect the connection to a different
  • 0736 * host, say bar.com. Before connecting the permission returned by
  • 0737 * the connection will represent the permission needed to connect
  • 0738 * to foo.com, while the permission returned after connecting will
  • 0739 * be to bar.com.
  • 0740 *
  • 0741 * <p>Permissions are generally used for two purposes: to protect
  • 0742 * caches of objects obtained through URLConnections, and to check
  • 0743 * the right of a recipient to learn about a particular URL. In
  • 0744 * the first case, the permission should be obtained
  • 0745 * <em>after</em> the object has been obtained. For example, in an
  • 0746 * HTTP connection, this will represent the permission to connect
  • 0747 * to the host from which the data was ultimately fetched. In the
  • 0748 * second case, the permission should be obtained and tested
  • 0749 * <em>before</em> connecting.
  • 0750 *
  • 0751 * @return the permission object representing the permission
  • 0752 * necessary to make the connection represented by this
  • 0753 * URLConnection.
  • 0754 *
  • 0755 * @exception IOException if the computation of the permission
  • 0756 * requires network or file I/O and an exception occurs while
  • 0757 * computing it.
  • 0758 */
  • 0759 public Permission getPermission() throws IOException {
  • 0760 return SecurityConstants.ALL_PERMISSION;
  • 0761 }
  • 0762
  • 0763 /**
  • 0764 * Returns an input stream that reads from this open connection.
  • 0765 *
  • 0766 * A SocketTimeoutException can be thrown when reading from the
  • 0767 * returned input stream if the read timeout expires before data
  • 0768 * is available for read.
  • 0769 *
  • 0770 * @return an input stream that reads from this open connection.
  • 0771 * @exception IOException if an I/O error occurs while
  • 0772 * creating the input stream.
  • 0773 * @exception UnknownServiceException if the protocol does not support
  • 0774 * input.
  • 0775 * @see #setReadTimeout(int)
  • 0776 * @see #getReadTimeout()
  • 0777 */
  • 0778 public InputStream getInputStream() throws IOException {
  • 0779 throw new UnknownServiceException("protocol doesn't support input");
  • 0780 }
  • 0781
  • 0782 /**
  • 0783 * Returns an output stream that writes to this connection.
  • 0784 *
  • 0785 * @return an output stream that writes to this connection.
  • 0786 * @exception IOException if an I/O error occurs while
  • 0787 * creating the output stream.
  • 0788 * @exception UnknownServiceException if the protocol does not support
  • 0789 * output.
  • 0790 */
  • 0791 public OutputStream getOutputStream() throws IOException {
  • 0792 throw new UnknownServiceException("protocol doesn't support output");
  • 0793 }
  • 0794
  • 0795 /**
  • 0796 * Returns a <code>String</code> representation of this URL connection.
  • 0797 *
  • 0798 * @return a string representation of this <code>URLConnection</code>.
  • 0799 */
  • 0800 public String toString() {
  • 0801 return this.getClass().getName() + ":" + url;
  • 0802 }
  • 0803
  • 0804 /**
  • 0805 * Sets the value of the <code>doInput</code> field for this
  • 0806 * <code>URLConnection</code> to the specified value.
  • 0807 * <p>
  • 0808 * A URL connection can be used for input and/or output. Set the DoInput
  • 0809 * flag to true if you intend to use the URL connection for input,
  • 0810 * false if not. The default is true.
  • 0811 *
  • 0812 * @param doinput the new value.
  • 0813 * @throws IllegalStateException if already connected
  • 0814 * @see java.net.URLConnection#doInput
  • 0815 * @see #getDoInput()
  • 0816 */
  • 0817 public void setDoInput(boolean doinput) {
  • 0818 if (connected)
  • 0819 throw new IllegalStateException("Already connected");
  • 0820 doInput = doinput;
  • 0821 }
  • 0822
  • 0823 /**
  • 0824 * Returns the value of this <code>URLConnection</code>'s
  • 0825 * <code>doInput</code> flag.
  • 0826 *
  • 0827 * @return the value of this <code>URLConnection</code>'s
  • 0828 * <code>doInput</code> flag.
  • 0829 * @see #setDoInput(boolean)
  • 0830 */
  • 0831 public boolean getDoInput() {
  • 0832 return doInput;
  • 0833 }
  • 0834
  • 0835 /**
  • 0836 * Sets the value of the <code>doOutput</code> field for this
  • 0837 * <code>URLConnection</code> to the specified value.
  • 0838 * <p>
  • 0839 * A URL connection can be used for input and/or output. Set the DoOutput
  • 0840 * flag to true if you intend to use the URL connection for output,
  • 0841 * false if not. The default is false.
  • 0842 *
  • 0843 * @param dooutput the new value.
  • 0844 * @throws IllegalStateException if already connected
  • 0845 * @see #getDoOutput()
  • 0846 */
  • 0847 public void setDoOutput(boolean dooutput) {
  • 0848 if (connected)
  • 0849 throw new IllegalStateException("Already connected");
  • 0850 doOutput = dooutput;
  • 0851 }
  • 0852
  • 0853 /**
  • 0854 * Returns the value of this <code>URLConnection</code>'s
  • 0855 * <code>doOutput</code> flag.
  • 0856 *
  • 0857 * @return the value of this <code>URLConnection</code>'s
  • 0858 * <code>doOutput</code> flag.
  • 0859 * @see #setDoOutput(boolean)
  • 0860 */
  • 0861 public boolean getDoOutput() {
  • 0862 return doOutput;
  • 0863 }
  • 0864
  • 0865 /**
  • 0866 * Set the value of the <code>allowUserInteraction</code> field of
  • 0867 * this <code>URLConnection</code>.
  • 0868 *
  • 0869 * @param allowuserinteraction the new value.
  • 0870 * @throws IllegalStateException if already connected
  • 0871 * @see #getAllowUserInteraction()
  • 0872 */
  • 0873 public void setAllowUserInteraction(boolean allowuserinteraction) {
  • 0874 if (connected)
  • 0875 throw new IllegalStateException("Already connected");
  • 0876 allowUserInteraction = allowuserinteraction;
  • 0877 }
  • 0878
  • 0879 /**
  • 0880 * Returns the value of the <code>allowUserInteraction</code> field for
  • 0881 * this object.
  • 0882 *
  • 0883 * @return the value of the <code>allowUserInteraction</code> field for
  • 0884 * this object.
  • 0885 * @see #setAllowUserInteraction(boolean)
  • 0886 */
  • 0887 public boolean getAllowUserInteraction() {
  • 0888 return allowUserInteraction;
  • 0889 }
  • 0890
  • 0891 /**
  • 0892 * Sets the default value of the
  • 0893 * <code>allowUserInteraction</code> field for all future
  • 0894 * <code>URLConnection</code> objects to the specified value.
  • 0895 *
  • 0896 * @param defaultallowuserinteraction the new value.
  • 0897 * @see #getDefaultAllowUserInteraction()
  • 0898 */
  • 0899 public static void setDefaultAllowUserInteraction(boolean defaultallowuserinteraction) {
  • 0900 defaultAllowUserInteraction = defaultallowuserinteraction;
  • 0901 }
  • 0902
  • 0903 /**
  • 0904 * Returns the default value of the <code>allowUserInteraction</code>
  • 0905 * field.
  • 0906 * <p>
  • 0907 * Ths default is "sticky", being a part of the static state of all
  • 0908 * URLConnections. This flag applies to the next, and all following
  • 0909 * URLConnections that are created.
  • 0910 *
  • 0911 * @return the default value of the <code>allowUserInteraction</code>
  • 0912 * field.
  • 0913 * @see #setDefaultAllowUserInteraction(boolean)
  • 0914 */
  • 0915 public static boolean getDefaultAllowUserInteraction() {
  • 0916 return defaultAllowUserInteraction;
  • 0917 }
  • 0918
  • 0919 /**
  • 0920 * Sets the value of the <code>useCaches</code> field of this
  • 0921 * <code>URLConnection</code> to the specified value.
  • 0922 * <p>
  • 0923 * Some protocols do caching of documents. Occasionally, it is important
  • 0924 * to be able to "tunnel through" and ignore the caches (e.g., the
  • 0925 * "reload" button in a browser). If the UseCaches flag on a connection
  • 0926 * is true, the connection is allowed to use whatever caches it can.
  • 0927 * If false, caches are to be ignored.
  • 0928 * The default value comes from DefaultUseCaches, which defaults to
  • 0929 * true.
  • 0930 *
  • 0931 * @param usecaches a <code>boolean</code> indicating whether
  • 0932 * or not to allow caching
  • 0933 * @throws IllegalStateException if already connected
  • 0934 * @see #getUseCaches()
  • 0935 */
  • 0936 public void setUseCaches(boolean usecaches) {
  • 0937 if (connected)
  • 0938 throw new IllegalStateException("Already connected");
  • 0939 useCaches = usecaches;
  • 0940 }
  • 0941
  • 0942 /**
  • 0943 * Returns the value of this <code>URLConnection</code>'s
  • 0944 * <code>useCaches</code> field.
  • 0945 *
  • 0946 * @return the value of this <code>URLConnection</code>'s
  • 0947 * <code>useCaches</code> field.
  • 0948 * @see #setUseCaches(boolean)
  • 0949 */
  • 0950 public boolean getUseCaches() {
  • 0951 return useCaches;
  • 0952 }
  • 0953
  • 0954 /**
  • 0955 * Sets the value of the <code>ifModifiedSince</code> field of
  • 0956 * this <code>URLConnection</code> to the specified value.
  • 0957 *
  • 0958 * @param ifmodifiedsince the new value.
  • 0959 * @throws IllegalStateException if already connected
  • 0960 * @see #getIfModifiedSince()
  • 0961 */
  • 0962 public void setIfModifiedSince(long ifmodifiedsince) {
  • 0963 if (connected)
  • 0964 throw new IllegalStateException("Already connected");
  • 0965 ifModifiedSince = ifmodifiedsince;
  • 0966 }
  • 0967
  • 0968 /**
  • 0969 * Returns the value of this object's <code>ifModifiedSince</code> field.
  • 0970 *
  • 0971 * @return the value of this object's <code>ifModifiedSince</code> field.
  • 0972 * @see #setIfModifiedSince(long)
  • 0973 */
  • 0974 public long getIfModifiedSince() {
  • 0975 return ifModifiedSince;
  • 0976 }
  • 0977
  • 0978 /**
  • 0979 * Returns the default value of a <code>URLConnection</code>'s
  • 0980 * <code>useCaches</code> flag.
  • 0981 * <p>
  • 0982 * Ths default is "sticky", being a part of the static state of all
  • 0983 * URLConnections. This flag applies to the next, and all following
  • 0984 * URLConnections that are created.
  • 0985 *
  • 0986 * @return the default value of a <code>URLConnection</code>'s
  • 0987 * <code>useCaches</code> flag.
  • 0988 * @see #setDefaultUseCaches(boolean)
  • 0989 */
  • 0990 public boolean getDefaultUseCaches() {
  • 0991 return defaultUseCaches;
  • 0992 }
  • 0993
  • 0994 /**
  • 0995 * Sets the default value of the <code>useCaches</code> field to the
  • 0996 * specified value.
  • 0997 *
  • 0998 * @param defaultusecaches the new value.
  • 0999 * @see #getDefaultUseCaches()
  • 1000 */
  • 1001 public void setDefaultUseCaches(boolean defaultusecaches) {
  • 1002 defaultUseCaches = defaultusecaches;
  • 1003 }
  • 1004
  • 1005 /**
  • 1006 * Sets the general request property. If a property with the key already
  • 1007 * exists, overwrite its value with the new value.
  • 1008 *
  • 1009 * <p> NOTE: HTTP requires all request properties which can
  • 1010 * legally have multiple instances with the same key
  • 1011 * to use a comma-seperated list syntax which enables multiple
  • 1012 * properties to be appended into a single property.
  • 1013 *
  • 1014 * @param key the keyword by which the request is known
  • 1015 * (e.g., "<code>accept</code>").
  • 1016 * @param value the value associated with it.
  • 1017 * @throws IllegalStateException if already connected
  • 1018 * @throws NullPointerException if key is <CODE>null</CODE>
  • 1019 * @see #getRequestProperty(java.lang.String)
  • 1020 */
  • 1021 public void setRequestProperty(String key, String value) {
  • 1022 if (connected)
  • 1023 throw new IllegalStateException("Already connected");
  • 1024 if (key == null)
  • 1025 throw new NullPointerException ("key is null");
  • 1026
  • 1027 if (requests == null)
  • 1028 requests = new MessageHeader();
  • 1029
  • 1030 requests.set(key, value);
  • 1031 }
  • 1032
  • 1033 /**
  • 1034 * Adds a general request property specified by a
  • 1035 * key-value pair. This method will not overwrite
  • 1036 * existing values associated with the same key.
  • 1037 *
  • 1038 * @param key the keyword by which the request is known
  • 1039 * (e.g., "<code>accept</code>").
  • 1040 * @param value the value associated with it.
  • 1041 * @throws IllegalStateException if already connected
  • 1042 * @throws NullPointerException if key is null
  • 1043 * @see #getRequestProperties()
  • 1044 * @since 1.4
  • 1045 */
  • 1046 public void addRequestProperty(String key, String value) {
  • 1047 if (connected)
  • 1048 throw new IllegalStateException("Already connected");
  • 1049 if (key == null)
  • 1050 throw new NullPointerException ("key is null");
  • 1051
  • 1052 if (requests == null)
  • 1053 requests = new MessageHeader();
  • 1054
  • 1055 requests.add(key, value);
  • 1056 }
  • 1057
  • 1058
  • 1059 /**
  • 1060 * Returns the value of the named general request property for this
  • 1061 * connection.
  • 1062 *
  • 1063 * @param key the keyword by which the request is known (e.g., "accept").
  • 1064 * @return the value of the named general request property for this
  • 1065 * connection. If key is null, then null is returned.
  • 1066 * @throws IllegalStateException if already connected
  • 1067 * @see #setRequestProperty(java.lang.String, java.lang.String)
  • 1068 */
  • 1069 public String getRequestProperty(String key) {
  • 1070 if (connected)
  • 1071 throw new IllegalStateException("Already connected");
  • 1072
  • 1073 if (requests == null)
  • 1074 return null;
  • 1075
  • 1076 return requests.findValue(key);
  • 1077 }
  • 1078
  • 1079 /**
  • 1080 * Returns an unmodifiable Map of general request
  • 1081 * properties for this connection. The Map keys
  • 1082 * are Strings that represent the request-header
  • 1083 * field names. Each Map value is a unmodifiable List
  • 1084 * of Strings that represents the corresponding
  • 1085 * field values.
  • 1086 *
  • 1087 * @return a Map of the general request properties for this connection.
  • 1088 * @throws IllegalStateException if already connected
  • 1089 * @since 1.4
  • 1090 */
  • 1091 public Map<String,List<String>> getRequestProperties() {
  • 1092 if (connected)
  • 1093 throw new IllegalStateException("Already connected");
  • 1094
  • 1095 if (requests == null)
  • 1096 return Collections.EMPTY_MAP;
  • 1097
  • 1098 return requests.getHeaders(null);
  • 1099 }
  • 1100
  • 1101 /**
  • 1102 * Sets the default value of a general request property. When a
  • 1103 * <code>URLConnection</code> is created, it is initialized with
  • 1104 * these properties.
  • 1105 *
  • 1106 * @param key the keyword by which the request is known
  • 1107 * (e.g., "<code>accept</code>").
  • 1108 * @param value the value associated with the key.
  • 1109 *
  • 1110 * @see java.net.URLConnection#setRequestProperty(java.lang.String,java.lang.String)
  • 1111 *
  • 1112 * @deprecated The instance specific setRequestProperty method
  • 1113 * should be used after an appropriate instance of URLConnection
  • 1114 * is obtained. Invoking this method will have no effect.
  • 1115 *
  • 1116 * @see #getDefaultRequestProperty(java.lang.String)
  • 1117 */
  • 1118 @Deprecated
  • 1119 public static void setDefaultRequestProperty(String key, String value) {
  • 1120 }
  • 1121
  • 1122 /**
  • 1123 * Returns the value of the default request property. Default request
  • 1124 * properties are set for every connection.
  • 1125 *
  • 1126 * @param key the keyword by which the request is known (e.g., "accept").
  • 1127 * @return the value of the default request property
  • 1128 * for the specified key.
  • 1129 *
  • 1130 * @see java.net.URLConnection#getRequestProperty(java.lang.String)
  • 1131 *
  • 1132 * @deprecated The instance specific getRequestProperty method
  • 1133 * should be used after an appropriate instance of URLConnection
  • 1134 * is obtained.
  • 1135 *
  • 1136 * @see #setDefaultRequestProperty(java.lang.String, java.lang.String)
  • 1137 */
  • 1138 @Deprecated
  • 1139 public static String getDefaultRequestProperty(String key) {
  • 1140 return null;
  • 1141 }
  • 1142
  • 1143 /**
  • 1144 * The ContentHandler factory.
  • 1145 */
  • 1146 static ContentHandlerFactory factory;
  • 1147
  • 1148 /**
  • 1149 * Sets the <code>ContentHandlerFactory</code> of an
  • 1150 * application. It can be called at most once by an application.
  • 1151 * <p>
  • 1152 * The <code>ContentHandlerFactory</code> instance is used to
  • 1153 * construct a content handler from a content type
  • 1154 * <p>
  • 1155 * If there is a security manager, this method first calls
  • 1156 * the security manager's <code>checkSetFactory</code> method
  • 1157 * to ensure the operation is allowed.
  • 1158 * This could result in a SecurityException.
  • 1159 *
  • 1160 * @param fac the desired factory.
  • 1161 * @exception Error if the factory has already been defined.
  • 1162 * @exception SecurityException if a security manager exists and its
  • 1163 * <code>checkSetFactory</code> method doesn't allow the operation.
  • 1164 * @see java.net.ContentHandlerFactory
  • 1165 * @see java.net.URLConnection#getContent()
  • 1166 * @see SecurityManager#checkSetFactory
  • 1167 */
  • 1168 public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {
  • 1169 if (factory != null) {
  • 1170 throw new Error("factory already defined");
  • 1171 }
  • 1172 SecurityManager security = System.getSecurityManager();
  • 1173 if (security != null) {
  • 1174 security.checkSetFactory();
  • 1175 }
  • 1176 factory = fac;
  • 1177 }
  • 1178
  • 1179 private static Hashtable handlers = new Hashtable();
  • 1180 private static final ContentHandler UnknownContentHandlerP = new UnknownContentHandler();
  • 1181
  • 1182 /**
  • 1183 * Gets the Content Handler appropriate for this connection.
  • 1184 * @param connection the connection to use.
  • 1185 */
  • 1186 synchronized ContentHandler getContentHandler()
  • 1187 throws UnknownServiceException
  • 1188 {
  • 1189 String contentType = stripOffParameters(getContentType());
  • 1190 ContentHandler handler = null;
  • 1191 if (contentType == null)
  • 1192 throw new UnknownServiceException("no content-type");
  • 1193 try {
  • 1194 handler = (ContentHandler) handlers.get(contentType);
  • 1195 if (handler != null)
  • 1196 return handler;
  • 1197 } catch(Exception e) {
  • 1198 }
  • 1199
  • 1200 if (factory != null)
  • 1201 handler = factory.createContentHandler(contentType);
  • 1202 if (handler == null) {
  • 1203 try {
  • 1204 handler = lookupContentHandlerClassFor(contentType);
  • 1205 } catch(Exception e) {
  • 1206 e.printStackTrace();
  • 1207 handler = UnknownContentHandlerP;
  • 1208 }
  • 1209 handlers.put(contentType, handler);
  • 1210 }
  • 1211 return handler;
  • 1212 }
  • 1213
  • 1214 /*
  • 1215 * Media types are in the format: type/subtype*(; parameter).
  • 1216 * For looking up the content handler, we should ignore those
  • 1217 * parameters.
  • 1218 */
  • 1219 private String stripOffParameters(String contentType)
  • 1220 {
  • 1221 if (contentType == null)
  • 1222 return null;
  • 1223 int index = contentType.indexOf(';');
  • 1224
  • 1225 if (index > 0)
  • 1226 return contentType.substring(0, index);
  • 1227 else
  • 1228 return contentType;
  • 1229 }
  • 1230
  • 1231 private static final String contentClassPrefix = "sun.net.www.content";
  • 1232 private static final String contentPathProp = "java.content.handler.pkgs";
  • 1233
  • 1234 /**
  • 1235 * Looks for a content handler in a user-defineable set of places.
  • 1236 * By default it looks in sun.net.www.content, but users can define a
  • 1237 * vertical-bar delimited set of class prefixes to search through in
  • 1238 * addition by defining the java.content.handler.pkgs property.
  • 1239 * The class name must be of the form:
  • 1240 * <pre>
  • 1241 * {package-prefix}.{major}.{minor}
  • 1242 * e.g.
  • 1243 * YoyoDyne.experimental.text.plain
  • 1244 * </pre>
  • 1245 */
  • 1246 private ContentHandler lookupContentHandlerClassFor(String contentType)
  • 1247 throws InstantiationException, IllegalAccessException, ClassNotFoundException {
  • 1248 String contentHandlerClassName = typeToPackageName(contentType);
  • 1249
  • 1250 String contentHandlerPkgPrefixes =getContentHandlerPkgPrefixes();
  • 1251
  • 1252 StringTokenizer packagePrefixIter =
  • 1253 new StringTokenizer(contentHandlerPkgPrefixes, "|");
  • 1254
  • 1255 while (packagePrefixIter.hasMoreTokens()) {
  • 1256 String packagePrefix = packagePrefixIter.nextToken().trim();
  • 1257
  • 1258 try {
  • 1259 String clsName = packagePrefix + "." + contentHandlerClassName;
  • 1260 Class cls = null;
  • 1261 try {
  • 1262 cls = Class.forName(clsName);
  • 1263 } catch (ClassNotFoundException e) {
  • 1264 ClassLoader cl = ClassLoader.getSystemClassLoader();
  • 1265 if (cl != null) {
  • 1266 cls = cl.loadClass(clsName);
  • 1267 }
  • 1268 }
  • 1269 if (cls != null) {
  • 1270 ContentHandler handler =
  • 1271 (ContentHandler)cls.newInstance();
  • 1272 return handler;
  • 1273 }
  • 1274 } catch(Exception e) {
  • 1275 }
  • 1276 }
  • 1277
  • 1278 return UnknownContentHandlerP;
  • 1279 }
  • 1280
  • 1281 /**
  • 1282 * Utility function to map a MIME content type into an equivalent
  • 1283 * pair of class name components. For example: "text/html" would
  • 1284 * be returned as "text.html"
  • 1285 */
  • 1286 private String typeToPackageName(String contentType) {
  • 1287 // make sure we canonicalize the class name: all lower case
  • 1288 contentType = contentType.toLowerCase();
  • 1289 int len = contentType.length();
  • 1290 char nm[] = new char[len];
  • 1291 contentType.getChars(0, len, nm, 0);
  • 1292 for (int i = 0; i < len; i++) {
  • 1293 char c = nm[i];
  • 1294 if (c == '/') {
  • 1295 nm[i] = '.';
  • 1296 } else if (!('A' <= c && c <= 'Z' ||
  • 1297 'a' <= c && c <= 'z' ||
  • 1298 '0' <= c && c <= '9')) {
  • 1299 nm[i] = '_';
  • 1300 }
  • 1301 }
  • 1302 return new String(nm);
  • 1303 }
  • 1304
  • 1305
  • 1306 /**
  • 1307 * Returns a vertical bar separated list of package prefixes for potential
  • 1308 * content handlers. Tries to get the java.content.handler.pkgs property
  • 1309 * to use as a set of package prefixes to search. Whether or not
  • 1310 * that property has been defined, the sun.net.www.content is always
  • 1311 * the last one on the returned package list.
  • 1312 */
  • 1313 private String getContentHandlerPkgPrefixes() {
  • 1314 String packagePrefixList = (String) AccessController.doPrivileged(
  • 1315 new sun.security.action.GetPropertyAction(contentPathProp, ""));
  • 1316
  • 1317 if (packagePrefixList != "") {
  • 1318 packagePrefixList += "|";
  • 1319 }
  • 1320
  • 1321 return packagePrefixList + contentClassPrefix;
  • 1322 }
  • 1323
  • 1324 /**
  • 1325 * Tries to determine the content type of an object, based
  • 1326 * on the specified "file" component of a URL.
  • 1327 * This is a convenience method that can be used by
  • 1328 * subclasses that override the <code>getContentType</code> method.
  • 1329 *
  • 1330 * @param fname a filename.
  • 1331 * @return a guess as to what the content type of the object is,
  • 1332 * based upon its file name.
  • 1333 * @see java.net.URLConnection#getContentType()
  • 1334 */
  • 1335 public static String guessContentTypeFromName(String fname) {
  • 1336 return getFileNameMap().getContentTypeFor(fname);
  • 1337 }
  • 1338
  • 1339 /**
  • 1340 * Tries to determine the type of an input stream based on the
  • 1341 * characters at the beginning of the input stream. This method can
  • 1342 * be used by subclasses that override the
  • 1343 * <code>getContentType</code> method.
  • 1344 * <p>
  • 1345 * Ideally, this routine would not be needed. But many
  • 1346 * <code>http</code> servers return the incorrect content type; in
  • 1347 * addition, there are many nonstandard extensions. Direct inspection
  • 1348 * of the bytes to determine the content type is often more accurate
  • 1349 * than believing the content type claimed by the <code>http</code> server.
  • 1350 *
  • 1351 * @param is an input stream that supports marks.
  • 1352 * @return a guess at the content type, or <code>null</code> if none
  • 1353 * can be determined.
  • 1354 * @exception IOException if an I/O error occurs while reading the
  • 1355 * input stream.
  • 1356 * @see java.io.InputStream#mark(int)
  • 1357 * @see java.io.InputStream#markSupported()
  • 1358 * @see java.net.URLConnection#getContentType()
  • 1359 */
  • 1360 static public String guessContentTypeFromStream(InputStream is)
  • 1361 throws IOException {
  • 1362 // If we can't read ahead safely, just give up on guessing
  • 1363 if (!is.markSupported())
  • 1364 return null;
  • 1365
  • 1366 is.mark(12);
  • 1367 int c1 = is.read();
  • 1368 int c2 = is.read();
  • 1369 int c3 = is.read();
  • 1370 int c4 = is.read();
  • 1371 int c5 = is.read();
  • 1372 int c6 = is.read();
  • 1373 int c7 = is.read();
  • 1374 int c8 = is.read();
  • 1375 int c9 = is.read();
  • 1376 int c10 = is.read();
  • 1377 int c11 = is.read();
  • 1378 is.reset();
  • 1379
  • 1380 if (c1 == 0xCA && c2 == 0xFE && c3 == 0xBA && c4 == 0xBE) {
  • 1381 return "application/java-vm";
  • 1382 }
  • 1383
  • 1384 if (c1 == 0xAC && c2 == 0xED) {
  • 1385 // next two bytes are version number, currently 0x00 0x05
  • 1386 return "application/x-java-serialized-object";
  • 1387 }
  • 1388
  • 1389 if (c1 == '<') {
  • 1390 if (c2 == '!'
  • 1391 || ((c2 == 'h' && (c3 == 't' && c4 == 'm' && c5 == 'l' ||
  • 1392 c3 == 'e' && c4 == 'a' && c5 == 'd') ||
  • 1393 (c2 == 'b' && c3 == 'o' && c4 == 'd' && c5 == 'y'))) ||
  • 1394 ((c2 == 'H' && (c3 == 'T' && c4 == 'M' && c5 == 'L' ||
  • 1395 c3 == 'E' && c4 == 'A' && c5 == 'D') ||
  • 1396 (c2 == 'B' && c3 == 'O' && c4 == 'D' && c5 == 'Y')))) {
  • 1397 return "text/html";
  • 1398 }
  • 1399
  • 1400 if (c2 == '?' && c3 == 'x' && c4 == 'm' && c5 == 'l' && c6 == ' ') {
  • 1401 return "application/xml";
  • 1402 }
  • 1403 }
  • 1404
  • 1405 // big and little endian UTF-16 encodings, with byte order mark
  • 1406 if (c1 == 0xfe && c2 == 0xff) {
  • 1407 if (c3 == 0 && c4 == '<' && c5 == 0 && c6 == '?' &&
  • 1408 c7 == 0 && c8 == 'x') {
  • 1409 return "application/xml";
  • 1410 }
  • 1411 }
  • 1412
  • 1413 if (c1 == 0xff && c2 == 0xfe) {
  • 1414 if (c3 == '<' && c4 == 0 && c5 == '?' && c6 == 0 &&
  • 1415 c7 == 'x' && c8 == 0) {
  • 1416 return "application/xml";
  • 1417 }
  • 1418 }
  • 1419
  • 1420 if (c1 == 'G' && c2 == 'I' && c3 == 'F' && c4 == '8') {
  • 1421 return "image/gif";
  • 1422 }
  • 1423
  • 1424 if (c1 == '#' && c2 == 'd' && c3 == 'e' && c4 == 'f') {
  • 1425 return "image/x-bitmap";
  • 1426 }
  • 1427
  • 1428 if (c1 == '!' && c2 == ' ' && c3 == 'X' && c4 == 'P' &&
  • 1429 c5 == 'M' && c6 == '2') {
  • 1430 return "image/x-pixmap";
  • 1431 }
  • 1432
  • 1433 if (c1 == 137 && c2 == 80 && c3 == 78 &&
  • 1434 c4 == 71 && c5 == 13 && c6 == 10 &&
  • 1435 c7 == 26 && c8 == 10) {
  • 1436 return "image/png";
  • 1437 }
  • 1438
  • 1439 if (c1 == 0xFF && c2 == 0xD8 && c3 == 0xFF) {
  • 1440 if (c4 == 0xE0) {
  • 1441 return "image/jpeg";
  • 1442 }
  • 1443
  • 1444 /**
  • 1445 * File format used by digital cameras to store images.
  • 1446 * Exif Format can be read by any application supporting
  • 1447 * JPEG. Exif Spec can be found at:
  • 1448 * http://www.pima.net/standards/it10/PIMA15740/Exif_2-1.PDF
  • 1449 */
  • 1450 if ((c4 == 0xE1) &&
  • 1451 (c7 == 'E' && c8 == 'x' && c9 == 'i' && c10 =='f' &&
  • 1452 c11 == 0)) {
  • 1453 return "image/jpeg";
  • 1454 }
  • 1455
  • 1456 if (c4 == 0xEE) {
  • 1457 return "image/jpg";
  • 1458 }
  • 1459 }
  • 1460
  • 1461 if (c1 == 0xD0 && c2 == 0xCF && c3 == 0x11 && c4 == 0xE0 &&
  • 1462 c5 == 0xA1 && c6 == 0xB1 && c7 == 0x1A && c8 == 0xE1) {
  • 1463
  • 1464 /* Above is signature of Microsoft Structured Storage.
  • 1465 * Below this, could have tests for various SS entities.
  • 1466 * For now, just test for FlashPix.
  • 1467 */
  • 1468 if (checkfpx(is)) {
  • 1469 return "image/vnd.fpx";
  • 1470 }
  • 1471 }
  • 1472
  • 1473 if (c1 == 0x2E && c2 == 0x73 && c3 == 0x6E && c4 == 0x64) {
  • 1474 return "audio/basic"; // .au format, big endian
  • 1475 }
  • 1476
  • 1477 if (c1 == 0x64 && c2 == 0x6E && c3 == 0x73 && c4 == 0x2E) {
  • 1478 return "audio/basic"; // .au format, little endian
  • 1479 }
  • 1480
  • 1481 if (c1 == 'R' && c2 == 'I' && c3 == 'F' && c4 == 'F') {
  • 1482 /* I don't know if this is official but evidence
  • 1483 * suggests that .wav files start with "RIFF" - brown
  • 1484 */
  • 1485 return "audio/x-wav";
  • 1486 }
  • 1487 return null;
  • 1488 }
  • 1489
  • 1490 /**
  • 1491 * Check for FlashPix image data in InputStream is. Return true if
  • 1492 * the stream has FlashPix data, false otherwise. Before calling this
  • 1493 * method, the stream should have already been checked to be sure it
  • 1494 * contains Microsoft Structured Storage data.
  • 1495 */
  • 1496 static private boolean checkfpx(InputStream is) throws IOException {
  • 1497
  • 1498 /* Test for FlashPix image data in Microsoft Structured Storage format.
  • 1499 * In general, should do this with calls to an SS implementation.
  • 1500 * Lacking that, need to dig via offsets to get to the FlashPix
  • 1501 * ClassID. Details:
  • 1502 *
  • 1503 * Offset to Fpx ClsID from beginning of stream should be:
  • 1504 *
  • 1505 * FpxClsidOffset = rootEntryOffset + clsidOffset
  • 1506 *
  • 1507 * where: clsidOffset = 0x50.
  • 1508 * rootEntryOffset = headerSize + sectorSize*sectDirStart
  • 1509 * + 128*rootEntryDirectory
  • 1510 *
  • 1511 * where: headerSize = 0x200 (always)
  • 1512 * sectorSize = 2 raised to power of uSectorShift,
  • 1513 * which is found in the header at
  • 1514 * offset 0x1E.
  • 1515 * sectDirStart = found in the header at offset 0x30.
  • 1516 * rootEntryDirectory = in general, should search for
  • 1517 * directory labelled as root.
  • 1518 * We will assume value of 0 (i.e.,
  • 1519 * rootEntry is in first directory)
  • 1520 */
  • 1521
  • 1522 // Mark the stream so we can reset it. 0x100 is enough for the first
  • 1523 // few reads, but the mark will have to be reset and set again once
  • 1524 // the offset to the root directory entry is computed. That offset
  • 1525 // can be very large and isn't know until the stream has been read from
  • 1526 is.mark(0x100);
  • 1527
  • 1528 // Get the byte ordering located at 0x1E. 0xFE is Intel,
  • 1529 // 0xFF is other
  • 1530 long toSkip = (long)0x1C;
  • 1531 long posn;
  • 1532
  • 1533 if ((posn = skipForward(is, toSkip)) < toSkip) {
  • 1534 is.reset();
  • 1535 return false;
  • 1536 }
  • 1537
  • 1538 int c[] = new int[16];
  • 1539 if (readBytes(c, 2, is) < 0) {
  • 1540 is.reset();
  • 1541 return false;
  • 1542 }
  • 1543
  • 1544 int byteOrder = c[0];
  • 1545
  • 1546 posn+=2;
  • 1547 int uSectorShift;
  • 1548 if (readBytes(c, 2, is) < 0) {
  • 1549 is.reset();
  • 1550 return false;
  • 1551 }
  • 1552
  • 1553 if(byteOrder == 0xFE) {
  • 1554 uSectorShift = c[0];
  • 1555 uSectorShift += c[1] << 8;
  • 1556 }
  • 1557 else {
  • 1558 uSectorShift = c[0] << 8;
  • 1559 uSectorShift += c[1];
  • 1560 }
  • 1561
  • 1562 posn += 2;
  • 1563 toSkip = (long)0x30 - posn;
  • 1564 long skipped = 0;
  • 1565 if ((skipped = skipForward(is, toSkip)) < toSkip) {
  • 1566 is.reset();
  • 1567 return false;
  • 1568 }
  • 1569 posn += skipped;
  • 1570
  • 1571 if (readBytes(c, 4, is) < 0) {
  • 1572 is.reset();
  • 1573 return false;
  • 1574 }
  • 1575
  • 1576 int sectDirStart;
  • 1577 if(byteOrder == 0xFE) {
  • 1578 sectDirStart = c[0];
  • 1579 sectDirStart += c[1] << 8;
  • 1580 sectDirStart += c[2] << 16;
  • 1581 sectDirStart += c[3] << 24;
  • 1582 } else {
  • 1583 sectDirStart = c[0] << 24;
  • 1584 sectDirStart += c[1] << 16;
  • 1585 sectDirStart += c[2] << 8;
  • 1586 sectDirStart += c[3];
  • 1587 }
  • 1588 posn += 4;
  • 1589 is.reset(); // Reset back to the beginning
  • 1590
  • 1591 toSkip = (long)0x200 +
  • 1592 (long)((int)1<<uSectorShift)*sectDirStart + (long)0x50;
  • 1593
  • 1594 // Sanity check!
  • 1595 if (toSkip < 0) {
  • 1596 return false;
  • 1597 }
  • 1598
  • 1599 /*
  • 1600 * How far can we skip? Is there any performance problem here?
  • 1601 * This skip can be fairly long, at least 0x4c650 in at least
  • 1602 * one case. Have to assume that the skip will fit in an int.
  • 1603 * Leave room to read whole root dir
  • 1604 */
  • 1605 is.mark((int)toSkip+0x30);
  • 1606
  • 1607 if ((skipForward(is, toSkip)) < toSkip) {
  • 1608 is.reset();
  • 1609 return false;
  • 1610 }
  • 1611
  • 1612 /* should be at beginning of ClassID, which is as follows
  • 1613 * (in Intel byte order):
  • 1614 * 00 67 61 56 54 C1 CE 11 85 53 00 AA 00 A1 F9 5B
  • 1615 *
  • 1616 * This is stored from Windows as long,short,short,char[8]
  • 1617 * so for byte order changes, the order only changes for
  • 1618 * the first 8 bytes in the ClassID.
  • 1619 *
  • 1620 * Test against this, ignoring second byte (Intel) since
  • 1621 * this could change depending on part of Fpx file we have.
  • 1622 */
  • 1623
  • 1624 if (readBytes(c, 16, is) < 0) {
  • 1625 is.reset();
  • 1626 return false;
  • 1627 }
  • 1628
  • 1629 // intel byte order
  • 1630 if (byteOrder == 0xFE &&
  • 1631 c[0] == 0x00 && c[2] == 0x61 && c[3] == 0x56 &&
  • 1632 c[4] == 0x54 && c[5] == 0xC1 && c[6] == 0xCE &&
  • 1633 c[7] == 0x11 && c[8] == 0x85 && c[9] == 0x53 &&
  • 1634 c[10]== 0x00 && c[11]== 0xAA && c[12]== 0x00 &&
  • 1635 c[13]== 0xA1 && c[14]== 0xF9 && c[15]== 0x5B) {
  • 1636 is.reset();
  • 1637 return true;
  • 1638 }
  • 1639
  • 1640 // non-intel byte order
  • 1641 else if (c[3] == 0x00 && c[1] == 0x61 && c[0] == 0x56 &&
  • 1642 c[5] == 0x54 && c[4] == 0xC1 && c[7] == 0xCE &&
  • 1643 c[6] == 0x11 && c[8] == 0x85 && c[9] == 0x53 &&
  • 1644 c[10]== 0x00 && c[11]== 0xAA && c[12]== 0x00 &&
  • 1645 c[13]== 0xA1 && c[14]== 0xF9 && c[15]== 0x5B) {
  • 1646 is.reset();
  • 1647 return true;
  • 1648 }
  • 1649 is.reset();
  • 1650 return false;
  • 1651 }
  • 1652
  • 1653 /**
  • 1654 * Tries to read the specified number of bytes from the stream
  • 1655 * Returns -1, If EOF is reached before len bytes are read, returns 0
  • 1656 * otherwise
  • 1657 */
  • 1658 static private int readBytes(int c[], int len, InputStream is)
  • 1659 throws IOException {
  • 1660
  • 1661 byte buf[] = new byte[len];
  • 1662 if (is.read(buf, 0, len) < len) {
  • 1663 return -1;
  • 1664 }
  • 1665
  • 1666 // fill the passed in int array
  • 1667 for (int i = 0; i < len; i++) {
  • 1668 c[i] = buf[i] & 0xff;
  • 1669 }
  • 1670 return 0;
  • 1671 }
  • 1672
  • 1673
  • 1674 /**
  • 1675 * Skips through the specified number of bytes from the stream
  • 1676 * until either EOF is reached, or the specified
  • 1677 * number of bytes have been skipped
  • 1678 */
  • 1679 static private long skipForward(InputStream is, long toSkip)
  • 1680 throws IOException {
  • 1681
  • 1682 long eachSkip = 0;
  • 1683 long skipped = 0;
  • 1684
  • 1685 while (skipped != toSkip) {
  • 1686 eachSkip = is.skip(toSkip - skipped);
  • 1687
  • 1688 // check if EOF is reached
  • 1689 if (eachSkip <= 0) {
  • 1690 if (is.read() == -1) {
  • 1691 return skipped ;
  • 1692 } else {
  • 1693 skipped++;
  • 1694 }
  • 1695 }
  • 1696 skipped += eachSkip;
  • 1697 }
  • 1698 return skipped;
  • 1699 }
  • 1700
  • 1701}
  • 1702
  • 1703
  • 1704class UnknownContentHandler extends ContentHandler {
  • 1705 public Object getContent(URLConnection uc) throws IOException {
  • 1706 return uc.getInputStream();
  • 1707 }
  • 1708}

文件:URLConnection.java
包名:java.net
类名:URLConnection
继承:
接口: