Top Description Inners Fields Constructors Methods
java.net

public Class Proxy

extends Object
Class Inheritance
Known Direct Subclasses
sun.net.ApplicationProxy, sun.net.SocksProxy
Imports
java.util.Objects

This class represents a proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object.
Authors
Yingxian Wang, Jean-Christophe Collet
Since
1.5
See Also
java.net.ProxySelector

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Proxy.Type

Represents the proxy type.

Field Summary

Modifier and TypeField and Description
public static final Proxy
NO_PROXY

A proxy setting that represents a DIRECT connection, basically telling the protocol handler not to use any proxying.

private final SocketAddress
private final Proxy.Type

Constructor Summary

AccessConstructor and Description
private
public
Proxy(Proxy.Type
the Type of the proxy
type
,
SocketAddress
the SocketAddress for that proxy
sa
)

Creates an entry representing a PROXY connection.

Method Summary

Modifier and TypeMethod and Description
public SocketAddress

Returns:

a SocketAddress representing the socket end point of the proxy
address
()

Returns the socket address of the proxy, or null if it's a direct connection.

public final boolean

Returns:

true if the objects are the same; false otherwise.
equals
(Object
the object to compare against.
obj
)

Overrides java.lang.Object.equals.

Compares this object against the specified object.

public final int

Returns:

a hash code value for this Proxy
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this Proxy.

public String

Returns:

a string representation of this object.
toString
()

Overrides java.lang.Object.toString.

Constructs a string representation of this Proxy.

public Proxy.Type

Returns:

a Type representing the proxy type
type
()

Returns the proxy type.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

NO_PROXYback to summary
public static final Proxy NO_PROXY

A proxy setting that represents a DIRECT connection, basically telling the protocol handler not to use any proxying. Used, for instance, to create sockets bypassing any other global proxy settings (like SOCKS):

Socket s = new Socket(Proxy.NO_PROXY);

saback to summary
private final SocketAddress sa
typeback to summary
private final Proxy.Type type

Constructor Detail

Proxyback to summary
private Proxy()
Proxyback to summary
public Proxy(Proxy.Type type, SocketAddress sa)

Creates an entry representing a PROXY connection. Certain combinations are illegal. For instance, for types Http, and Socks, a SocketAddress must be provided.

Use the Proxy.NO_PROXY constant for representing a direct connection.

Parameters
type:Proxy.Type

the Type of the proxy

sa:SocketAddress

the SocketAddress for that proxy

Exceptions
IllegalArgumentException:
when the type and the address are incompatible

Method Detail

addressback to summary
public SocketAddress address()

Returns the socket address of the proxy, or null if it's a direct connection.

Returns:SocketAddress

a SocketAddress representing the socket end point of the proxy

equalsback to summary
public final boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares this object against the specified object. The result is true if and only if the argument is not null and it represents the same proxy as this object.

Two instances of Proxy represent the same address if both the SocketAddresses and type are equal.

Parameters
obj:Object

the object to compare against.

Returns:boolean

true if the objects are the same; false otherwise.

Annotations
@Override
See Also
java.net.InetSocketAddress#equals(java.lang.Object)
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this Proxy.

Returns:int

a hash code value for this Proxy

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Constructs a string representation of this Proxy. This String is constructed by calling toString() on its type and concatenating " @ " and the toString() result from its address if its type is not DIRECT.

Returns:String

a string representation of this object.

typeback to summary
public Proxy.Type type()

Returns the proxy type.

Returns:Proxy.Type

a Type representing the proxy type

java.net back to summary

public final Enum Proxy.Type

extends Enum<Proxy.Type>
Class Inheritance

Represents the proxy type.
Since
1.5

Field Summary

Modifier and TypeField and Description
public static final Proxy.Type
DIRECT

Represents a direct connection, or the absence of a proxy.

public static final Proxy.Type
HTTP

Represents proxy for high level protocols such as HTTP or FTP.

public static final Proxy.Type
SOCKS

Represents a SOCKS (V4 or V5) proxy.

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public static Proxy.Type
public static Proxy.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DIRECTback to summary
public static final Proxy.Type DIRECT

Represents a direct connection, or the absence of a proxy.

HTTPback to summary
public static final Proxy.Type HTTP

Represents proxy for high level protocols such as HTTP or FTP.

SOCKSback to summary
public static final Proxy.Type SOCKS

Represents a SOCKS (V4 or V5) proxy.

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static Proxy.Type valueOf(String name)
valuesback to summary
public static Proxy.Type[] values()