FileDocCategorySizeDatePackage
HttpHost.javaAPI DocAndroid 1.5 API6612Wed May 06 22:41:10 BST 2009org.apache.http

HttpHost

public final class HttpHost extends Object implements Cloneable
Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host name, port and scheme.
author
Michael Becke
author
Mike Bowler
author
Oleg Kalnichevski
author
Laura Werner
since
4.0

Fields Summary
public static final String
DEFAULT_SCHEME_NAME
The default scheme is "http".
protected final String
hostname
The host to use.
protected final String
lcHostname
The lowercase host, for {@link #equals} and {@link #hashCode}.
protected final int
port
The port to use.
protected final String
schemeName
The scheme
Constructors Summary
public HttpHost(String hostname, int port, String scheme)
Creates a new {@link HttpHost HttpHost}, specifying all values. Constructor for HttpHost.

param
hostname the hostname (IP or DNS name)
param
port the port number. -1 indicates the scheme default port.
param
scheme the name of the scheme. null indicates the {@link #DEFAULT_SCHEME_NAME default scheme}



                                                                                                                     
             
        super();
        if (hostname == null) {
            throw new IllegalArgumentException("Host name may not be null");
        }
        this.hostname   = hostname;
        this.lcHostname = hostname.toLowerCase(Locale.ENGLISH);
        if (scheme != null) {
            this.schemeName = scheme.toLowerCase(Locale.ENGLISH);
        } else {
            this.schemeName = DEFAULT_SCHEME_NAME;
        }
        this.port = port;
    
public HttpHost(String hostname, int port)
Creates a new {@link HttpHost HttpHost}, with default scheme.

param
hostname the hostname (IP or DNS name)
param
port the port number. -1 indicates the scheme default port.

        this(hostname, port, null);
    
public HttpHost(String hostname)
Creates a new {@link HttpHost HttpHost}, with default scheme and port.

param
hostname the hostname (IP or DNS name)

        this(hostname, -1, null);
    
public HttpHost(HttpHost httphost)
Copy constructor for {@link HttpHost HttpHost}.

param
httphost the HTTP host to copy details from

        this(httphost.hostname, httphost.port, httphost.schemeName);
    
Methods Summary
public java.lang.Objectclone()

        return super.clone();
    
public booleanequals(java.lang.Object obj)

        if (obj == null) return false;
        if (this == obj) return true;
        if (obj instanceof HttpHost) {
            HttpHost that = (HttpHost) obj;
            return this.lcHostname.equals(that.lcHostname) 
                && this.port == that.port
                && this.schemeName.equals(that.schemeName);
        } else {
            return false;
        }
    
public java.lang.StringgetHostName()
Returns the host name.

return
the host name (IP or DNS name)

        return this.hostname;
    
public intgetPort()
Returns the port.

return
the host port, or -1 if not set

        return this.port;
    
public java.lang.StringgetSchemeName()
Returns the scheme name.

return
the scheme name

        return this.schemeName;
    
public inthashCode()

see
java.lang.Object#hashCode()

        int hash = LangUtils.HASH_SEED;
        hash = LangUtils.hashCode(hash, this.lcHostname);
        hash = LangUtils.hashCode(hash, this.port);
        hash = LangUtils.hashCode(hash, this.schemeName);
        return hash;
    
public java.lang.StringtoHostString()
Obtains the host string, without scheme prefix.

return
the host string, for example localhost:8080

        CharArrayBuffer buffer = new CharArrayBuffer(32);        
        buffer.append(this.hostname);
        if (this.port != -1) {
            buffer.append(':");
            buffer.append(Integer.toString(this.port));
        }
        return buffer.toString();
    
public java.lang.StringtoString()

        return toURI();
    
public java.lang.StringtoURI()
Return the host URI, as a string.

return
the host URI

        CharArrayBuffer buffer = new CharArrayBuffer(32);        
        buffer.append(this.schemeName);
        buffer.append("://");
        buffer.append(this.hostname);
        if (this.port != -1) {
            buffer.append(':");
            buffer.append(Integer.toString(this.port));
        }
        return buffer.toString();