public class NetworkAddress extends Object
| Constructor and Description |
|---|
NetworkAddress()
Default constructor
|
NetworkAddress(InetAddress host,
int port)
Create an instance of
NetworkAddress using given host address and port. |
NetworkAddress(String str)
Parameterized constructor
|
NetworkAddress(String host,
int port)
Create an instance of
NetworkAddress using given host address and port. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all the values of this
NetworkAddress |
boolean |
equals(Object other) |
String |
getHostIp() |
String |
getHostName() |
InetAddress |
getIpAsInet()
Get the ip address as
InetAddress for the given hostIp |
int |
getPort() |
boolean |
isValid()
Check if ip and port are valid for this instance or not.
|
void |
setHostIp(String hostIp) |
void |
setHostName(String hostName) |
void |
setPort(int port) |
String |
toString()
Create a string for this instance.
|
void |
update(InetAddress host,
String hostName,
int port)
Update the current values of this
NetworkAddress with given values. |
void |
update(NetworkAddress address)
Update the current values of this
NetworkAddress with given instance of NetworkAddress. |
void |
update(String str)
Update the current values of this
NetworkAddress with given values. |
void |
update(String host,
int port)
Update the current values of this
NetworkAddress with given values. |
public NetworkAddress()
public NetworkAddress(String str) throws UnknownHostException
str - contains both ip and port separated with COLON (:). For ex - www.google.com:8080, 45.23.36.89:8547UnknownHostException - if any occurs while resolving the ip address.public NetworkAddress(String host, int port) throws UnknownHostException
NetworkAddress using given host address and port.host - Hostname or IP addressport - PortUnknownHostException - if any occurs while resolving the ip address.public NetworkAddress(InetAddress host, int port)
NetworkAddress using given host address and port.host - InetAddress instanceport - port for this NetworkAddresspublic String getHostIp()
public void setHostIp(String hostIp)
public String getHostName()
public void setHostName(String hostName) throws UnknownHostException
UnknownHostExceptionpublic int getPort()
public void setPort(int port)
public void update(String str) throws UnknownHostException
NetworkAddress with given values.str - contains both ip and port separated with COLON (:). For ex - www.google.com:8080, 45.23.36.89:8547UnknownHostException - if any occurs while resolving the ip address.public void update(String host, int port) throws UnknownHostException
NetworkAddress with given values.host - Hostname or IP addressport - PortUnknownHostException - if any occurs while resolving the ip address.public void update(InetAddress host, String hostName, int port)
NetworkAddress with given values.host - InetAddress instancehostName - Hostname of given InetAddress if there is any, otherwise, should be null.port - Port for this NetworkAddresspublic void update(NetworkAddress address)
NetworkAddress with given instance of NetworkAddress.address - values will be taken from this instance.public void clear()
NetworkAddresspublic InetAddress getIpAsInet() throws UnknownHostException
InetAddress for the given hostIpInetAddress for the given hostIpUnknownHostException - if any occurs while resolving the ip address.public boolean isValid()
public String toString()
Copyright © 2024. All rights reserved.