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

📄 hostconfiguration.java

📁 Light in the box 抓取程序。 使用HttpClient
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public synchronized void setHost(final String host, final String virtualHost, int port,         final Protocol protocol) {        setHost(host, port, protocol);        this.params.setVirtualHost(virtualHost);    }    /**     * Sets the given host, port and protocol.     *        * @param host the host(IP or DNS name)     * @param port The port     * @param protocol the protocol     */    public synchronized void setHost(final String host, int port, final Protocol protocol) {        if (host == null) {            throw new IllegalArgumentException("host must not be null");           }        if (protocol == null) {            throw new IllegalArgumentException("protocol must not be null");           }        this.host = new HttpHost(host, port, protocol);    }    /**     * Sets the given host and port.  Uses the default protocol "http".     *      * @param host the host(IP or DNS name)     * @param port The port     */    public synchronized void setHost(final String host, int port) {        setHost(host, port, Protocol.getProtocol("http"));    }        /**     * Set the given host. Uses the default protocol("http") and its port.     *      * @param host The host(IP or DNS name).     */    public synchronized void setHost(final String host) {        Protocol defaultProtocol = Protocol.getProtocol("http");         setHost(host, defaultProtocol.getDefaultPort(), defaultProtocol);    }        /**     * Sets the protocol, host and port from the given URI.     * @param uri the URI.     */    public synchronized void setHost(final URI uri) {        try {            setHost(uri.getHost(), uri.getPort(), uri.getScheme());        } catch (URIException e) {            throw new IllegalArgumentException(e.toString());        }    }    /**     * Return the host url.     *      * @return The host url.     */    public synchronized String getHostURL() {        if (this.host == null) {            throw new IllegalStateException("Host must be set to create a host URL");           } else {            return this.host.toURI();        }    }    /**     * Returns the host.     *      * @return the host(IP or DNS name), or <code>null</code> if not set     *      * @see #isHostSet()     */    public synchronized String getHost() {        if (this.host != null) {            return this.host.getHostName();        } else {            return null;        }    }    /**     * Returns the virtual host.     *      * @return the virtual host name, or <code>null</code> if not set     *      * @deprecated use HostParams     */    public synchronized String getVirtualHost() {        return this.params.getVirtualHost();    }    /**     * Returns the port.     *      * @return the host port, or <code>-1</code> if not set     *      * @see #isHostSet()     */    public synchronized int getPort() {        if (this.host != null) {            return this.host.getPort();        } else {            return -1;        }    }    /**     * Returns the protocol.     * @return The protocol.     */    public synchronized Protocol getProtocol() {        if (this.host != null) {            return this.host.getProtocol();        } else {            return null;        }    }    /**     * Tests if the proxy host/port have been set.     *      * @return <code>true</code> if a proxy server has been set.     *      * @see #setProxy(String, int)     *      * @deprecated no longer used     */        public synchronized boolean isProxySet() {        return this.proxyHost != null;       }    /**     * Sets the given proxy host     *      * @param proxyHost the proxy host     */    public synchronized void setProxyHost(final ProxyHost proxyHost) {        this.proxyHost = proxyHost;    }        /**     * Set the proxy settings.     * @param proxyHost The proxy host     * @param proxyPort The proxy port     */    public synchronized void setProxy(final String proxyHost, int proxyPort) {        this.proxyHost = new ProxyHost(proxyHost, proxyPort);     }    /**     * Returns the proxyHost.     *      * @return the proxy host, or <code>null</code> if not set     *      * @see #isProxySet()     */    public synchronized String getProxyHost() {        if (this.proxyHost != null) {            return this.proxyHost.getHostName();        } else {            return null;        }    }    /**     * Returns the proxyPort.     *      * @return the proxy port, or <code>-1</code> if not set     *      * @see #isProxySet()     */    public synchronized int getProxyPort() {        if (this.proxyHost != null) {            return this.proxyHost.getPort();        } else {            return -1;        }    }    /**     * Set the local address to be used when creating connections.     * If this is unset, the default address will be used.     * This is useful for specifying the interface to use on multi-homed or clustered systems.     *      * @param localAddress the local address to use     */        public synchronized void setLocalAddress(InetAddress localAddress) {        this.localAddress = localAddress;    }    /**     * Return the local address to be used when creating connections.     * If this is unset, the default address should be used.     *      * @return the local address to be used when creating Sockets, or <code>null</code>     */        public synchronized InetAddress getLocalAddress() {        return this.localAddress;    }        /**     * Returns {@link HostParams HTTP protocol parameters} associated with this host.     *     * @return HTTP parameters.     *     * @since 3.0     */    public HostParams getParams() {        return this.params;    }    /**     * Assigns {@link HostParams HTTP protocol parameters} specific to this host.     *      * @since 3.0     *      * @see HostParams     */    public void setParams(final HostParams params) {        if (params == null) {            throw new IllegalArgumentException("Parameters may not be null");        }        this.params = params;    }    /**     * @see java.lang.Object#equals(java.lang.Object)     */    public synchronized boolean equals(final Object o) {        if (o instanceof HostConfiguration) {            // shortcut if we're comparing with ourselves            if (o == this) {                 return true;            }            HostConfiguration that = (HostConfiguration) o;            return LangUtils.equals(this.host, that.host)                && LangUtils.equals(this.proxyHost, that.proxyHost)                && LangUtils.equals(this.localAddress, that.localAddress);        } else {            return false;        }            }    /**     * @see java.lang.Object#hashCode()     */    public synchronized int hashCode() {        int hash = LangUtils.HASH_SEED;        hash = LangUtils.hashCode(hash, this.host);        hash = LangUtils.hashCode(hash, this.proxyHost);        hash = LangUtils.hashCode(hash, this.localAddress);        return hash;    }}

⌨️ 快捷键说明

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