Class NetworkAddress

java.lang.Object
com.reve.utils.ip.NetworkAddress

public class NetworkAddress extends Object
Contains the information about IP and port of a network address.
  • Constructor Details

    • NetworkAddress

      public NetworkAddress()
      Default constructor
    • NetworkAddress

      public NetworkAddress(String str) throws UnknownHostException
      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

      public NetworkAddress(String host, int port) throws UnknownHostException
      Create an instance of NetworkAddress using given host address and port.
      Parameters:
      host - Hostname or IP address
      port - Port
      Throws:
      UnknownHostException - if any occurs while resolving the ip address.
    • NetworkAddress

      public NetworkAddress(InetAddress host, int port)
      Create an instance of NetworkAddress using given host address and port.
      Parameters:
      host - InetAddress instance
      port - port for this NetworkAddress
  • Method Details

    • getHostIp

      public String getHostIp()
    • setHostIp

      public void setHostIp(String hostIp)
    • getHostName

      public String getHostName()
    • setHostName

      public void setHostName(String hostName) throws UnknownHostException
      Throws:
      UnknownHostException
    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
    • update

      public void update(String str) throws UnknownHostException
      Update the current values of this NetworkAddress with 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

      public void update(String host, int port) throws UnknownHostException
      Update the current values of this NetworkAddress with given values.
      Parameters:
      host - Hostname or IP address
      port - Port
      Throws:
      UnknownHostException - if any occurs while resolving the ip address.
    • update

      public void update(InetAddress host, String hostName, int port)
      Update the current values of this NetworkAddress with given values.
      Parameters:
      host - InetAddress instance
      hostName - Hostname of given InetAddress if there is any, otherwise, should be null.
      port - Port for this NetworkAddress
    • update

      public void update(NetworkAddress address)
      Update the current values of this NetworkAddress with given instance of NetworkAddress.
      Parameters:
      address - values will be taken from this instance.
    • clear

      public void clear()
      Clear all the values of this NetworkAddress
    • getIpAsInet

      public InetAddress getIpAsInet() throws UnknownHostException
      Get the ip address as InetAddress for the given hostIp
      Returns:
      the ip address as InetAddress for the given hostIp
      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

      public String toString()
      Create a string for this instance.
      Overrides:
      toString in class Object
      Returns:
      a string for this instance.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object