Package org.n52.janmayen.net
Class IPAddress
java.lang.Object
org.n52.janmayen.net.IPAddress
- All Implemented Interfaces:
Comparable<IPAddress>
Encapsulation of an IP address.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionIPAddress(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.Creates a newIPAddressfrom its string representation.IPAddress(InetAddress address) Creates a newIPAddressfrom anInetAddress. -
Method Summary
Modifier and TypeMethodDescription(package private) static intcompareLittleEndianUnsignedByte(byte[] a, byte[] b) Compares tobytearrays.intbooleanintGet the number of bits the address contains.byte[]getBytes()intGet the number of bytes the address contains.static PatternGet the regular expression matching an IPv4.static PatternGet the regular expression matching an IPv6.inthashCode()booleanisIPv4()Checks if this address is IPv4.booleanisIPv6()Checks if this address is IPv6.toString()
-
Field Details
-
IPV6_BYTE_SIZE
public static final int IPV6_BYTE_SIZE- See Also:
-
IPV4_BYTE_SIZE
public static final int IPV4_BYTE_SIZE- See Also:
-
IPV6_BIT_SIZE
public static final int IPV6_BIT_SIZE- See Also:
-
IPV4_BIT_SIZE
public static final int IPV4_BIT_SIZE- See Also:
-
-
Constructor Details
-
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
Creates a newIPAddressfrom its string representation.- Parameters:
address- the address
-
IPAddress
Creates a newIPAddressfrom anInetAddress.- Parameters:
address- the address
-
-
Method Details
-
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
- Returns:
- the IP address as an
Inet4Address
-
getBytes
public byte[] getBytes()- Returns:
- the IP address as an byte array.
-
compareTo
- Specified by:
compareToin interfaceComparable<IPAddress>
-
hashCode
public int hashCode() -
equals
-
toString
-
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
Get the regular expression matching an IPv4. No capturing groups are included in the pattern.- Returns:
- the pattern
-
getV6Pattern
Get the regular expression matching an IPv6. No capturing groups are included in the pattern.- Returns:
- the pattern
-