Package org.n52.janmayen.net
Class IPAddress
- java.lang.Object
-
- org.n52.janmayen.net.IPAddress
-
- All Implemented Interfaces:
Comparable<IPAddress>
public class IPAddress extends Object implements Comparable<IPAddress>
Encapsulation of an IP address.
-
-
Field Summary
Fields Modifier and Type Field Description static intIPV4_BIT_SIZEstatic intIPV4_BYTE_SIZEstatic intIPV6_BIT_SIZEstatic intIPV6_BYTE_SIZE
-
Constructor Summary
Constructors Constructor Description IPAddress(byte[] address)Creates a newIPAddressfrom an four element byte array.IPAddress(int address)Creates a newIPAddressfrom an 32-Bit integer.IPAddress(long upperBits, long lowerBits)Creates a newIPAddressfrom two 64-Bit integers.IPAddress(String address)Creates a newIPAddressfrom its string representation.IPAddress(InetAddress address)Creates a newIPAddressfrom anInetAddress.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static intcompareLittleEndianUnsignedByte(byte[] a, byte[] b)Compares tobytearrays.intcompareTo(IPAddress o)booleanequals(Object obj)intgetBitSize()Get the number of bits the address contains.byte[]getBytes()intgetByteSize()Get the number of bytes the address contains.InetAddressgetInetAddress()static PatterngetV4Pattern()Get the regular expression matching an IPv4.static PatterngetV6Pattern()Get the regular expression matching an IPv6.inthashCode()booleanisIPv4()Checks if this address is IPv4.booleanisIPv6()Checks if this address is IPv6.StringtoString()
-
-
-
Field Detail
-
IPV6_BYTE_SIZE
public static final int IPV6_BYTE_SIZE
- See Also:
- Constant Field Values
-
IPV4_BYTE_SIZE
public static final int IPV4_BYTE_SIZE
- See Also:
- Constant Field Values
-
IPV6_BIT_SIZE
public static final int IPV6_BIT_SIZE
- See Also:
- Constant Field Values
-
IPV4_BIT_SIZE
public static final int IPV4_BIT_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IPAddress
public IPAddress(int address)
Creates a newIPAddressfrom an 32-Bit integer.- Parameters:
address- the address
-
IPAddress
public IPAddress(long upperBits, long lowerBits)Creates a newIPAddressfrom two 64-Bit integers.- Parameters:
upperBits- the 64 upper bits of the addresslowerBits- the 64 lower bits of the address
-
IPAddress
public IPAddress(byte[] address)
Creates a newIPAddressfrom an four element byte array.- Parameters:
address- the address
-
IPAddress
public IPAddress(String address)
Creates a newIPAddressfrom its string representation.- Parameters:
address- the address
-
IPAddress
public IPAddress(InetAddress address)
Creates a newIPAddressfrom anInetAddress.- Parameters:
address- the address
-
-
Method Detail
-
isIPv4
public boolean isIPv4()
Checks if this address is IPv4.- Returns:
- if it is IPv4
-
getBitSize
public int getBitSize()
Get the number of bits the address contains.- Returns:
- the number of bits
-
getByteSize
public int getByteSize()
Get the number of bytes the address contains.- Returns:
- the number of bytes
-
isIPv6
public boolean isIPv6()
Checks if this address is IPv6.- Returns:
- if it is IPv6
-
getInetAddress
public InetAddress getInetAddress()
- Returns:
- the IP address as an
Inet4Address
-
getBytes
public byte[] getBytes()
- Returns:
- the IP address as an byte array.
-
compareTo
public int compareTo(IPAddress o)
- Specified by:
compareToin interfaceComparable<IPAddress>
-
compareLittleEndianUnsignedByte
static int compareLittleEndianUnsignedByte(byte[] a, byte[] b)Compares tobytearrays. Each element is compared with the corresponding element in the other array. If the array sizes differ the shorter array is treated as it would contain leading zeros.- Parameters:
a- the firstbytearrayb- the secondbytearray- Returns:
- the value
0ifa == b; a value less than0ifa < b; and a value greater than0ifa > b
-
getV4Pattern
public static Pattern getV4Pattern()
Get the regular expression matching an IPv4. No capturing groups are included in the pattern.- Returns:
- the pattern
-
getV6Pattern
public static Pattern getV6Pattern()
Get the regular expression matching an IPv6. No capturing groups are included in the pattern.- Returns:
- the pattern
-
-