public final class NetUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static int |
IPV4_BYTE_COUNT
Number of bytes needed to represent and IPV4 value
|
private static int |
IPV4_MAX_CHAR_BETWEEN_SEPARATOR
Maximum amount of value adding characters in between IPV4 separators
|
private static int |
IPV4_SEPARATORS
Number of separators that must be present in an IPv4 string
|
private static int |
IPV6_BYTE_COUNT
Number of bytes needed to represent and IPV6 value
|
private static int |
IPV6_MAX_CHAR_BETWEEN_SEPARATOR
Maximum amount of value adding characters in between IPV6 separators
|
private static int |
IPV6_MAX_CHAR_COUNT
The maximum number of characters for an IPV6 string with no scope
|
private static int |
IPV6_MAX_SEPARATORS
Maximum number of separators that must be present in an IPv6 string
|
private static int |
IPV6_MIN_SEPARATORS
Minimum number of separators that must be present in an IPv6 string
|
private static int |
IPV6_WORD_COUNT
This defines how many words (represented as ints) are needed to represent an IPv6 address
|
private static InternalLogger |
logger
The logger being used by this class
|
| Modifier | Constructor and Description |
|---|---|
private |
NetUtil()
A constructor to stop this class being constructed.
|
| Modifier and Type | Method and Description |
|---|---|
private static void |
convertToBytes(java.lang.String hexWord,
byte[] ipByteArray,
int byteIndex)
Converts a 4 character hex word into a 2 byte word equivalent
|
static byte[] |
createByteArrayFromIpAddressString(java.lang.String ipAddressString)
Creates an byte[] based on an ipAddressString.
|
static java.net.Inet6Address |
getByName(java.lang.CharSequence ip)
Returns the
Inet6Address representation of a CharSequence IP address. |
static java.net.Inet6Address |
getByName(java.lang.CharSequence ip,
boolean ipv4Mapped)
Returns the
Inet6Address representation of a CharSequence IP address. |
(package private) static int |
getIntValue(char c) |
private static boolean |
inRangeEndExclusive(int value,
int start,
int end)
Does a range check on
value if is within start (inclusive) and end (exclusive). |
private static boolean |
isValidHexChar(char c) |
static boolean |
isValidIp4Word(java.lang.String word) |
static boolean |
isValidIpV4Address(java.lang.String value)
Takes a string and parses it to see if it is a valid IPV4 address.
|
static boolean |
isValidIpV6Address(java.lang.String ipAddress) |
private static boolean |
isValidNumericChar(char c) |
static java.lang.String |
toAddressString(java.net.InetAddress ip)
Returns the
String representation of an InetAddress. |
static java.lang.String |
toAddressString(java.net.InetAddress ip,
boolean ipv4Mapped)
Returns the
String representation of an InetAddress. |
private static final int IPV6_WORD_COUNT
private static final int IPV6_MAX_CHAR_COUNT
private static final int IPV6_BYTE_COUNT
private static final int IPV6_MAX_CHAR_BETWEEN_SEPARATOR
private static final int IPV6_MIN_SEPARATORS
private static final int IPV6_MAX_SEPARATORS
private static final int IPV4_BYTE_COUNT
private static final int IPV4_MAX_CHAR_BETWEEN_SEPARATOR
private static final int IPV4_SEPARATORS
private static final InternalLogger logger
public static byte[] createByteArrayFromIpAddressString(java.lang.String ipAddressString)
private static void convertToBytes(java.lang.String hexWord,
byte[] ipByteArray,
int byteIndex)
static int getIntValue(char c)
public static boolean isValidIpV6Address(java.lang.String ipAddress)
public static boolean isValidIp4Word(java.lang.String word)
private static boolean isValidHexChar(char c)
private static boolean isValidNumericChar(char c)
public static boolean isValidIpV4Address(java.lang.String value)
public static java.net.Inet6Address getByName(java.lang.CharSequence ip)
Inet6Address representation of a CharSequence IP address.
This method will treat all IPv4 type addresses as "IPv4 mapped" (see getByName(CharSequence, boolean))
ip - CharSequence IP address to be converted to a Inet6AddressInet6Address representation of the ip or null if not a valid IP address.public static java.net.Inet6Address getByName(java.lang.CharSequence ip,
boolean ipv4Mapped)
Inet6Address representation of a CharSequence IP address.
The ipv4Mapped parameter specifies how IPv4 addresses should be treated.
"IPv4 mapped" format as
defined in rfc 4291 section 2 is supported.
ip - CharSequence IP address to be converted to a Inet6Addressipv4Mapped - true To allow IPv4 mapped inputs to be translated into Inet6Addressfalse Don't turn IPv4 addressed to mapped addressesInet6Address representation of the ip or null if not a valid IP address.public static java.lang.String toAddressString(java.net.InetAddress ip)
String representation of an InetAddress.
InetAddress.getHostAddress()The output does not include Scope ID.
ip - InetAddress to be converted to an address stringString containing the text-formatted IP addresspublic static java.lang.String toAddressString(java.net.InetAddress ip,
boolean ipv4Mapped)
String representation of an InetAddress.
InetAddress.getHostAddress()ipv4Mapped is false. If ipv4Mapped is true then "IPv4 mapped" format
from rfc 4291 section 2 will be supported.
The compressed result will always obey the compression rules defined in
rfc 5952 section 4The output does not include Scope ID.
ip - InetAddress to be converted to an address stringipv4Mapped - true to stray from strict rfc 5952 and support the "IPv4 mapped" format
defined in rfc 4291 section 2 while still
following the updated guidelines in
rfc 5952 section 4false to strictly follow rfc 5952String containing the text-formatted IP addressprivate static boolean inRangeEndExclusive(int value,
int start,
int end)
value if is within start (inclusive) and end (exclusive).value - The value to checked if is within start (inclusive) and end (exclusive)start - The start of the range (inclusive)end - The end of the range (exclusive)true if value if is within start (inclusive) and end (exclusive)false otherwise