urlconnection.java
来自「kaffe Java 解释器语言,源码,Java的子集系统,开放源代码」· Java 代码 · 共 957 行 · 第 1/2 页
JAVA
957 行
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(); } /** * 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. * * @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; } /** * Returns 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 defaultusecaches) { defaultUseCaches = defaultusecaches; } /** * Sets the value of the named request property * * @param key The name of the property * @param value The value of the property * * @exception IllegalStateException If already connected * @exception NullPointerException If key is null * * @see URLConnection#getRequestProperty(String key) * @see URLConnection#addRequestProperty(String key, String value) * * @since 1.4 */ public void setRequestProperty(String key, String value) { if (connected) throw new IllegalStateException ("Already connected"); if (key == null) throw new NullPointerException ("key is null"); // Do nothing unless overridden by subclasses that support setting // header fields in the request. } /** * Adds a new request property by a key/value pair. * This method does not overwrite existing properties with the same key. * * @param key Key of the property to add * @param value Value of the Property to add * * @exception IllegalStateException If already connected * @exception NullPointerException If key is null * * @see URLConnection#getRequestProperty(String key) * @see URLConnection#setRequestProperty(String key, String value) * * @since 1.4 */ public void addRequestProperty(String key, String value) { if (connected) throw new IllegalStateException ("Already connected"); if (key == null) throw new NullPointerException ("key is null"); // Do nothing unless overridden by subclasses that support adding // header fields in the request. } /** * Returns the value of the named request property. * * @param key The name of the property * * @return Value of the property * * @exception IllegalStateException If already connected * * @see URLConnection#setRequestProperty(String key, String value) * @see URLConnection#addRequestProperty(String key, String value) */ public String getRequestProperty(String key) { if (connected) throw new IllegalStateException ("Already connected"); // Overridden by subclasses that support reading header fields from the // request. return null; } /** * Returns an unmodifiable Map containing the request properties. * * @return The map of properties * * @exception IllegalStateException If already connected * * @since 1.4 */ public Map getRequestProperties() { if (connected) throw new IllegalStateException ("Already connected"); // Overridden by subclasses that support reading header fields from the // request. return Collections.EMPTY_MAP; } /** * Sets the default value of a request property. This will be used * for all connections unless the value of the property is manually * overridden. * * @param key The request property name the default is being set for * @param value The value to set the default to * * @deprecated 1.3 The method setRequestProperty should be used instead. * This method does nothing now. * * @see URLConnection#setRequestProperty(String key, String value) */ public static void setDefaultRequestProperty (String key, String value) { // This method does nothing since JDK 1.3. } /** * Returns the default value of a request property. This will be used * for all connections unless the value of the property is manually * overridden. * * @param key The request property to return the default value of * * @return The value of the default property or null if not available * * @deprecated 1.3 The method getRequestProperty should be used instead. * This method does nothing now. * * @see URLConnection#getRequestProperty(String key) */ public static String getDefaultRequestProperty(String key) { // This method does nothing since JDK 1.3. return null; } /** * Set's the ContentHandlerFactory for an application. This can be called * once and only once. If it is called again, then an Error is thrown. * Unlike for other set factory methods, this one does not do a security * check prior to setting the factory. * * @param factory The ContentHandlerFactory for this application * * @exception Error If the factory has already been defined * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation */ public static synchronized void setContentHandlerFactory (ContentHandlerFactory fac) { if (factory != null) throw new Error("ContentHandlerFactory already set"); // Throw an exception if an extant security mgr precludes // setting the factory. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkSetFactory(); factory = fac; } /** * Returns the MIME type of a file based on the name of the file. This * works by searching for the file's extension in a list of file extensions * and returning the MIME type associated with it. If no type is found, * then a MIME type of "application/octet-stream" will be returned. * * @param filename The filename to determine the MIME type for * * @return The MIME type String * * @specnote public since JDK 1.4 */ public static String guessContentTypeFromName(String filename) { return getFileNameMap().getContentTypeFor(filename.toLowerCase()); } /** * Returns the MIME type of a stream based on the first few characters * at the beginning of the stream. This routine can be used to determine * the MIME type if a server is believed to be returning an incorrect * MIME type. This method returns "application/octet-stream" if it * cannot determine the MIME type. * <p> * NOTE: Overriding MIME types sent from the server can be obnoxious * to user's. See Internet Exploder 4 if you don't believe me. * * @param is The InputStream to determine the MIME type from * * @return The MIME type * * @exception IOException If an error occurs */ public static String guessContentTypeFromStream(InputStream is) throws IOException { return("application/octet-stream"); } /** * This method returns the <code>FileNameMap</code> object being used * to decode MIME types by file extension. * * @return The <code>FileNameMap</code>. * * @since 1.2 */ public static synchronized FileNameMap getFileNameMap() { // Delayed initialization. if (fileNameMap == null) { fileNameMap = new MimeTypeMapper(); } return fileNameMap; } /** * This method set the <code>FileNameMap</code> object being used * to decode MIME types by file extension. * * @param map The <code>FileNameMap</code>. * * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation * * @since 1.2 */ public static void setFileNameMap(FileNameMap map) { // Throw an exception if an extant security mgr precludes // setting the factory. SecurityManager s = System.getSecurityManager(); if (s != null) s.checkSetFactory(); fileNameMap = map; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?