public final class

HttpHost

extends Object
implements Cloneable
java.lang.Object
   ↳ org.apache.http.HttpHost

Class Overview

Holds all of the variables needed to describe an HTTP connection to a host. This includes remote host name, port and scheme.

Summary

Constants
String DEFAULT_SCHEME_NAME The default scheme is "http".
Fields
protected final String hostname The host to use.
protected final String lcHostname The lowercase host, for equals(Object) and hashCode().
protected final int port The port to use.
protected final String schemeName The scheme
Public Constructors
HttpHost(String hostname, int port, String scheme)
Creates a new HttpHost, specifying all values.
HttpHost(String hostname, int port)
Creates a new HttpHost, with default scheme.
HttpHost(String hostname)
Creates a new HttpHost, with default scheme and port.
HttpHost(HttpHost httphost)
Copy constructor for HttpHost.
Public Methods
Object clone()
Creates and returns a copy of this Object.
boolean equals(Object obj)
Compares this instance with the specified object and indicates if they are equal.
String getHostName()
Returns the host name.
int getPort()
Returns the port.
String getSchemeName()
Returns the scheme name.
int hashCode()
Returns an integer hash code for this object.
String toHostString()
Obtains the host string, without scheme prefix.
String toString()
Returns a string containing a concise, human-readable description of this object.
String toURI()
Return the host URI, as a string.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DEFAULT_SCHEME_NAME

Since: API Level 1

The default scheme is "http".

Constant Value: "http"

Fields

protected final String hostname

Since: API Level 1

The host to use.

protected final String lcHostname

Since: API Level 1

The lowercase host, for equals(Object) and hashCode().

protected final int port

Since: API Level 1

The port to use.

protected final String schemeName

Since: API Level 1

The scheme

Public Constructors

public HttpHost (String hostname, int port, String scheme)

Since: API Level 1

Creates a new HttpHost, specifying all values. Constructor for HttpHost.

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

public HttpHost (String hostname, int port)

Since: API Level 1

Creates a new HttpHost, with default scheme.

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

public HttpHost (String hostname)

Since: API Level 1

Creates a new HttpHost, with default scheme and port.

Parameters
hostname the hostname (IP or DNS name)

public HttpHost (HttpHost httphost)

Since: API Level 1

Copy constructor for HttpHost.

Parameters
httphost the HTTP host to copy details from

Public Methods

public Object clone ()

Since: API Level 1

Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.

public boolean equals (Object obj)

Since: API Level 1

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be both transitive and reflexive.

The implementation in Object returns true only if o is the exact same object as the receiver (using the == operator for comparison). Subclasses often implement equals(Object) so that it takes into account the two object's types and states.

The general contract for the equals(Object) and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or none of them.

Parameters
obj the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object; false otherwise.

public String getHostName ()

Since: API Level 1

Returns the host name.

Returns
  • the host name (IP or DNS name)

public int getPort ()

Since: API Level 1

Returns the port.

Returns
  • the host port, or -1 if not set

public String getSchemeName ()

Since: API Level 1

Returns the scheme name.

Returns
  • the scheme name

public int hashCode ()

Since: API Level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Returns
  • this object's hash code.
See Also

public String toHostString ()

Since: API Level 1

Obtains the host string, without scheme prefix.

Returns
  • the host string, for example localhost:8080

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a printable representation of this object.

public String toURI ()

Since: API Level 1

Return the host URI, as a string.

Returns
  • the host URI