toString(): This method is available in the java.net.Proxy class of Java.
Syntax:
String java.net.Proxy.toString()
This method constructs a string representation of this Proxy. This String is constructed by calling toString() on its type and concatenating " @ " and the toString() results from its address if its type is not DIRECT.
Parameters: NA
Returns: a string representation of this object.
Exceptions: NA
Approach
Java
package com.Proxy;import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.Proxy;import java.net.Proxy.Type;import java.net.SocketAddress;import java.net.UnknownHostException;public class ProxytoString {public static void main(String[] args) throws UnknownHostException {InetAddress addr = InetAddress.getByName("java.sun.com");int port = 80;SocketAddress sockaddr = new InetSocketAddress(addr, port);Proxy proxy = new Proxy(Type.HTTP, sockaddr);System.out.println(proxy.toString());}}
Output:
HTTP @ java.sun.com/23.54.83.211:80
Some other methods of Proxy class
Proxy(Type, SocketAddress): This method creates an entry representing a PROXY connection.
address(): This method returns the socket address of the proxy, or null if it's a direct connection.
Proxy Constants: Some of the Proxy constants like Proxy.NO_PROXY, Type.DIRECT, etc.
equals(Object): This method compares this object against the specified object.
hashCode(): This method returns a hashcode for this Proxy.
toString(): This method constructs a string representation of this Proxy. This String is constructed by calling toString() on its type and concatenating " @ " and the toString() results from its address if its type is not DIRECT.
type(): This method returns the proxy type.
No comments:
Post a Comment