|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.net.tcp.InetAddressFilters
public final class InetAddressFilters
Collection of standard IP address filters.
This class provides many of the standard IP filters one is likely to need. You can filter to a specific host or particular network and do boolean OR, NOT and AND operations on sets of filters.
The fromString method is particularily handy as it can be
used to dynamically load a set of OR conditions from a single string (handy
when working with Java property files).
To see this in action, take a look at the Filter.java example.
InetAddressFilter,
Filter.java| Method Summary | |
|---|---|
static InetAddressFilter |
acceptExactMatch(InetAddress addr)
Get a IP filter which only "accepts" an IP address that matches a particular InetAddress exactly. |
static InetAddressFilter |
acceptLocalHost()
Get a IP filter which only "accepts" an IP address that is the local host (127.0.0.1). |
static InetAddressFilter |
acceptMaskAndMatch(InetAddress match,
InetAddress mask)
Get a IP filter which only "accepts" an IP address that matches a particular InetAddress exactly. |
static InetAddressFilter |
acceptThisHost()
Get a IP filter which only "accepts" IP addresses that corresponds to this host. |
static InetAddressFilter |
and(InetAddressFilter a,
InetAddressFilter b)
A boolean AND of two different filters. |
static InetAddressFilter |
fromString(String s)
A method to build a IP address filter from the contents of a string. |
static InetAddressFilter |
not(InetAddressFilter a)
A boolean NOT of a particular filter. |
static InetAddressFilter |
or(InetAddressFilter a,
InetAddressFilter b)
A boolean OR of two different filters. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static InetAddressFilter acceptLocalHost()
InetAddressFilter which only accepts local host.
public static InetAddressFilter acceptThisHost()
throws UnknownHostException
The filter returned by this method accepts any IP address that is
associated with the local machine (the machine that the JVM is running
on). This includes: 127.0.0.1 and ALL of the host names returned by
InetAddress.getAllByName(java.lang.String).
InetAddressFilter which accepts all IP addresses that the host
running the JVM is known as.
UnknownHostExceptionpublic static InetAddressFilter acceptExactMatch(InetAddress addr)
InetAddress exactly.
ip - The InetAddress to match - must not be null.
InetAddressFilter which only accepts a exact match.
public static InetAddressFilter acceptMaskAndMatch(InetAddress match,
InetAddress mask)
InetAddress exactly.
This method allows one to create filters for networks. For example, if the 'match' parameter were 192.168.0.0, and the 'mask' parameter was '255.255.0.0', then ALL IP addresses from 192.168.0.0 to 192.168.255.255 (inclusive) would be accepted.
match - The InetAddress to match - must not be null.mask - The InetAddress to mask any address to check PRIOR to
comparing it to the "match" address.
InetAddressFilter which does the mask/accept filtering.
public static InetAddressFilter or(InetAddressFilter a,
InetAddressFilter b)
filters.
This method allows one to combine two filters in a boolean OR. That is, it's accept method will return true if EITHER of the two filters passed returns true.
a - The first filter to check - may be null, in which case 'b' is returned.b - The second filter to check - may be null, in which case 'a' is returned.
InetAddressFilter which to test IP addresses with, or null if
BOTH 'a' and 'b' are null.
public static InetAddressFilter and(InetAddressFilter a,
InetAddressFilter b)
filters.
This method allows one to combine two filters in a boolean AND. That is,
it's accept method will return true if BOTH of the two filters passed
returns true. This is rarely used in a positive sense, but can be
combined with the NOT operation to prevent certain hosts.
a - The first filter to check - may be null, in which case 'b' is returned.b - The second filter to check - may be null, in which case 'a' is returned.
InetAddressFilter which to test IP addresses with, or null if
BOTH 'a' and 'b' are null.public static InetAddressFilter not(InetAddressFilter a)
filter.
This method allows one to inverse the results of another filter. That is, it's accept method will return true if the filter passed to it returns false.
a - The filter to invert (do the NOT operation on).
InetAddressFilter which to test IP addresses with, or null if
'a' was null.
public static InetAddressFilter fromString(String s)
throws UnknownHostException
This method takes a string of the following form:
MATCH0[/MASK0,MATCH1[/MASK1[,...]]]
For example, the following would accept a IP address if it matched the IP address of "mole.linux.bogus" or if it match the localhost "127.0.0.1", or if it was in the range 192.168.137.0 to 192.168.137.255:
mole.linux.bogus,127.0.0.1,192.168.137.0/255.255.255.0
This can be really handy when you want to allow someone to configure IP filters in property files.
s - The string to parse for the filter list - must not be null.
InetAddressFilter which is a boolean OR of the comma separated
host (and optional mask values).
UnknownHostException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||