FileDocCategorySizeDatePackage
Proxy.javaAPI DocAndroid 1.5 API5792Wed May 06 22:41:04 BST 2009java.net

Proxy

public class Proxy extends Object
This class represents proxy server settings. A created instance of {@code Proxy} stores a type and an address and is immutable. There are three types of proxies:
  • DIRECT
  • HTTP
  • SOCKS
since
Android 1.0

Fields Summary
public static final Proxy
NO_PROXY
Represents the proxy type setting {@code Proxy.Type.DIRECT}. It tells protocol handlers that there is no proxy to be used. The address is set to {@code null}.
private Type
type
private SocketAddress
address
Constructors Summary
public Proxy(Type type, SocketAddress sa)
Creates a new {@code Proxy} instance. {@code SocketAddress} must NOT be {@code null} when {@code type} is either {@code Proxy.Type.HTTP} or {@code Proxy.Type.SOCKS}. To create a {@code Proxy} instance representing the proxy type {@code Proxy.Type.DIRECT}, use {@code Proxy.NO_PROXY} instead of this constructor.

param
type the proxy type of this instance.
param
sa the proxy address of this instance.
throws
IllegalArgumentException if the parameter {@code type} is set to {@code Proxy.Type.DIRECT} or the value for {@code SocketAddress} is {@code null}.
since
Android 1.0


                                                                                                                                                      
         
        /*
         * Don't use DIRECT type to construct a proxy instance directly.
         * SocketAddress must NOT be null.
         */
        if (type == Type.DIRECT || null == sa) {
            // KA022=Illegal Proxy.Type or SocketAddress argument
            throw new IllegalArgumentException(Msg.getString("KA022")); //$NON-NLS-1$
        }
        this.type = type;
        address = sa;
    
private Proxy()

        type = Type.DIRECT;
        address = null;
    
Methods Summary
public java.net.SocketAddressaddress()
Gets the address of this {@code Proxy} instance.

return
the stored proxy address or {@code null} if the proxy type is {@code DIRECT}.
since
Android 1.0

        return address;
    
public final booleanequals(java.lang.Object obj)
Compares the specified {@code obj} to this {@code Proxy} instance and returns whether they are equal or not. The given object must be an instance of {@code Proxy} with the same address and the same type value to be equal.

param
obj the object to compare with this instance.
return
{@code true} if the given object represents the same {@code Proxy} as this instance, {@code false} otherwise.
see
#hashCode
since
Android 1.0

        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Proxy)) {
            return false;
        }
        Proxy another = (Proxy) obj;
        // address is null when and only when it's NO_PROXY.
        return (type == another.type) && address.equals(another.address);
    
public final inthashCode()
Gets the hashcode for this {@code Proxy} instance.

return
the hashcode value for this Proxy instance.
since
Android 1.0

        int ret = 0;
        ret += type.hashCode();
        if (null != address) {
            ret += address.hashCode();
        }
        return ret;
    
public java.lang.StringtoString()
Gets a textual representation of this {@code Proxy} instance. The string includes the two parts {@code type.toString()} and {@code address.toString()} if {@code address} is not {@code null}.

return
the representing string of this proxy.
since
Android 1.0

        String proxyString = String.valueOf(type);
        if (null != address) {
            proxyString += "/" + address.toString(); //$NON-NLS-1$
        }
        return proxyString;
    
public java.net.Proxy$Typetype()
Gets the type of this {@code Proxy} instance.

return
the stored proxy type.
since
Android 1.0

        return type;