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

📄 protocol.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
         * RFC:  Add back protocol stripped by Content Connection.         */                return protocol + ":" + saved_url;    }    /**      * Get the protocol scheme parsed from the URL.     *     * @return protocol scheme is "http"      */    public String getProtocol() {        return protocol;    }    /**      * Get the host name parsed from the URL.     *     * @return host name from the parsed URL     */    public String getHost() {        return (url.host.length() == 0 ? null : url.host);    }    /**      * Get the file path name parsed from the URL.     *     * @return file path name from the parsed URL     */    public String getFile() {        return url.path;    }    /**      * Get the fragment identifier  parsed from the URL.     *     * @return reference component from the parsed URL     */    public String getRef() {        return url.fragment;    }    /**      * Get the query string  parsed from the URL.     *     * @return query string from the parsed URL     */    public String getQuery() {        return url.query;    }    /**      * Get the query string  parsed from the URL.     *     * @return query string from the parsed URL     */    public int getPort() {        return url.port;    }    /**      * Get the request method of the current connection.     *     * @return request method is GET, HEAD or POST     * @see #setRequestMethod     */    public String getRequestMethod() {        return method;    }    /**      * Set the request method of the current connection.     *     * @param method request method is GET, HEAD or POST     * @exception IOException is thrown if the connection is already open     * @see #getRequestMethod     */    public void setRequestMethod(String method) throws IOException {        if (state == CONNECT_STATE)            throw new IOException("connection already open");                if (!method.equals(HEAD) &&             !method.equals(GET) &&             !method.equals(POST)) {            throw new IOException("unsupported method: " + method);        }                this.method = method;    }    /**      * Get the request header value for the named property.     *     * @param key property name of specific HTTP 1.1 header field     * @return value of the named property, if found, null otherwise.     * @see #setRequestProperty     */    public String getRequestProperty(String key) {                /* https handles the proxy fields in a different way */        if (key.startsWith("Proxy-")) {            return proxyHeaders.getProperty(key);        }        return reqProperties.getProperty(key);    }    /**     * Set the request header name/value of specific HTTP 1.1 header field.     *     * @param key property name      * @param value property value     * @exception IllegalArgumentException is thrown if value contains CRLF.     * @exception IOException  If some other kind of I/O error occurs.     * @see #getRequestProperty     */    public void setRequestProperty(String key, String value) throws            IOException {                if (state == CONNECT_STATE)            throw new IOException("connection already open");        if ((value.indexOf("\r\n")) != -1) {                        // illegal values passed for properties - raise an exception                   throw new IllegalArgumentException("illegal value found");        }        setRequestField(key, value);    }    /**     * Add the named field to the list of request fields.     * This method is where a subclass should override properties.     *     * @param key key for the request header field.     * @param value the value for the request header field.     */    protected void setRequestField(String key, String value) {        /* https handles the proxy fields in a different way */        if (key.startsWith("Proxy-")) {            proxyHeaders.setProperty(key, value);            return;        }        /*         * if application setRequestProperties("Connection", "close")         * then we need to know this & take appropriate default close action         */        if ((key.equals("Connection")) && (value.equals("close"))) {            ConnectionCloseFlag = true;        }        if ((key.equals("Transfer-Encoding")) && (value.equals("chunked"))) {            chunkedOut = true;        }        reqProperties.setProperty(key, value);    }    /**      * Get the response code of the current request.     *     * @return numeric value of the parsed response code     * @exception IOException is thrown if a network error ocurrs     */       public int getResponseCode() throws IOException {        /*         * move to READ state at the end of the sendRequest()         */        sendRequest(READ_STATE);        return responseCode;    }    /**      * Get the response message of the current request.     *     * @return message associated with the current response header     * @exception IOException is thrown if a network error ocurrs     */       public String getResponseMessage() throws IOException {        /*         * move to READ state at the end of the sendRequest()         */        sendRequest(READ_STATE);        return responseMsg;    }    /**      * Get the Content-Length for the current response.     *     * @return length of data to be transmitted after the response headers     */       public long getLength() {                try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return -1;        }	return getHeaderFieldInt("content-length", -1);    }    /**      * Get the Content-Type for the current response.     *     * @return MIME type of data to be transmitted after the response header     */       public String getType() {                try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return null;        }	return getHeaderField("content-type");    }    /**      * Get the Content-Encoding for the current response.     *     * @return encoding type of data to be transmitted after the      *         response headers     */       public String getEncoding() {        try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return null;        }	return getHeaderField("content-encoding");    }    /**      * Get the Expires header for the current response.     *     * @return expiration data for the transmitted data     */       public long getExpiration() {	return getHeaderFieldDate("expires", 0);    }    /**      * Get the Date header for the current response.     *     * @return timestamp for the data transmission event     */       public long getDate() {	return getHeaderFieldDate("date", 0);    }    /**      * Get the Last-Modified date header for the current response.     *     * @return timestamp for the transmitted data last modification     */       public long getLastModified() {	return getHeaderFieldDate("last-modified", 0);    }    /**      * Get the named header field  for the current response.     *     * @param name header field to be examined     * @return value of requested header, if found, otherwise null     */       public String getHeaderField(String name) {        try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return null;        }        return (headerFields.getProperty(toLowerCase(name)));    }        /**      * Get the indexed header field  for the current response.     *     * @param index header field offset to be examined     * @return key name of requested header, if found, otherwise null     */       public String getHeaderField(int index) {        try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return null;        }                if (index >= headerFields.size())            return null;                return (headerFields.getValueAt(index));    }    /**      * Get the indexed header field value for the current response.     *     * @param index header field value offset to be examined     * @return value of requested header, if found, otherwise null     */       public String getHeaderFieldKey(int index) {        try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }        catch (IOException x) {            return null;        }        if (index >= headerFields.size())            return null;                return ((String)(headerFields.getKeyAt(index)));    }        /**      * Get the named header field  for the current response and return a      * numeric value for the parsed field, with a supplied default value       * if the field does not exist or can not be parsed cleanly.     *     * @param name of the field to be examined     * @param def default value to use, if field is not parsable     * @return numeric value of requested header, if found, otherwise      *         supplied default is returned     */       public int getHeaderFieldInt(String name, int def) {	try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        }	catch (IOException x) {            return def;        }	try {	    return Integer.parseInt(getHeaderField(name));	}         catch (IllegalArgumentException iae) { }        catch (NullPointerException npe) { }	return def;    }    /**      * Get the named header field for the current response and return a date     * value for the parsed field,with a supplied default value if the field     * does not exist or can not be parsed cleanly.     *     * @param name of the field to be examined     * @param def default value to use, if field is not parsable     * @return date value of requested header, if found, otherwise      *         supplied default is returned     */       public long getHeaderFieldDate(String name, long def) {                try {            /*             * move to READ state at the end of the sendRequest()             */            sendRequest(READ_STATE);        } catch (IOException x) {            return def;        }        try {            return DateParser.parse(getHeaderField(name));        }         catch (NumberFormatException nfe) { }        catch (IllegalArgumentException iae) { }        catch (NullPointerException npe) { }                return def;    }    /**      * Connect to the underlying socket transport.     * If an http_proxy was specified the socket connection will be made to 

⌨️ 快捷键说明

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