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

📄 urlconnection.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * Sets the default value of the      * <code>allowUserInteraction</code> field for all future      * <code>URLConnection</code> objects to the specified value.      *     * @param   defaultallowuserinteraction   the new value.     * @see     #getDefaultAllowUserInteraction()     */    public static void setDefaultAllowUserInteraction(boolean defaultallowuserinteraction) {	defaultAllowUserInteraction = defaultallowuserinteraction;    }    /**     * Returns the default value of the <code>allowUserInteraction</code>     * field.     * <p>     * Ths default is "sticky", being a part of the static state of all     * URLConnections.  This flag applies to the next, and all following     * URLConnections that are created.     *     * @return  the default value of the <code>allowUserInteraction</code>     *          field.     * @see     #setDefaultAllowUserInteraction(boolean)     */    public static boolean getDefaultAllowUserInteraction() {	return defaultAllowUserInteraction;    }    /**     * Sets the value of the <code>useCaches</code> field of this      * <code>URLConnection</code> to the specified value.      * <p>     * Some protocols do caching of documents.  Occasionally, it is important     * to be able to "tunnel through" and ignore the caches (e.g., the     * "reload" button in a browser).  If the UseCaches flag on a connection     * is true, the connection is allowed to use whatever caches it can.     *  If false, caches are to be ignored.     *  The default value comes from DefaultUseCaches, which defaults to     * true.     *     * @param usecaches a <code>boolean</code> indicating whether      * or not to allow caching     * @throws IllegalStateException if already connected     * @see #getUseCaches()     */    public void setUseCaches(boolean usecaches) {	if (connected)	    throw new IllegalStateException("Already connected");	useCaches = usecaches;    }    /**     * Returns the value of this <code>URLConnection</code>'s     * <code>useCaches</code> field.     *     * @return  the value of this <code>URLConnection</code>'s     *          <code>useCaches</code> field.     * @see #setUseCaches(boolean)     */    public boolean getUseCaches() {	return useCaches;    }    /**     * Sets the value of the <code>ifModifiedSince</code> field of      * this <code>URLConnection</code> to the specified value.     *     * @param   ifmodifiedsince   the new value.     * @throws IllegalStateException if already connected     * @see     #getIfModifiedSince()     */    public void setIfModifiedSince(long ifmodifiedsince) {	if (connected)	    throw new IllegalStateException("Already connected");	ifModifiedSince = ifmodifiedsince;    }    /**     * Returns the value of this object's <code>ifModifiedSince</code> field.     *     * @return  the value of this object's <code>ifModifiedSince</code> field.     * @see #setIfModifiedSince(long)     */    public long getIfModifiedSince() {	return ifModifiedSince;    }   /**     * Returns the default value of a <code>URLConnection</code>'s     * <code>useCaches</code> flag.     * <p>     * Ths default is "sticky", being a part of the static state of all     * URLConnections.  This flag applies to the next, and all following     * URLConnections that are created.     *     * @return  the default value of a <code>URLConnection</code>'s     *          <code>useCaches</code> flag.     * @see     #setDefaultUseCaches(boolean)     */    public boolean getDefaultUseCaches() {	return defaultUseCaches;    }   /**     * Sets the default value of the <code>useCaches</code> field to the      * specified value.      *     * @param   defaultusecaches   the new value.     * @see     #getDefaultUseCaches()     */    public void setDefaultUseCaches(boolean defaultusecaches) {	defaultUseCaches = defaultusecaches;    }    /**     * Sets the general request property. If a property with the key already     * exists, overwrite its value with the new value.     *     * <p> NOTE: HTTP requires all request properties which can     * legally have multiple instances with the same key     * to use a comma-seperated list syntax which enables multiple     * properties to be appended into a single property.     *     * @param   key     the keyword by which the request is known     *                  (e.g., "<code>accept</code>").     * @param   value   the value associated with it.     * @throws IllegalStateException if already connected     * @throws NullPointerException if key is <CODE>null</CODE>     * @see #getRequestProperty(java.lang.String)     */    public void setRequestProperty(String key, String value) {	if (connected)	    throw new IllegalStateException("Already connected");	if (key == null) 	    throw new NullPointerException ("key is null");    }    /**     * Adds a general request property specified by a     * key-value pair.  This method will not overwrite     * existing values associated with the same key.     *     * @param   key     the keyword by which the request is known     *                  (e.g., "<code>accept</code>").     * @param   value  the value associated with it.     * @throws IllegalStateException if already connected     * @throws NullPointerException if key is null     * @see #getRequestProperties(java.lang.String)     * @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");    }    /**     * Returns the value of the named general request property for this     * connection.     *     * @param key the keyword by which the request is known (e.g., "accept").     * @return  the value of the named general request property for this     *           connection. If key is null, then null is returned.     * @throws IllegalStateException if already connected     * @see #setRequestProperty(java.lang.String, java.lang.String)     */    public String getRequestProperty(String key) {	if (connected)	    throw new IllegalStateException("Already connected");	return null;    }    /**     * Returns an unmodifiable Map of general request     * properties for this connection. The Map keys     * are Strings that represent the request-header     * field names. Each Map value is a unmodifiable List      * of Strings that represents the corresponding      * field values.     *     * @return  a Map of the general request properties for this connection.     * @throws IllegalStateException if already connected     * @since 1.4     */    public Map getRequestProperties() {        if (connected)            throw new IllegalStateException("Already connected");	return Collections.EMPTY_MAP;    }    /**     * Sets the default value of a general request property. When a      * <code>URLConnection</code> is created, it is initialized with      * these properties.      *     * param   key     the keyword by which the request is known     *                  (e.g., "<code>accept</code>").     * param   value   the value associated with the key.     *     * see java.net.URLConnection#setRequestProperty(java.lang.String,java.lang.String)      *     * deprecated The instance specific setRequestProperty method     * should be used after an appropriate instance of URLConnection     * is obtained.     *     * see #getDefaultRequestProperty(java.lang.String)     *    public static void setDefaultRequestProperty(String key, String value) {    }     */    /**     * Returns the value of the default request property. Default request      * properties are set for every connection.      *     * param key the keyword by which the request is known (e.g., "accept").     * return  the value of the default request property      * for the specified key.     *     * see java.net.URLConnection#getRequestProperty(java.lang.String)     *     * deprecated The instance specific getRequestProperty method     * should be used after an appropriate instance of URLConnection     * is obtained.     *     * see #setDefaultRequestProperty(java.lang.String, java.lang.String)     *    public static String getDefaultRequestProperty(String key) {	return null;    }     */    /**     * The ContentHandler factory.     */    static ContentHandlerFactory factory;    /**     * Sets the <code>ContentHandlerFactory</code> of an      * application. It can be called at most once by an application.      * <p>     * The <code>ContentHandlerFactory</code> instance is used to      * construct a content handler from a content type      * <p>     * If there is a security manager, this method first calls     * the security manager's <code>checkSetFactory</code> method      * to ensure the operation is allowed.      * This could result in a SecurityException.     *     * @param      fac   the desired factory.     * @exception  Error  if the factory has already been defined.     * @exception  SecurityException  if a security manager exists and its       *             <code>checkSetFactory</code> method doesn't allow the operation.     * @see        java.net.ContentHandlerFactory     * @see        java.net.URLConnection#getContent()     * @see        SecurityManager#checkSetFactory     */    public static synchronized void setContentHandlerFactory(ContentHandlerFactory fac) {	if (factory != null) {	    throw new Error("factory already defined");	}	SecurityManager security = System.getSecurityManager();	if (security != null) {	    security.checkSetFactory();	}	factory = fac;    }    private static Hashtable handlers = new Hashtable();    private static final ContentHandler UnknownContentHandlerP = new UnknownContentHandler();    /**     * Gets the Content Handler appropriate for this connection.     * @param connection the connection to use.     */    synchronized ContentHandler getContentHandler()    throws UnknownServiceException    {	String contentType = stripOffParameters(getContentType());	ContentHandler handler = null;	if (contentType == null)	    throw new UnknownServiceException("no content-type");	try {	    handler = (ContentHandler) handlers.get(contentType);	    if (handler != null)		return handler;	} catch(Exception e) {	}	if (factory != null)	    handler = factory.createContentHandler(contentType);	if (handler == null) {	    try {		handler = lookupContentHandlerClassFor(contentType);	    } catch(Exception e) {		e.printStackTrace();		handler = UnknownContentHandlerP;	    }	    handlers.put(contentType, handler);	}	return handler;    }    /*     * Media types are in the format: type/subtype*(; parameter).     * For looking up the content handler, we should ignore those     * parameters.     */    private String stripOffParameters(String contentType)    {	if (contentType == null)	    return null;	int index = contentType.indexOf(';');	if (index > 0)	    return contentType.substring(0, index);	else	    return contentType;    }    private static final String contentClassPrefix = "sun.net.www.content";    private static final String contentPathProp = "java.content.handler.pkgs";    /**     * Looks for a content handler in a user-defineable set of places.     * By default it looks in sun.net.www.content, but users can define a      * vertical-bar delimited set of class prefixes to search through in      * addition by defining the java.content.handler.pkgs property.     * The class name must be of the form:     * <pre>     *     {package-prefix}.{major}.{minor}     * e.g.     *     YoyoDyne.experimental.text.plain     * </pre>     */    private ContentHandler lookupContentHandlerClassFor(String contentType)	throws InstantiationException, IllegalAccessException, ClassNotFoundException {	String contentHandlerClassName = typeToPackageName(contentType);	String contentHandlerPkgPrefixes =getContentHandlerPkgPrefixes();	StringTokenizer packagePrefixIter =	    new StringTokenizer(contentHandlerPkgPrefixes, "|");		while (packagePrefixIter.hasMoreTokens()) {	    String packagePrefix = packagePrefixIter.nextToken().trim();	    try {		String clsName = packagePrefix + "." + contentHandlerClassName;		Class cls = null;		try {		    cls = Class.forName(clsName);		} catch (ClassNotFoundException e) {		    ClassLoader cl = ClassLoader.getSystemClassLoader();		    if (cl != null) {			cls = cl.loadClass(clsName);		    }		}		if (cls != null) {		    ContentHandler handler = 			(ContentHandler)cls.newInstance();		    return handler;		}	    } catch(Exception e) {	    }	}		return UnknownContentHandlerP;    }    /**     * Utility function to map a MIME content type into an equivalent     * pair of class name components.  For example: "text/html" would     * be returned as "text.html"     */    private String typeToPackageName(String contentType) {	// make sure we canonicalize the class name: all lower case	contentType = contentType.toLowerCase();	int len = contentType.length();	char nm[] = new char[len];	contentType.getChars(0, len, nm, 0);	for (int i = 0; i < len; i++) {	    char c = nm[i];	    if (c == '/') {		nm[i] = '.';	    } else if (!('A' <= c && c <= 'Z' ||		       'a' <= c && c <= 'z' ||		       '0' <= c && c <= '9')) {		nm[i] = '_';	    }	}	return new String(nm);    }    /**     * Returns a vertical bar separated list of package prefixes for potential     * content handlers.  Tries to get the java.content.handler.pkgs property     * to use as a set of package prefixes to search.  Whether or not     * that property has been defined, the sun.net.www.content is always

⌨️ 快捷键说明

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