Package com.reve.utils.ip
Class NetworkAddress
java.lang.Object
com.reve.utils.ip.NetworkAddress
Contains the information about IP and port of a network address.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructorNetworkAddress(String str) Parameterized constructorNetworkAddress(String host, int port) Create an instance ofNetworkAddressusing given host address and port.NetworkAddress(InetAddress host, int port) Create an instance ofNetworkAddressusing given host address and port. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all the values of thisNetworkAddressbooleanGet the ip address asInetAddressfor the givenhostIpintgetPort()booleanisValid()Check if ip and port are valid for this instance or not.voidvoidsetHostName(String hostName) voidsetPort(int port) toString()Create a string for this instance.voidupdate(NetworkAddress address) Update the current values of thisNetworkAddresswith given instance ofNetworkAddress.voidUpdate the current values of thisNetworkAddresswith given values.voidUpdate the current values of thisNetworkAddresswith given values.voidupdate(InetAddress host, String hostName, int port) Update the current values of thisNetworkAddresswith given values.
-
Constructor Details
-
NetworkAddress
public NetworkAddress()Default constructor -
NetworkAddress
Parameterized constructor- Parameters:
str- contains both ip and port separated with COLON (:). For ex - www.google.com:8080, 45.23.36.89:8547- Throws:
UnknownHostException- if any occurs while resolving the ip address.
-
NetworkAddress
Create an instance ofNetworkAddressusing given host address and port.- Parameters:
host- Hostname or IP addressport- Port- Throws:
UnknownHostException- if any occurs while resolving the ip address.
-
NetworkAddress
Create an instance ofNetworkAddressusing given host address and port.- Parameters:
host-InetAddressinstanceport- port for thisNetworkAddress
-
-
Method Details
-
getHostIp
-
setHostIp
-
getHostName
-
setHostName
- Throws:
UnknownHostException
-
getPort
public int getPort() -
setPort
public void setPort(int port) -
update
Update the current values of thisNetworkAddresswith given values.- Parameters:
str- contains both ip and port separated with COLON (:). For ex - www.google.com:8080, 45.23.36.89:8547- Throws:
UnknownHostException- if any occurs while resolving the ip address.
-
update
Update the current values of thisNetworkAddresswith given values.- Parameters:
host- Hostname or IP addressport- Port- Throws:
UnknownHostException- if any occurs while resolving the ip address.
-
update
Update the current values of thisNetworkAddresswith given values.- Parameters:
host-InetAddressinstancehostName- Hostname of givenInetAddressif there is any, otherwise, should be null.port- Port for thisNetworkAddress
-
update
Update the current values of thisNetworkAddresswith given instance ofNetworkAddress.- Parameters:
address- values will be taken from this instance.
-
clear
public void clear()Clear all the values of thisNetworkAddress -
getIpAsInet
Get the ip address asInetAddressfor the givenhostIp- Returns:
- the ip address as
InetAddressfor the givenhostIp - Throws:
UnknownHostException- if any occurs while resolving the ip address.
-
isValid
public boolean isValid()Check if ip and port are valid for this instance or not.- Returns:
- true, if valid, otherwise, return false.
-
toString
Create a string for this instance. -
equals
-