public class IpAddress extends java.lang.Object implements java.lang.Comparable<IpAddress>
Modifier and Type | Class and Description |
---|---|
static class |
IpAddress.Version |
Modifier and Type | Field and Description |
---|---|
static int |
INET_BIT_LENGTH |
static int |
INET_BYTE_LENGTH |
static int |
INET6_BIT_LENGTH |
static int |
INET6_BYTE_LENGTH |
Modifier | Constructor and Description |
---|---|
protected |
IpAddress()
Default constructor for Kryo serialization.
|
protected |
IpAddress(IpAddress.Version version,
byte[] value)
Constructor for given IP address version and address octets.
|
Modifier and Type | Method and Description |
---|---|
static int |
byteLength(IpAddress.Version version)
Computes the IP address byte length for a given IP version.
|
int |
compareTo(IpAddress o) |
boolean |
equals(java.lang.Object obj) |
Ip4Address |
getIp4Address()
Gets the
Ip4Address view of the IP address. |
Ip6Address |
getIp6Address()
Gets the
Ip6Address view of the IP address. |
int |
hashCode() |
boolean |
isIp4()
Tests whether the IP version of this address is IPv4.
|
boolean |
isIp6()
Tests whether the IP version of this address is IPv6.
|
boolean |
isLinkLocal()
Check if this IP address is a link-local address.
|
boolean |
isMulticast()
Check if this IP address is a multicast address.
|
boolean |
isSelfAssigned()
Check if this IP address is self-assigned.
|
boolean |
isZero()
Check if this IP address is zero.
|
static IpAddress |
makeMaskedAddress(IpAddress address,
int prefixLength)
Creates an IP address by masking it with a network mask of given
mask length.
|
static IpAddress |
makeMaskPrefix(IpAddress.Version version,
int prefixLength)
Creates an IP network mask prefix.
|
java.net.InetAddress |
toInetAddress()
Returns the IP address as InetAddress.
|
IpPrefix |
toIpPrefix()
Generates an IP prefix.
|
byte[] |
toOctets()
Returns the IP address as a byte array.
|
java.lang.String |
toString() |
static IpAddress |
valueOf(java.net.InetAddress inetAddress)
Converts an InetAddress into an IP address.
|
static IpAddress |
valueOf(int value)
Converts an integer into an IPv4 address.
|
static IpAddress |
valueOf(IpAddress.Version version,
byte[] value)
Converts a byte array into an IP address.
|
static IpAddress |
valueOf(IpAddress.Version version,
byte[] value,
int offset)
Converts a byte array and a given offset from the beginning of the
array into an IP address.
|
static IpAddress |
valueOf(java.lang.String value)
Converts an IPv4 or IPv6 string literal (e.g., "10.2.3.4" or
"1111:2222::8888") into an IP address.
|
IpAddress.Version |
version()
Returns the IP version of this address.
|
public static final int INET_BYTE_LENGTH
public static final int INET_BIT_LENGTH
public static final int INET6_BYTE_LENGTH
public static final int INET6_BIT_LENGTH
protected IpAddress(IpAddress.Version version, byte[] value)
version
- the IP address versionvalue
- the IP address value stored in network byte order
(i.e., the most significant byte first)java.lang.IllegalArgumentException
- if the arguments are invalidprotected IpAddress()
public IpAddress.Version version()
public boolean isIp4()
public boolean isIp6()
public Ip4Address getIp4Address()
Ip4Address
view of the IP address.Ip4Address
view of the IP address if it is IPv4,
otherwise nullpublic Ip6Address getIp6Address()
Ip6Address
view of the IP address.Ip6Address
view of the IP address if it is IPv6,
otherwise nullpublic byte[] toOctets()
public java.net.InetAddress toInetAddress()
public static int byteLength(IpAddress.Version version)
version
- the IP versionjava.lang.IllegalArgumentException
- if the IP version is invalidpublic static IpAddress valueOf(int value)
value
- an integer representing an IPv4 address valuepublic static IpAddress valueOf(IpAddress.Version version, byte[] value)
version
- the IP address versionvalue
- the IP address value stored in network byte order
(i.e., the most significant byte first)java.lang.IllegalArgumentException
- if the arguments are invalidpublic static IpAddress valueOf(IpAddress.Version version, byte[] value, int offset)
The IP address is stored in network byte order (i.e., the most significant byte first).
version
- the IP address versionvalue
- the value to useoffset
- the offset in bytes from the beginning of the byte arrayjava.lang.IllegalArgumentException
- if the arguments are invalidpublic static IpAddress valueOf(java.net.InetAddress inetAddress)
inetAddress
- the InetAddress value to usejava.lang.IllegalArgumentException
- if the argument is invalidpublic static IpAddress valueOf(java.lang.String value)
value
- an IP address value in string formjava.lang.IllegalArgumentException
- if the argument is invalidpublic static IpAddress makeMaskPrefix(IpAddress.Version version, int prefixLength)
version
- the IP address versionprefixLength
- the length of the mask prefix. Must be in the
interval [0, 32] for IPv4, or [0, 128] for IPv6java.lang.IllegalArgumentException
- if the arguments are invalidpublic static IpAddress makeMaskedAddress(IpAddress address, int prefixLength)
address
- the address to maskprefixLength
- the length of the mask prefix. Must be in the
interval [0, 32] for IPv4, or [0, 128] for IPv6java.lang.IllegalArgumentException
- if the prefix length is invalidpublic boolean isZero()
public boolean isSelfAssigned()
public boolean isMulticast()
public boolean isLinkLocal()
public int compareTo(IpAddress o)
compareTo
in interface java.lang.Comparable<IpAddress>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public IpPrefix toIpPrefix()