org.elkoserver.foundation.net
Class NetAddr

java.lang.Object
  extended by org.elkoserver.foundation.net.NetAddr

public class NetAddr
extends Object

An IP network address and port number combination, represented in a somewhat friendlier way than InetSocketAddress does.


Constructor Summary
NetAddr(InetAddress inetAddress, int portNumber)
          Construct a new NetAddr given an IP address and a port number.
NetAddr(String addressStr)
          Construct a NetAddr from a string in the form: hostName:portNumber or hostName.
 
Method Summary
 boolean equals(Object other)
          Test if another object is a NetAddr denoting the same address as this.
 int getPort()
          Get the port number.
 int hashCode()
          Get a hash code for this address.
 InetAddress inetAddress()
          Get the IP address.
 String toString()
          Produce a printable representation of this.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NetAddr

public NetAddr(String addressStr)
        throws UnknownHostException
Construct a NetAddr from a string in the form: hostName:portNumber or hostName. If the :portNumber is omitted, port number 0 will be assumed. The host name may be either a DNS name or a raw IPv4 address in dotted decimal format. Alternatively, it may be both these, separated by a slash, in which case only the part after the slash is significant. If the significant part of the hostname is absent, then the port is associated with all local IP addresses.

Parameters:
addressStr - The network address string, as described above.
Throws:
UnknownHostException - if the host name can't be resolved.

NetAddr

public NetAddr(InetAddress inetAddress,
               int portNumber)
Construct a new NetAddr given an IP address and a port number.

Parameters:
inetAddress - An IP address, where null => all local IP addresses.
portNumber - A port at that IP address.
Method Detail

equals

public boolean equals(Object other)
Test if another object is a NetAddr denoting the same address as this.

Overrides:
equals in class Object
Parameters:
other - The other object to test for equality.
Returns:
true if this and 'other' denote the same net address.

inetAddress

public InetAddress inetAddress()
Get the IP address.

Returns:
the IP address embodied by this object.

getPort

public int getPort()
Get the port number.

Returns:
the port number embodied by this object.

hashCode

public int hashCode()
Get a hash code for this address.

Overrides:
hashCode in class Object
Returns:
a hash code that accounts for both the IP address and port.

toString

public String toString()
Produce a printable representation of this.

Overrides:
toString in class Object
Returns:
a nicely formatted string representing this address.