org.apache.james.jspf.core
Class IPAddr

java.lang.Object
  extended by org.apache.james.jspf.core.IPAddr

public class IPAddr
extends java.lang.Object


Method Summary
static IPAddr getAddress(java.lang.String netAddress)
           
static IPAddr getAddress(java.lang.String netAddress, int maskLength)
          Get ipAddress for the given String and netmask
static java.lang.String getInAddress(java.lang.String ipAddress)
          This method return the InAddress for the given ip.
 java.lang.String getIPAddress()
           
 java.lang.String getMaskedIPAddress()
           
 int getMaskLength()
          Get mask length
 java.lang.String getNibbleFormat()
          Return the NibbleFormat of the IPAddr
static java.lang.String getProperIpAddress(java.lang.String ip)
          This method convert the given ip to the proper format.
static java.lang.String getReadableIP(java.lang.String ip)
          This method try to covnert an ip address to an easy readable ip.
 java.lang.String getReverseIP()
          Get reverse ipAddress
static boolean isIPAddr(java.lang.String data)
          Check if a the Object is instance of this class
static boolean isIPV6(java.lang.String ip)
          Return if the given ipAddress is ipv6
static boolean isValidIP(java.lang.String ip)
          Check if the given IP is valid.
 void setMask(int maskLength)
          create series of 16 bit masks for each ip block
static java.lang.String stripDot(java.lang.String data)
          Strip the last char of a string when it ends with a dot
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getAddress

public static IPAddr getAddress(java.lang.String netAddress,
                                int maskLength)
                         throws PermErrorException
Get ipAddress for the given String and netmask

Parameters:
netAddress - The ipAddress given as String
maskLength - The netmask
Returns:
IpAddress AAn Arraylist which contains all ipAddresses
Throws:
PermErrorException - on error

getAddress

public static IPAddr getAddress(java.lang.String netAddress)
                         throws PermErrorException
Throws:
PermErrorException
See Also:
getAddress(String, int)

isIPAddr

public static boolean isIPAddr(java.lang.String data)
Check if a the Object is instance of this class

Parameters:
data - The object to check
Returns:
true or false

setMask

public void setMask(int maskLength)
create series of 16 bit masks for each ip block

Parameters:
maskLength - The netmask

stripDot

public static java.lang.String stripDot(java.lang.String data)
Strip the last char of a string when it ends with a dot

Parameters:
data - The String where the dot should removed
Returns:
modified The Given String with last char stripped

getIPAddress

public java.lang.String getIPAddress()
See Also:
getInAddress(String)

getMaskedIPAddress

public java.lang.String getMaskedIPAddress()
See Also:
getIPAddress(int[])

getNibbleFormat

public java.lang.String getNibbleFormat()
Return the NibbleFormat of the IPAddr

Returns:
ipAddress The ipAddress in nibbleFormat

getReverseIP

public java.lang.String getReverseIP()
Get reverse ipAddress

Returns:
reverse ipAddress

getMaskLength

public int getMaskLength()
Get mask length

Returns:
maskLength

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getInAddress

public static java.lang.String getInAddress(java.lang.String ipAddress)
                                     throws PermErrorException
This method return the InAddress for the given ip.

Parameters:
ipAddress - - ipAddress that should be processed
Returns:
the inAddress (in-addr or ip6)
Throws:
PermErrorException - if the ipAddress is not valid (rfc conform)

isValidIP

public static boolean isValidIP(java.lang.String ip)
Check if the given IP is valid. Works with ipv4 and ip6

Parameters:
ip - The ipaddress to check
Returns:
true or false

isIPV6

public static boolean isIPV6(java.lang.String ip)
Return if the given ipAddress is ipv6

Parameters:
ip - The ipAddress
Returns:
true or false

getReadableIP

public static java.lang.String getReadableIP(java.lang.String ip)
This method try to covnert an ip address to an easy readable ip. See http://java.sun.com/j2se/1.4.2/docs/api/java/net/Inet6Address.html for the format it returns. For ipv4 it make no convertion

Parameters:
ip - The ip which should be tried to convert
Returns:
ip The converted ip

getProperIpAddress

public static java.lang.String getProperIpAddress(java.lang.String ip)
                                           throws PermErrorException
This method convert the given ip to the proper format. Convertion will only done if the given ipAddress is ipv6 and ipv4-mapped This must be done to correct handle IPv4-mapped-addresses. See: http://java.sun.com/j2se/1.4.2/docs/api/java/net/Inet6Address.html Special IPv6 address: IPv4-mapped address: Of the form::ffff:w.x.y.z, this IPv6 address is used to represent an IPv4 address. It allows the native program to use the same address data structure and also the same socket when communicating with both IPv4 and IPv6 nodes. In InetAddress and Inet6Address, it is used for internal representation; it has no functional role. Java will never return an IPv4-mapped address. These classes can take an IPv4-mapped address as input, both in byte array and text representation. However, it will be converted into an IPv4 address.

Parameters:
ip - the ipAddress to convert
Returns:
return converted ip
Throws:
PermErrorException - if the given ipAddress is invalid


Copyright © 2006-2009 The Apache Software Foundation. All Rights Reserved.