⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlconnection.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   * @param defaultValue The default date if the header field is not found   * or can't be converted.   *   * @return Returns the date value of the header filed or the default value   * if the field is missing or malformed   */  public long getHeaderFieldDate(String name, long defaultValue)  {    if (! dateformats_initialized)      initializeDateFormats();    if (position == null)      position = new ParsePosition(0);    long result = defaultValue;    String str = getHeaderField(name);    if (str != null)      {	for (int i = 0; i < dateFormats.length; i++)	  {	    SimpleDateFormat df = dateFormats[i];	    position.setIndex(0);	    position.setErrorIndex(0);	    Date date = df.parse(str, position);	    if (date != null)	      return date.getTime();	  }      }    return result;  }  /**   * Returns a String representing the header key at the specified index.   * This allows the caller to walk the list of header fields.  The analogous   * getHeaderField(int) method allows access to the corresponding value for   * this tag.   *   * @param index The index into the header field list to retrieve the key for.   *   * @return The header field key or null if index is past the end   * of the headers.   */  public String getHeaderFieldKey(int index)  {    // Subclasses for specific protocols override this.    return null;  }  /**   * This method returns the content of the document pointed to by the   * URL as an Object.  The type of object depends on the MIME type of   * the object and particular content hander loaded.  Most text type   * content handlers will return a subclass of   * <code>InputStream</code>.  Images usually return a class that   * implements <code>ImageProducer</code>.  There is not guarantee   * what type of object will be returned, however.   *   * <p>This class first determines the MIME type of the content, then   * creates a ContentHandler object to process the input.  If the   * <code>ContentHandlerFactory</code> is set, then that object is   * called to load a content handler, otherwise a class called   * gnu.java.net.content.&lt;content_type&gt; is tried.  If this   * handler does not exist, the method will simple return the   * <code>InputStream</code> returned by   * <code>getInputStream()</code>.  Note that the default   * implementation of <code>getInputStream()</code> throws a   * <code>UnknownServiceException</code> so subclasses are encouraged   * to override this method.</p>   *   * @return the content   *   * @exception IOException If an error with the connection occurs.   * @exception UnknownServiceException If the protocol does not support the   * content type at all.   */  public Object getContent() throws IOException  {    if (!connected)      connect();    // FIXME: Doc indicates that other criteria should be applied as    // heuristics to determine the true content type, e.g. see     // guessContentTypeFromName() and guessContentTypeFromStream methods    // as well as FileNameMap class & fileNameMap field & get/set methods.    String type = getContentType();    ContentHandler ch = getContentHandler(type);    if (ch != null)      return ch.getContent(this);    return getInputStream();  }  /**   * Retrieves the content of this URLConnection   *   * @param classes The allowed classes for the content   *   * @return the content   *   * @exception IOException If an error occurs   * @exception UnknownServiceException If the protocol does not support the   * content type   */  public Object getContent(Class[] classes) throws IOException  {    // FIXME: implement this    return getContent();  }  /**   * This method returns a <code>Permission</code> object representing the   * permissions required to access this URL.  This method returns   * <code>java.security.AllPermission</code> by default.  Subclasses should   * override it to return a more specific permission.  For example, an   * HTTP URL should return an instance of <code>SocketPermission</code>   * for the appropriate host and port.   * <p>   * Note that because of items such as HTTP redirects, the permission   * object returned might be different before and after connecting.   *   * @return A Permission object   *   * @exception IOException If the computation of the permission requires   * network or file I/O and an exception occurs while computing it   */  public Permission getPermission() throws IOException  {    // Subclasses may override this.    return new AllPermission();  }  /**   * Returns an InputStream for this connection.  As this default   * implementation returns null, subclasses should override this method   *   * @return An InputStream for this connection   *   * @exception IOException If an error occurs   * @exception UnknownServiceException If the protocol does not support input   */  public InputStream getInputStream() throws IOException  {    // Subclasses for specific protocols override this.    throw new UnknownServiceException("Protocol " + url.getProtocol()                                      + " does not support input.");  }  /**   * Returns an OutputStream for this connection.  As this default   * implementation returns null, subclasses should override this method   *   * @return An OutputStream for this connection   *   * @exception IOException If an error occurs   * @exception UnknownServiceException If the protocol does not support output   */  public OutputStream getOutputStream() throws IOException  {    // Subclasses for specific protocols override this.    throw new UnknownServiceException("Protocol " + url.getProtocol()                                      + " does not support output.");  }  /**   * The methods prints the value of this object as a String by calling the   * toString() method of its associated URL.  Overrides Object.toString()   *   * @return A String representation of this object   */  public String toString()  {    return this.getClass().getName() + ":" + url.toString();  }  /**   * Sets the value of a flag indicating whether or not input is going   * to be done for this connection.  This default to true unless the   * doOutput flag is set to false, in which case this defaults to false.   *   * @param input <code>true</code> if input is to be done,   * <code>false</code> otherwise   *   * @exception IllegalStateException If already connected   */  public void setDoInput(boolean input)  {    if (connected)      throw new IllegalStateException("Already connected");    doInput = input;  }  /**   * Returns the value of a flag indicating whether or not input is going   * to be done for this connection.  This default to true unless the   * doOutput flag is set to false, in which case this defaults to false.   *   * @return true if input is to be done, false otherwise   */  public boolean getDoInput()  {    return doInput;  }  /**   * Sets a boolean flag indicating whether or not output will be done   * on this connection.  The default value is false, so this method can   * be used to override the default   *   * @param output ture if output is to be done, false otherwise   *   * @exception IllegalStateException If already connected   */  public void setDoOutput(boolean output)  {    if (connected)      throw new IllegalStateException("Already connected");    doOutput = output;  }  /**   * Returns a boolean flag indicating whether or not output will be done   * on this connection.  This defaults to false.   *   * @return true if output is to be done, false otherwise   */  public boolean getDoOutput()  {    return doOutput;  }  /**   * Sets a boolean flag indicating whether or not user interaction is   * allowed for this connection.  (For example, in order to prompt for   * username and password info.   *   * @param allow true if user interaction should be allowed, false otherwise.   *   * @exception IllegalStateException If already connected   */  public void setAllowUserInteraction(boolean allow)  {    allowUserInteraction = allow;  }  /**   * Returns a boolean flag indicating whether or not user interaction is   * allowed for this connection.  (For example, in order to prompt for   * username and password info.   *   * @return true if user interaction is allowed, false otherwise   */  public boolean getAllowUserInteraction()  {    return allowUserInteraction;  }  /**   * Sets the default flag for whether or not interaction with a user   * is allowed.  This will be used for all connections unless overridden   *   * @param allow true to allow user interaction, false otherwise   */  public static void setDefaultAllowUserInteraction(boolean allow)  {    defaultAllowUserInteraction = allow;  }  /**   * Returns the default flag for whether or not interaction with a user   * is allowed.  This will be used for all connections unless overridden   *   * @return true if user interaction is allowed, false otherwise   */  public static boolean getDefaultAllowUserInteraction()  {    return defaultAllowUserInteraction;  }  /**   * Sets a boolean flag indicating whether or not caching will be used   * (if possible) to store data downloaded via the connection.   *   * @param usecaches The new value   *   * @exception IllegalStateException If already connected   */  public void setUseCaches(boolean usecaches)  {    if (connected)      throw new IllegalStateException("Already connected");    useCaches = usecaches;  }  /**   * Returns a boolean flag indicating whether or not caching will be used   * (if possible) to store data downloaded via the connection.   *   * @return true if caching should be used if possible, false otherwise   */  public boolean getUseCaches()  {    return useCaches;  }  /**   * Sets the ifModified since instance variable.  If this value is non   * zero and the underlying protocol supports it, the actual document will   * not be fetched unless it has been modified since this time.  The value   * passed should  be 0 if this feature is to be disabled or the time expressed   * as the number of seconds since midnight 1/1/1970 GMT otherwise.   *   * @param ifmodifiedsince The new value in milliseconds   * since January 1, 1970 GMT   *   * @exception IllegalStateException If already connected   */  public void setIfModifiedSince(long ifmodifiedsince)  {    if (connected)      throw new IllegalStateException("Already connected");    ifModifiedSince = ifmodifiedsince;  }  /**   * Returns the ifModified since instance variable.  If this value is non   * zero and the underlying protocol supports it, the actual document will   * not be fetched unless it has been modified since this time.  The value   * returned will be 0 if this feature is disabled or the time expressed   * as the number of seconds since midnight 1/1/1970 GMT otherwise   *   * @return The ifModifiedSince value   */  public long getIfModifiedSince()  {    return ifModifiedSince;  }  /**   * Returns the default value used to determine whether or not caching   * of documents will be done when possible.   *   * @return true if caches will be used, false otherwise   */  public boolean getDefaultUseCaches()  {    return defaultUseCaches;  }  /**   * Sets the default value used to determine whether or not caching   * of documents will be done when possible.   *   * @param use true to use caches if possible by default, false otherwise   */  public void setDefaultUseCaches(boolean use)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -