public class Inet4AddressMatcher extends java.lang.Object implements AddressMatcher
Matcher
, i.e. you create a new Inet4AddressMatcher
with the IP address pattern and can then match IP addresses to it. The
Inet4AddressMatcher can match the following kinds of IP addresses or address
ranges:
192.168.1.2
)192.168.1.2/255.255.255.0
)192.168.1.2/24
)Constructor and Description |
---|
Inet4AddressMatcher(java.lang.String cidrHostname)
Creates a new address matcher that matches InetAddress objects to the
address specification given by
cidrHostname . |
Modifier and Type | Method and Description |
---|---|
static int |
convertToBytes(java.lang.String address)
Converts a dotted IP address (a.b.c.d) to a 32-bit value.
|
java.lang.String |
getHumanRepresentation()
Get the human-readable version of the Matcher
|
boolean |
matches(java.net.InetAddress inetAddress)
Checks whether the given address matches this matcher's address.
|
static boolean |
matches(java.lang.String cidrHostname,
java.net.InetAddress address)
Shortcut method for creating a new Inet4AddressMatcher and matching
address to it. |
public Inet4AddressMatcher(java.lang.String cidrHostname)
cidrHostname
.cidrHostname
- The address range this matcher matchespublic static int convertToBytes(java.lang.String address)
address
- The address to convertjava.lang.NumberFormatException
- if a part of the string can not be parsed using
Integer.parseInt(java.lang.String)
java.util.NoSuchElementException
- if address
contains less than 3 dotspublic boolean matches(java.net.InetAddress inetAddress)
matches
in interface AddressMatcher
inetAddress
- The address to match to this matchertrue
if inetAddress
matches the
specification of this matcher, false
otherwisepublic static boolean matches(java.lang.String cidrHostname, java.net.InetAddress address)
address
to it.cidrHostname
- The host specification to matchaddress
- The address to matchtrue
if address
matches the
specification in cidrHostname
, false
otherwiseInet4AddressMatcher(String)
,
matches(InetAddress)
public java.lang.String getHumanRepresentation()
AddressMatcher
getHumanRepresentation
in interface AddressMatcher