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 of
Proxy stores 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. -
Field Summary
-
Constructor Summary
Constructors Constructor Description Proxy(Proxy.Type type, SocketAddress sa)Creates a newProxyinstance. -
Method Summary
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 Details
-
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 Details
-
Proxy
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 Details
-
type
Gets the type of thisProxyinstance.- Returns:
- the stored proxy type.
-
address
Gets the address of thisProxyinstance.- Returns:
- the stored proxy address or
nullif the proxy type isDIRECT.
-
toString
Gets a textual representation of thisProxyinstance. The string includes the two partstype.toString()andaddress.toString()ifaddressis notnull. -
equals
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)
-