Package java.net
Class Proxy
- java.lang.Object
-
- java.net.Proxy
-
public class Proxy extends Object
This class represents proxy server settings. A created instance ofProxystores a type and an address and is immutable. There are three types of proxies:- DIRECT
- HTTP
- SOCKS
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProxy.TypeEnumclass for the proxy type.
-
Constructor Summary
Constructors Constructor Description Proxy(Proxy.Type type, SocketAddress sa)Creates a newProxyinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SocketAddressaddress()Gets the address of thisProxyinstance.booleanequals(Object obj)Compares the specifiedobjto thisProxyinstance and returns whether they are equal or not.inthashCode()Gets the hashcode for thisProxyinstance.StringtoString()Gets a textual representation of thisProxyinstance.Proxy.Typetype()Gets the type of thisProxyinstance.
-
-
-
Field Detail
-
NO_PROXY
public static final Proxy NO_PROXY
Represents the proxy type settingProxy.Type.DIRECT. It tells protocol handlers that there is no proxy to be used. The address is set tonull.
-
-
Constructor Detail
-
Proxy
public Proxy(Proxy.Type type, SocketAddress sa)
Creates a newProxyinstance.SocketAddressmust NOT benullwhentypeis eitherProxy.Type.HTTPorProxy.Type.SOCKS. To create aProxyinstance representing the proxy typeProxy.Type.DIRECT, useProxy.NO_PROXYinstead of this constructor.- Parameters:
type- the proxy type of this instance.sa- the proxy address of this instance.- Throws:
IllegalArgumentException- if the parametertypeis set toProxy.Type.DIRECTor the value forSocketAddressisnull.
-
-
Method Detail
-
type
public Proxy.Type type()
Gets the type of thisProxyinstance.- Returns:
- the stored proxy type.
-
address
public SocketAddress address()
Gets the address of thisProxyinstance.- Returns:
- the stored proxy address or
nullif the proxy type isDIRECT.
-
toString
public String toString()
Gets a textual representation of thisProxyinstance. The string includes the two partstype.toString()andaddress.toString()ifaddressis notnull.
-
equals
public final boolean equals(Object obj)
Compares the specifiedobjto thisProxyinstance and returns whether they are equal or not. The given object must be an instance ofProxywith the same address and the same type value to be equal.- Overrides:
equalsin classObject- Parameters:
obj- the object to compare with this instance.- Returns:
trueif the given object represents the sameProxyas this instance,falseotherwise.- See Also:
hashCode()
-
hashCode
public final int hashCode()
Gets the hashcode for thisProxyinstance.- Overrides:
hashCodein classObject- Returns:
- the hashcode value for this Proxy instance.
- See Also:
Object.equals(java.lang.Object)
-
-