Package uk.ipfreely
Class Family<A extends Address<A>>
java.lang.Object
uk.ipfreely.Family<A>
-
Method Summary
Modifier and TypeMethodDescriptionmax()
Maximum IP value.min()
Zero.abstract A
parse
(byte... address) Argument must bebitWidth() / 8
bytes in length.abstract A
parse
(int unsigned) Convenience method for creatingAddress
from number.abstract A
parse
(long high, long low) IP address instantiation from primitives.abstract A
parse
(CharSequence candidate) Parses an IP address string.abstract A
parse
(BigInteger address) Enables the conversion fromBigInteger
to theAddress
type.abstract String
regex()
Regular expression for detecting IP addresses in this family.subnets()
Subnet utilities.abstract String
toString()
Informational.type()
IP address type.static Address
<?> unknown
(byte... address) Uses array length to detect IP address family and callsparse(byte...)
.static Address
<?> unknown
(CharSequence candidate) Uses heuristics to detect IP address family and callsparse(CharSequence)
.v4()
IPv4.v6()
IPv6.abstract int
width()
Width of the IP address type in bits.
-
Method Details
-
v4
IPv4.// EXAMPLE V4 localhost = Family.v4().parse("127.0.0.1");
- Returns:
- IPv4 family of addresses
-
v6
IPv6.- Returns:
- IPv6 family of addresses
-
toString
Informational. -
parse
IP address instantiation from primitives.
Only values up to
(0L, 0xffffffffL)
are valid for IPv4.All values are valid for IPv6.
- Parameters:
high
- high bits of the IP addresslow
- low bits of the IP address- Returns:
- the address
- Throws:
ParseException
- on invalid values
-
parse
Parses an IP address string. TODO: supported string forms.- Parameters:
candidate
- valid IP address in this family- Returns:
- parsed address
- Throws:
ParseException
- on invalid address
-
parse
Argument must bebitWidth() / 8
bytes in length.- Parameters:
address
- the address as bytes- Returns:
- parsed address
- Throws:
ParseException
- if the array is not the expected length
-
parse
Enables the conversion fromBigInteger
to theAddress
type. The largest acceptable value ismax().toBigInteger()
.- Parameters:
address
- must be between zero and the maximum value inclusive- Returns:
- the new address
- Throws:
ParseException
- when the argument is out of range- See Also:
-
parse
Convenience method for creatingAddress
from number. All values ofint
are valid for this method. Every value in the IPv4 range can be created with this method.- Parameters:
unsigned
- integer treated as unsigned value- Returns:
- IP address
-
width
public abstract int width()Width of the IP address type in bits.- Returns:
- 32 (V4) or 128 (V6)
-
type
IP address type. -
subnets
Subnet utilities.- Returns:
- subnet methods for this family
-
min
Zero.- Returns:
- "0.0.0.0" (V4) or "::" (V6)
-
max
Maximum IP value.- Returns:
- "255.255.255.255" (V4) or "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" (V6)
-
regex
Regular expression for detecting IP addresses in this family.
// EXAMPLE String startOfString = "^"; String endOfString = "$"; String or = "|"; String v4r = Family.v4().regex(); String v6r = Family.v6().regex(); Pattern addressPattern = Pattern.compile(startOfString + v4r + or + v6r + endOfString); for (String candidate : new String[]{"172.0.0.1", "foo", "::1",}) { Matcher m = addressPattern.matcher(candidate); if (m.matches()) { System.out.println(Family.unknown(candidate).family() + "\t" + candidate); } else { System.out.println("none\t" + candidate); } }
- Returns:
- regular expression for matching address patterns
- See Also:
-
unknown
Uses heuristics to detect IP address family and callsparse(CharSequence)
.- Parameters:
candidate
- IP address- Returns:
- instance of
V4
orV6
- Throws:
ParseException
- on invalid address- See Also:
-
unknown
Uses array length to detect IP address family and callsparse(byte...)
.- Parameters:
address
- an IPv4 or IPv6 address in byte form- Returns:
- parsed address
- Throws:
ParseException
- if array is not 4 (V4) or 16 (V6) bytes in length- See Also:
-