Top Inners Fields Constructors Methods
sun.net.util

public Class IPAddressUtil

extends Object
Class Inheritance
Imports
sun.security.action.GetPropertyAction, java.io.UncheckedIOException, java.net.Inet6Address, .InetAddress, .InetSocketAddress, .NetworkInterface, .SocketException, .URL, java.nio.CharBuffer, java.security.AccessController, .PrivilegedExceptionAction, .PrivilegedActionException, java.util.Arrays, .List, java.util.concurrent.ConcurrentHashMap

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final boolean
private static final ConcurrentHashMap<InetAddress, InetAddress>
cache

Mapping from unscoped local Inet(6)Address to the same address including the correct scope-id, determined from NetworkInterface.

private static final long
private static final int
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final int
private static final int
private static final int
private static final int
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final int
private static final char[]
private static final int[]
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String
public static String
public static String
private static String
public static String
private static boolean
checkPrefix(CharBuffer buffer, int radix)

public static String
public static byte[]
public static boolean
private static String
describeChar(char c)

public static int

Returns:

the numeric value represented by the character in the specified radix.
digit
(char
the character to be converted.
ch
,
int
the radix.
radix
)

Returns the numeric value of the character ch in the specified radix.

public static boolean
private static InetAddress
public static IllegalArgumentException

Returns:

an IllegalArgumentException instance
invalidIpAddressLiteral
(String
address literal string to include to the exception message
src
)

Creates IllegalArgumentException with invalid IP address literal message.

public static boolean

Returns:

true if input string is parsable as IPv4 address literal, false otherwise.
isBsdParsableV4
(String
input string
input
)

Try to parse String as IPv4 address literal by following BSD-style formatting rules.

private static boolean
private static boolean
public static boolean

Returns:

a boolean indicating whether src is an IPv4 literal address
isIPv4LiteralAddress
(String
a String representing an IPv4 address in textual format
src
)

private static boolean

Returns:

a boolean indicating if the InetAddress is an IPv4 mapped IPv6 address; or false if address is IPv4 address.
isIPv4MappedAddress
(byte[] addr)

Utility routine to check if the InetAddress is an IPv4 mapped IPv6 address.

public static boolean

Returns:

a boolean indicating whether src is an IPv6 literal address
isIPv6LiteralAddress
(String
a String representing an IPv6 address in textual format
src
)

private static boolean
public static boolean
match(char c, long lowMask, long highMask)

public static int
parseAsciiDigit(char c, int radix)

private static int
parseAsciiHexDigit(char digit)

public static byte[]

Returns:

a byte array representing the IPv4 numeric address if input string is a parsable POSIX formatted IPv4 address literal, null otherwise.
parseBsdLiteralV4
(String
a String representing an IPv4 address in POSIX format
input
)

Parse String as IPv4 address literal by following POSIX-style formatting rules.

private static long

Returns:

CANT_PARSE_IN_RADIX if field can not be parsed in requested radix. TERMINAL_PARSE_ERROR if field can't be parsed and the whole parse process should be terminated. Parsed field value otherwise.
parseV4FieldBsd
(int
digits encoding radix to use for parsing. Valid values: 8, 10, 16.
radix
,
CharBuffer
CharBuffer with position set to the field's fist character
buffer
,
int
parsed field number
fieldNumber
)

Method tries to parse IP address field that starts from current position of the provided character buffer.

public static int
scan(String s, long lowMask, long highMask)

public static int
scan(String s, long lowMask, long highMask, char[] others)

public static byte[]
public static byte[]
public static InetAddress
toScopedAddress(InetAddress address)

Returns a scoped version of the supplied local, link-local ipv6 address if that scope-id can be determined from local NetworkInterfaces.

public static InetSocketAddress
toScopedAddress(InetSocketAddress address)

Same as above for InetSocketAddress

public static byte[]

Returns:

bytes array if string is a valid IPv4 address string
validateNumericFormatV4
(String
input string
src
,
boolean
true - throw IllegalArgumentException when cannot be parsed as IPv4 address string; false - throw IllegalArgumentException only when IPv4 address string is ambiguous.
throwIAE
)

Validates if input string is a valid IPv4 address literal.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLOW_AMBIGUOUS_IPADDRESS_LITERALS_SPback to summary
private static final String ALLOW_AMBIGUOUS_IPADDRESS_LITERALS_SP
ALLOW_AMBIGUOUS_IPADDRESS_LITERALS_SP_VALUEback to summary
private static final boolean ALLOW_AMBIGUOUS_IPADDRESS_LITERALS_SP_VALUE
cacheback to summary
private static final ConcurrentHashMap<InetAddress, InetAddress> cache

Mapping from unscoped local Inet(6)Address to the same address including the correct scope-id, determined from NetworkInterface.

CANT_PARSE_IN_RADIXback to summary
private static final long CANT_PARSE_IN_RADIX
DECIMALback to summary
private static final int DECIMAL
H_AUTH_DELIMSback to summary
private static final long H_AUTH_DELIMS
H_BACKSLASHback to summary
private static final long H_BACKSLASH
H_COLONback to summary
private static final long H_COLON
H_EXCLUDEback to summary
private static final long H_EXCLUDE
H_EXCLUDED_DELIMSback to summary
private static final long H_EXCLUDED_DELIMS
H_FRAGMENTback to summary
private static final long H_FRAGMENT
H_GEN_DELIMSback to summary
private static final long H_GEN_DELIMS
H_IPV6_DELIMSback to summary
private static final long H_IPV6_DELIMS
H_NON_PRINTABLEback to summary
private static final long H_NON_PRINTABLE
H_QUERYback to summary
private static final long H_QUERY
H_SLASHback to summary
private static final long H_SLASH
H_UNWISEback to summary
private static final long H_UNWISE
HEXADECIMALback to summary
private static final int HEXADECIMAL
INADDR16SZback to summary
private static final int INADDR16SZ
INADDR4SZback to summary
private static final int INADDR4SZ
INT16SZback to summary
private static final int INT16SZ
L_AUTH_DELIMSback to summary
private static final long L_AUTH_DELIMS
L_BACKSLASHback to summary
private static final long L_BACKSLASH
L_COLONback to summary
private static final long L_COLON
L_EXCLUDEback to summary
private static final long L_EXCLUDE
L_EXCLUDED_DELIMSback to summary
private static final long L_EXCLUDED_DELIMS
L_FRAGMENTback to summary
private static final long L_FRAGMENT
L_GEN_DELIMSback to summary
private static final long L_GEN_DELIMS
L_IPV6_DELIMSback to summary
private static final long L_IPV6_DELIMS
L_NON_PRINTABLEback to summary
private static final long L_NON_PRINTABLE
L_QUERYback to summary
private static final long L_QUERY
L_SLASHback to summary
private static final long L_SLASH
L_UNWISEback to summary
private static final long L_UNWISE
OCTALback to summary
private static final int OCTAL
OTHERSback to summary
private static final char[] OTHERS
SUPPORTED_RADIXESback to summary
private static final int[] SUPPORTED_RADIXES
TERMINAL_PARSE_ERRORback to summary
private static final long TERMINAL_PARSE_ERROR

Constructor Detail

IPAddressUtilback to summary
public IPAddressUtil()

Method Detail

checkAuthback to summary
public static String checkAuth(String str)
checkAuthorityback to summary
public static String checkAuthority(URL url)
checkExternalFormback to summary
public static String checkExternalForm(URL url)
checkHostback to summary
private static String checkHost(String str)
checkHostStringback to summary
public static String checkHostString(String host)
checkPrefixback to summary
private static boolean checkPrefix(CharBuffer buffer, int radix)
checkUserInfoback to summary
public static String checkUserInfo(String str)
convertFromIPv4MappedAddressback to summary
public static byte[] convertFromIPv4MappedAddress(byte[] addr)
delayURLParsingback to summary
public static boolean delayURLParsing()
describeCharback to summary
private static String describeChar(char c)
digitback to summary
public static int digit(char ch, int radix)

Returns the numeric value of the character ch in the specified radix.

Parameters
ch:char

the character to be converted.

radix:int

the radix.

Returns:int

the numeric value represented by the character in the specified radix.

earlyURLParsingback to summary
public static boolean earlyURLParsing()
findScopedAddressback to summary
private static InetAddress findScopedAddress(InetAddress address)
Annotations
@SuppressWarnings:removal
invalidIpAddressLiteralback to summary
public static IllegalArgumentException invalidIpAddressLiteral(String src)

Creates IllegalArgumentException with invalid IP address literal message.

Parameters
src:String

address literal string to include to the exception message

Returns:IllegalArgumentException

an IllegalArgumentException instance

isBsdParsableV4back to summary
public static boolean isBsdParsableV4(String input)

Try to parse String as IPv4 address literal by following BSD-style formatting rules.

Parameters
input:String

input string

Returns:boolean

true if input string is parsable as IPv4 address literal, false otherwise.

isDecimalFieldStartback to summary
private static boolean isDecimalFieldStart(CharBuffer cb)
isHexFieldStartback to summary
private static boolean isHexFieldStart(CharBuffer cb)
isIPv4LiteralAddressback to summary
public static boolean isIPv4LiteralAddress(String src)
Parameters
src:String

a String representing an IPv4 address in textual format

Returns:boolean

a boolean indicating whether src is an IPv4 literal address

isIPv4MappedAddressback to summary
private static boolean isIPv4MappedAddress(byte[] addr)

Utility routine to check if the InetAddress is an IPv4 mapped IPv6 address.

Returns:boolean

a boolean indicating if the InetAddress is an IPv4 mapped IPv6 address; or false if address is IPv4 address.

isIPv6LiteralAddressback to summary
public static boolean isIPv6LiteralAddress(String src)
Parameters
src:String

a String representing an IPv6 address in textual format

Returns:boolean

a boolean indicating whether src is an IPv6 literal address

isOctalFieldStartback to summary
private static boolean isOctalFieldStart(CharBuffer cb)
matchback to summary
public static boolean match(char c, long lowMask, long highMask)
parseAsciiDigitback to summary
public static int parseAsciiDigit(char c, int radix)
parseAsciiHexDigitback to summary
private static int parseAsciiHexDigit(char digit)
parseBsdLiteralV4back to summary
public static byte[] parseBsdLiteralV4(String input)

Parse String as IPv4 address literal by following POSIX-style formatting rules.

Parameters
input:String

a String representing an IPv4 address in POSIX format

Returns:byte[]

a byte array representing the IPv4 numeric address if input string is a parsable POSIX formatted IPv4 address literal, null otherwise.

parseV4FieldBsdback to summary
private static long parseV4FieldBsd(int radix, CharBuffer buffer, int fieldNumber)

Method tries to parse IP address field that starts from current position of the provided character buffer.

This method supports three "radix" values to decode field values in "HEXADECIMAL (radix=16)", "DECIMAL (radix=10)" and "OCTAL (radix=8)" radixes.

If -1 value is returned the char buffer position is reset to the value it was before it was called.

Method returns -2 if formatting illegal for all supported radix values is observed, and there is no point in checking other radix values. That includes the following cases:

  • Two subsequent dots are observer
  • Number of dots more than 3
  • Field value exceeds max allowed
  • Character is not a valid digit for the requested radix value, given that a field has the radix specific prefix
Parameters
radix:int

digits encoding radix to use for parsing. Valid values: 8, 10, 16.

buffer:CharBuffer

CharBuffer with position set to the field's fist character

fieldNumber:int

parsed field number

Returns:long

CANT_PARSE_IN_RADIX if field can not be parsed in requested radix. TERMINAL_PARSE_ERROR if field can't be parsed and the whole parse process should be terminated. Parsed field value otherwise.

scanback to summary
public static int scan(String s, long lowMask, long highMask)
scanback to summary
public static int scan(String s, long lowMask, long highMask, char[] others)
textToNumericFormatV4back to summary
public static byte[] textToNumericFormatV4(String src)
Annotations
@SuppressWarnings:fallthrough
textToNumericFormatV6back to summary
public static byte[] textToNumericFormatV6(String src)
toScopedAddressback to summary
public static InetAddress toScopedAddress(InetAddress address) throws SocketException

Returns a scoped version of the supplied local, link-local ipv6 address if that scope-id can be determined from local NetworkInterfaces. If the address already has a scope-id or if the address is not local, ipv6 or link local, then the original address is returned.

Exceptions
SocketException:
if the given ipv6 link local address is found on more than one local interface
toScopedAddressback to summary
public static InetSocketAddress toScopedAddress(InetSocketAddress address) throws SocketException

Same as above for InetSocketAddress

validateNumericFormatV4back to summary
public static byte[] validateNumericFormatV4(String src, boolean throwIAE)

Validates if input string is a valid IPv4 address literal. If the "jdk.net.allowAmbiguousIPAddressLiterals" system property is set to false, or is not set then validation of the address string is performed as follows: If string can't be parsed by following IETF IPv4 address string literals formatting style rules (default one), but can be parsed by following BSD formatting style rules, the IPv4 address string content is treated as ambiguous and either IllegalArgumentException is thrown, or null is returned.

Parameters
src:String

input string

throwIAE:boolean

true - throw IllegalArgumentException when cannot be parsed as IPv4 address string; false - throw IllegalArgumentException only when IPv4 address string is ambiguous.

Returns:byte[]

bytes array if string is a valid IPv4 address string

Exceptions
IllegalArgumentException:
if "jdk.net.allowAmbiguousIPAddressLiterals" SP is set to false, IPv4 address string src is ambiguous, or when address string cannot be parsed as an IPv4 address string and throwIAE is set to true.
sun.net.util back to summary

private Class IPAddressUtil.MASKS

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final String
private static final boolean
pack-priv static final long
pack-priv static final long
pack-priv static final long
pack-priv static final long
pack-priv static final long
pack-priv static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DELAY_URL_PARSING_SPback to summary
private static final String DELAY_URL_PARSING_SP
DELAY_URL_PARSING_SP_VALUEback to summary
private static final boolean DELAY_URL_PARSING_SP_VALUE
H_HOSTNAME_MASKback to summary
pack-priv static final long H_HOSTNAME_MASK
H_SCOPE_MASKback to summary
pack-priv static final long H_SCOPE_MASK
H_USERINFO_MASKback to summary
pack-priv static final long H_USERINFO_MASK
L_HOSTNAME_MASKback to summary
pack-priv static final long L_HOSTNAME_MASK
L_SCOPE_MASKback to summary
pack-priv static final long L_SCOPE_MASK
L_USERINFO_MASKback to summary
pack-priv static final long L_USERINFO_MASK

Constructor Detail

MASKSback to summary
private MASKS()