Top Description Fields Constructors Methods
io.smallrye.common.net

public final Class Inet

extends Object
Class Inheritance
Annotations
@SuppressWarnings:removal
Imports
java.lang.reflect.Array, java.net.Inet4Address, .Inet6Address, .InetAddress, .InetSocketAddress, .NetworkInterface, .ProtocolFamily, .SocketException, .StandardProtocolFamily, .URI, .URISyntaxException, .UnknownHostException, java.nio.ByteBuffer, java.security.AccessController, .PrivilegedAction, java.util.Enumeration, java.util.regex.Pattern, io.smallrye.common.constraint.Assert

Utilities relating to Internet protocol (a.k.a. "INET" or "IP") address manipulation.

Field Summary

Modifier and TypeField and Description
public static final Inet4Address
INET4_ANY

The "any" address for IPv4.

public static final Inet4Address
INET4_BROADCAST

The broadcast-all address for IPv4.

public static final Inet4Address
INET4_LOOPBACK

The traditional loopback address for IPv4.

public static final Inet6Address
INET6_ANY

The "any" address for IPv6.

public static final Inet6Address
INET6_LOOPBACK

The loopback address for IPv6.

private static final Pattern

Constructor Summary

AccessConstructor and Description
private
Inet()

Method Summary

Modifier and TypeMethod and Description
private static void
encodeUnsignedByte(int value, byte[] bytes, int offset, int digits)

public static NetworkInterface

Returns:

the interface whose scope name matches the given name
findInterfaceWithScopeId
(String
the scope name
scopeName
)

Returns the interface whose scope name matches the given name.

public static <
the type of the InetAddress to search for
T extends InetAddress
>
T

Returns:

the resolved address (not null)
getAddressByNameAndType
(String
the host name to resolve (must not be null)
hostName
,
Class<T>
the class of the InetAddress to search for (must not be null)
addressType
)

Resolve the given host name, returning the first answer with the given address type.

public static <
the type of the InetAddress to search for
T extends InetAddress
>
T[]

Returns:

the resolved addresses (not null)
getAllAddressesByNameAndType
(String
the host name to resolve (must not be null)
hostName
,
Class<T>
the class of the InetAddress to search for (must not be null)
addressType
)

Resolve the given host name, returning all answers with the given address type.

public static String

Returns:

the host name, or null if the address has no host name and is unresolved
getHostNameIfResolved
(InetAddress
the address to check (must not be null)
inetAddress
)

Get the host name of the given address, if it is resolved.

public static String

Returns:

the host name, or null if the address has no host name and is unresolved
getHostNameIfResolved
(InetSocketAddress
the socket address to check (must not be null)
socketAddress
)

Get the host name of the given address, if it is resolved.

public static Inet4Address

Returns:

the address (not null)
getInet4Address
(String
the host name (must not be null)
hostName
,
int
the first segment
s1
,
int
the second segment
s2
,
int
the third segment
s3
,
int
the fourth segment
s4
)

Get an IPv4 address from four integer segments and a host name.

public static Inet4Address

Returns:

the address (not null)
getInet4Address
(int
the first segment
s1
,
int
the second segment
s2
,
int
the third segment
s3
,
int
the fourth segment
s4
)

Get an IPv4 address from four integer segments.

private static byte[]
getInet4AddressBytes(final int s1, final int s2, final int s3, final int s4)

public static Inet6Address

Returns:

the address (not null)
getInet6Address
(int
the first segment
s1
,
int
the second segment
s2
,
int
the third segment
s3
,
int
the fourth segment
s4
,
int
the fifth segment
s5
,
int
the sixth segment
s6
,
int
the seventh segment
s7
,
int
the eighth segment
s8
)

Get an IPv6 address from eight integer segments.

public static Inet6Address

Returns:

the address (not null)
getInet6Address
(String
the host name (must not be null)
hostName
,
int
the first segment
s1
,
int
the second segment
s2
,
int
the third segment
s3
,
int
the fourth segment
s4
,
int
the fifth segment
s5
,
int
the sixth segment
s6
,
int
the seventh segment
s7
,
int
the eighth segment
s8
)

Get an IPv6 address from eight integer segments and a host name.

private static byte[]
getInet6AddressBytes(final int s1, final int s2, final int s3, final int s4, final int s5, final int s6, final int s7, final int s8)

public static ProtocolFamily

Returns:

the protocol family (not null)
getProtocolFamily
(InetAddress
the address (must not be null)
inetAddress
)

Get the protocol family of the given Internet address.

public static InetSocketAddress

Returns:

the socket address, or null if the URI does not have a host component
getResolved
(URI
the URI (must not be null)
uri
,
int
the default port to use if none is given (must be in the range 1 ≤ n ≤ 65535
defaultPort
,
Class<? extends InetAddress>
the class of the InetAddress to search for (must not be null)
addressType
)

Get a resolved socket address from the given URI.

public static InetSocketAddress

Returns:

the socket address, or null if the URI does not have a host component
getResolved
(URI
the URI (must not be null)
uri
,
int
the default port to use if none is given (must be in the range 1 ≤ n ≤ 65535
defaultPort
)

Get the resolved socket address from the given URI.

public static InetSocketAddress

Returns:

the resolved address (not null)
getResolved
(InetSocketAddress
the (possibly unresolved) address (must not be null)
address
)

Get a copy of the given socket address, but with a resolved address component.

public static InetSocketAddress

Returns:

the resolved address (not null)
getResolved
(InetSocketAddress
the (possibly unresolved) address (must not be null)
address
,
Class<? extends InetAddress>
the class of the InetAddress to search for (must not be null)
addressType
)

Get a copy of the given socket address, but with a resolved address component of the given type.

public static <
the type of the InetAddress to search for
T extends InetAddress
>
T

Returns:

the address, or null if no authority is present in the URI
getResolvedInetAddress
(URI
the destination URI
uri
,
Class<T>
the class of the InetAddress to search for (must not be null)
addressType
)

Get an Internet address for a URI destination, resolving the host name if necessary.

public static InetAddress

Returns:

the address, or null if no authority is present in the URI
getResolvedInetAddress
(URI
the destination URI
uri
)

Get an Internet address for a URI destination, resolving the host name if necessary.

public static int

Returns:

the scope ID, or 0 if there is none or the address is an IPv4 address
getScopeId
(InetAddress
the address
address
)

Get the scope ID of the given address (if it is an IPv6 address).

public static int

Returns:

the scope ID, or 0 if no matching scope could be found
getScopeId
(String
the scope number or name as a string (must not be null)
scopeName
)

Attempt to get the scope ID of the given string.

public static int

Returns:

the scope ID, or 0 if no matching scope could be found
getScopeId
(String
the scope number or name as a string (must not be null)
scopeName
,
InetAddress
the address to compare with, to ensure that the wrong local scope is not selected (may be null)
compareWith
)

Attempt to get the scope ID of the given string.

public static int

Returns:

the scope ID of the given interface
getScopeId
(NetworkInterface
the interface (must not be null)
networkInterface
)

Returns the scope ID of the given interface.

public static int

Returns:

the scope ID of the given interface which has the same link-local and site-local attribute as the given address
getScopeId
(NetworkInterface
the interface (must not be null)
networkInterface
,
InetAddress
the address to compare with
compareWith
)

Returns the scope ID of the given interface which has the same link-local and site-local attribute as the given address.

public static URI

Returns:

the URI instance
getURIFromAddress
(String
the URI scheme
scheme
,
InetSocketAddress
the host socket address
socketAddress
,
int
the protocol default port, or -1 if there is none
defaultPort
)

Extract a base URI from the given scheme and socket address.

public static boolean

Returns:

true if address is a valid IPv4 address, false otherwise
isInet4Address
(String
address textual representation
address
)

Checks whether given String is a valid IPv4 address.

public static boolean

Returns:

true if address is a valid IPv6 address, false otherwise
isInet6Address
(String
address textual representation
address
)

Checks whether given String is a valid IPv6 address.

public static CidrAddress

Returns:

the parsed address, or null if the address is not valid
parseCidrAddress
(String
the address to parse
address
)

Parse a CIDR address into a CidrAddress object.

private static byte
private static short
public static Inet4Address

Returns:

the parsed address, or null if the address is not valid
parseInet4Address
(String
the address to parse
address
)

Parse an IPv4 address into an Inet4Address object.

public static Inet4Address

Returns:

the parsed address, or null if the address is not valid
parseInet4Address
(String
the address to parse
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IPv4 address into an Inet4Address object.

public static Inet4Address

Returns:

the parsed address (not null)
parseInet4AddressOrFail
(String
the address to parse
address
)

Parse an IPv4 address into an Inet4Address object, throwing an exception on failure.

public static Inet4Address

Returns:

the parsed address (not null)
parseInet4AddressOrFail
(String
the address to parse (must not be null)
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IPv4 address into an Inet4Address object.

public static byte[]

Returns:

byte array representing the address, or null if the address is not valid
parseInet4AddressToBytes
(String
address textual representation
address
)

Converts IPv4 address from textual representation to bytes.

public static Inet6Address

Returns:

the parsed address, or null if the address is not valid
parseInet6Address
(String
the address to parse
address
)

Parse an IPv6 address into an Inet6Address object.

public static Inet6Address

Returns:

the parsed address, or null if the address is not valid
parseInet6Address
(String
the address to parse (must not be null)
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IPv6 address into an Inet6Address object.

public static Inet6Address

Returns:

the parsed address (not null)
parseInet6AddressOrFail
(String
the address to parse
address
)

Parse an IPv6 address into an Inet6Address object, throwing an exception on failure.

public static Inet6Address

Returns:

the parsed address (not null)
parseInet6AddressOrFail
(String
the address to parse (must not be null)
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IPv6 address into an Inet6Address object.

public static byte[]

Returns:

byte array representing the address, or null if the address is not valid
parseInet6AddressToBytes
(String
address textual representation
address
)

Converts IPv6 address from textual representation to bytes.

public static InetAddress

Returns:

the parsed address, or null if the address is not valid
parseInetAddress
(String
the address to parse
address
)

Parse an IP address into an InetAddress object.

public static InetAddress

Returns:

the parsed address, or null if the address is not valid
parseInetAddress
(String
the address to parse
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IP address into an InetAddress object.

public static InetAddress

Returns:

the parsed address (not null)
parseInetAddressOrFail
(String
the address to parse
address
)

Parse an IP address into an InetAddress object, throwing an exception on failure.

public static InetAddress

Returns:

the parsed address (not null)
parseInetAddressOrFail
(String
the address to parse (must not be null)
address
,
String
the host name to use in the resultant object, or null to use the string representation of the address
hostName
)

Parse an IP address into an InetAddress object.

public static byte[]

Returns:

byte array representing the address, or null if the address is not valid
parseInetAddressToBytes
(String
address textual representation
address
)

Converts an IP address from textual representation to bytes.

public static Inet6Address

Returns:

the converted address (not null)
toInet6Address
(InetAddress
the address to convert (must not be null)
inetAddress
)

Get the IPv6 equivalent of the given address.

public static String

Returns:

the string representation (not null)
toOptimalString
(InetAddress
the address (must not be null)
inetAddress
)

Get the optimal string representation of an IP address.

public static String

Returns:

the string representation (not null)
toOptimalString
(byte[]
the address bytes (must not be null)
addressBytes
)

Get the optimal string representation of the bytes of an IP address.

private static String
toOptimalStringV6(final byte[] bytes)

public static String

Returns:

the string representation (not null)
toURLString
(InetAddress
the address (must not be null)
inetAddress
,
boolean
true to preserve the host name string in the address, false to always give an IP address string
useHostNameIfPresent
)

Get a string representation of the given address which is suitable for use as the host component of a URL.

public static String

Returns:

the string representation (not null)
toURLString
(byte[]
the address bytes (must not be null)
addressBytes
)

Get a string representation of the given address bytes which is suitable for use as the host component of a URL.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INET4_ANYback to summary
public static final Inet4Address INET4_ANY

The "any" address for IPv4.

INET4_BROADCASTback to summary
public static final Inet4Address INET4_BROADCAST

The broadcast-all address for IPv4.

INET4_LOOPBACKback to summary
public static final Inet4Address INET4_LOOPBACK

The traditional loopback address for IPv4.

INET6_ANYback to summary
public static final Inet6Address INET6_ANY

The "any" address for IPv6.

INET6_LOOPBACKback to summary
public static final Inet6Address INET6_LOOPBACK

The loopback address for IPv6.

NUMERICback to summary
private static final Pattern NUMERIC

Constructor Detail

Inetback to summary
private Inet()

Method Detail

encodeUnsignedByteback to summary
private static void encodeUnsignedByte(int value, byte[] bytes, int offset, int digits)
findInterfaceWithScopeIdback to summary
public static NetworkInterface findInterfaceWithScopeId(String scopeName)

Returns the interface whose scope name matches the given name.

Parameters
scopeName:String

the scope name

Returns:NetworkInterface

the interface whose scope name matches the given name

getAddressByNameAndTypeback to summary
public static <T extends InetAddress> T getAddressByNameAndType(String hostName, Class<T> addressType) throws UnknownHostException

Resolve the given host name, returning the first answer with the given address type.

Parameters
<T>
the type of the InetAddress to search for
hostName:String

the host name to resolve (must not be null)

addressType:Class<T>

the class of the InetAddress to search for (must not be null)

Returns:T

the resolved address (not null)

Exceptions
UnknownHostException:
if address resolution failed or if no addresses of the given type were found
getAllAddressesByNameAndTypeback to summary
public static <T extends InetAddress> T[] getAllAddressesByNameAndType(String hostName, Class<T> addressType) throws UnknownHostException

Resolve the given host name, returning all answers with the given address type.

Parameters
<T>
the type of the InetAddress to search for
hostName:String

the host name to resolve (must not be null)

addressType:Class<T>

the class of the InetAddress to search for (must not be null)

Returns:T[]

the resolved addresses (not null)

Annotations
@SuppressWarnings:unchecked
Exceptions
UnknownHostException:
if address resolution failed or if no addresses of the given type were found
getHostNameIfResolvedback to summary
public static String getHostNameIfResolved(InetAddress inetAddress)

Get the host name of the given address, if it is resolved. Otherwise, return null.

Parameters
inetAddress:InetAddress

the address to check (must not be null)

Returns:String

the host name, or null if the address has no host name and is unresolved

getHostNameIfResolvedback to summary
public static String getHostNameIfResolved(InetSocketAddress socketAddress)

Get the host name of the given address, if it is resolved. Otherwise, return null.

Parameters
socketAddress:InetSocketAddress

the socket address to check (must not be null)

Returns:String

the host name, or null if the address has no host name and is unresolved

getInet4Addressback to summary
public static Inet4Address getInet4Address(String hostName, int s1, int s2, int s3, int s4)

Get an IPv4 address from four integer segments and a host name. Each segment must be between 0 and 255.

Parameters
hostName:String

the host name (must not be null)

s1:int

the first segment

s2:int

the second segment

s3:int

the third segment

s4:int

the fourth segment

Returns:Inet4Address

the address (not null)

getInet4Addressback to summary
public static Inet4Address getInet4Address(int s1, int s2, int s3, int s4)

Get an IPv4 address from four integer segments. Each segment must be between 0 and 255.

Parameters
s1:int

the first segment

s2:int

the second segment

s3:int

the third segment

s4:int

the fourth segment

Returns:Inet4Address

the address (not null)

getInet4AddressBytesback to summary
private static byte[] getInet4AddressBytes(final int s1, final int s2, final int s3, final int s4)
getInet6Addressback to summary
public static Inet6Address getInet6Address(int s1, int s2, int s3, int s4, int s5, int s6, int s7, int s8)

Get an IPv6 address from eight integer segments. Each segment must be between 0 and 65535 (0xffff).

Parameters
s1:int

the first segment

s2:int

the second segment

s3:int

the third segment

s4:int

the fourth segment

s5:int

the fifth segment

s6:int

the sixth segment

s7:int

the seventh segment

s8:int

the eighth segment

Returns:Inet6Address

the address (not null)

getInet6Addressback to summary
public static Inet6Address getInet6Address(String hostName, int s1, int s2, int s3, int s4, int s5, int s6, int s7, int s8)

Get an IPv6 address from eight integer segments and a host name. Each segment must be between 0 and 65535 (0xffff).

Parameters
hostName:String

the host name (must not be null)

s1:int

the first segment

s2:int

the second segment

s3:int

the third segment

s4:int

the fourth segment

s5:int

the fifth segment

s6:int

the sixth segment

s7:int

the seventh segment

s8:int

the eighth segment

Returns:Inet6Address

the address (not null)

getInet6AddressBytesback to summary
private static byte[] getInet6AddressBytes(final int s1, final int s2, final int s3, final int s4, final int s5, final int s6, final int s7, final int s8)
getProtocolFamilyback to summary
public static ProtocolFamily getProtocolFamily(InetAddress inetAddress)

Get the protocol family of the given Internet address.

Parameters
inetAddress:InetAddress

the address (must not be null)

Returns:ProtocolFamily

the protocol family (not null)

getResolvedback to summary
public static InetSocketAddress getResolved(URI uri, int defaultPort, Class<? extends InetAddress> addressType) throws UnknownHostException

Get a resolved socket address from the given URI.

Parameters
uri:URI

the URI (must not be null)

defaultPort:int

the default port to use if none is given (must be in the range 1 ≤ n ≤ 65535

addressType:Class<? extends InetAddress>

the class of the InetAddress to search for (must not be null)

Returns:InetSocketAddress

the socket address, or null if the URI does not have a host component

Exceptions
UnknownHostException:
if address resolution failed
getResolvedback to summary
public static InetSocketAddress getResolved(URI uri, int defaultPort) throws UnknownHostException

Get the resolved socket address from the given URI.

Parameters
uri:URI

the URI (must not be null)

defaultPort:int

the default port to use if none is given (must be in the range 1 ≤ n ≤ 65535

Returns:InetSocketAddress

the socket address, or null if the URI does not have a host component

Exceptions
UnknownHostException:
if address resolution failed
getResolvedback to summary
public static InetSocketAddress getResolved(InetSocketAddress address) throws UnknownHostException

Get a copy of the given socket address, but with a resolved address component.

Parameters
address:InetSocketAddress

the (possibly unresolved) address (must not be null)

Returns:InetSocketAddress

the resolved address (not null)

Exceptions
UnknownHostException:
if address resolution failed
getResolvedback to summary
public static InetSocketAddress getResolved(InetSocketAddress address, Class<? extends InetAddress> addressType) throws UnknownHostException

Get a copy of the given socket address, but with a resolved address component of the given type.

Parameters
address:InetSocketAddress

the (possibly unresolved) address (must not be null)

addressType:Class<? extends InetAddress>

the class of the InetAddress to search for (must not be null)

Returns:InetSocketAddress

the resolved address (not null)

Exceptions
UnknownHostException:
if address resolution failed, or if no addresses of the given type were found, or if the given address was already resolved but is not of the given address type
getResolvedInetAddressback to summary
public static <T extends InetAddress> T getResolvedInetAddress(URI uri, Class<T> addressType) throws UnknownHostException

Get an Internet address for a URI destination, resolving the host name if necessary.

Parameters
<T>
the type of the InetAddress to search for
uri:URI

the destination URI

addressType:Class<T>

the class of the InetAddress to search for (must not be null)

Returns:T

the address, or null if no authority is present in the URI

Exceptions
UnknownHostException:
if the URI host was existent but could not be resolved to a valid address
getResolvedInetAddressback to summary
public static InetAddress getResolvedInetAddress(URI uri) throws UnknownHostException

Get an Internet address for a URI destination, resolving the host name if necessary.

Parameters
uri:URI

the destination URI

Returns:InetAddress

the address, or null if no authority is present in the URI

Exceptions
UnknownHostException:
if the URI host was existent but could not be resolved to a valid address
getScopeIdback to summary
public static int getScopeId(InetAddress address)

Get the scope ID of the given address (if it is an IPv6 address).

Parameters
address:InetAddress

the address

Returns:int

the scope ID, or 0 if there is none or the address is an IPv4 address

getScopeIdback to summary
public static int getScopeId(String scopeName)

Attempt to get the scope ID of the given string. If the string is numeric then the number is parsed and returned as-is. If the scope is a string, then a search for the matching network interface will occur.

Parameters
scopeName:String

the scope number or name as a string (must not be null)

Returns:int

the scope ID, or 0 if no matching scope could be found

getScopeIdback to summary
public static int getScopeId(String scopeName, InetAddress compareWith)

Attempt to get the scope ID of the given string. If the string is numeric then the number is parsed and returned as-is. If the scope is a string, then a search for the matching network interface will occur.

Parameters
scopeName:String

the scope number or name as a string (must not be null)

compareWith:InetAddress

the address to compare with, to ensure that the wrong local scope is not selected (may be null)

Returns:int

the scope ID, or 0 if no matching scope could be found

getScopeIdback to summary
public static int getScopeId(NetworkInterface networkInterface)

Returns the scope ID of the given interface.

Parameters
networkInterface:NetworkInterface

the interface (must not be null)

Returns:int

the scope ID of the given interface

getScopeIdback to summary
public static int getScopeId(NetworkInterface networkInterface, InetAddress compareWith)

Returns the scope ID of the given interface which has the same link-local and site-local attribute as the given address.

Parameters
networkInterface:NetworkInterface

the interface (must not be null)

compareWith:InetAddress

the address to compare with

Returns:int

the scope ID of the given interface which has the same link-local and site-local attribute as the given address

getURIFromAddressback to summary
public static URI getURIFromAddress(String scheme, InetSocketAddress socketAddress, int defaultPort) throws URISyntaxException

Extract a base URI from the given scheme and socket address. The address is not resolved.

Parameters
scheme:String

the URI scheme

socketAddress:InetSocketAddress

the host socket address

defaultPort:int

the protocol default port, or -1 if there is none

Returns:URI

the URI instance

Exceptions
URISyntaxException:
if the URI failed to be constructed for some reason
isInet4Addressback to summary
public static boolean isInet4Address(String address)

Checks whether given String is a valid IPv4 address.

Parameters
address:String

address textual representation

Returns:boolean

true if address is a valid IPv4 address, false otherwise

isInet6Addressback to summary
public static boolean isInet6Address(String address)

Checks whether given String is a valid IPv6 address.

Parameters
address:String

address textual representation

Returns:boolean

true if address is a valid IPv6 address, false otherwise

parseCidrAddressback to summary
public static CidrAddress parseCidrAddress(String address)

Parse a CIDR address into a CidrAddress object.

Parameters
address:String

the address to parse

Returns:CidrAddress

the parsed address, or null if the address is not valid

parseDecimalback to summary
private static byte parseDecimal(String number)
parseHexadecimalback to summary
private static short parseHexadecimal(String hexNumber)
parseInet4Addressback to summary
public static Inet4Address parseInet4Address(String address)

Parse an IPv4 address into an Inet4Address object.

Parameters
address:String

the address to parse

Returns:Inet4Address

the parsed address, or null if the address is not valid

parseInet4Addressback to summary
public static Inet4Address parseInet4Address(String address, String hostName)

Parse an IPv4 address into an Inet4Address object.

Parameters
address:String

the address to parse

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:Inet4Address

the parsed address, or null if the address is not valid

parseInet4AddressOrFailback to summary
public static Inet4Address parseInet4AddressOrFail(String address)

Parse an IPv4 address into an Inet4Address object, throwing an exception on failure.

Parameters
address:String

the address to parse

Returns:Inet4Address

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInet4AddressOrFailback to summary
public static Inet4Address parseInet4AddressOrFail(String address, String hostName)

Parse an IPv4 address into an Inet4Address object.

Parameters
address:String

the address to parse (must not be null)

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:Inet4Address

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInet4AddressToBytesback to summary
public static byte[] parseInet4AddressToBytes(String address)

Converts IPv4 address from textual representation to bytes.

If given string doesn't represent valid IPv4 address, the method returns null.

This only supports decimal notation.

Parameters
address:String

address textual representation

Returns:byte[]

byte array representing the address, or null if the address is not valid

parseInet6Addressback to summary
public static Inet6Address parseInet6Address(String address)

Parse an IPv6 address into an Inet6Address object.

Parameters
address:String

the address to parse

Returns:Inet6Address

the parsed address, or null if the address is not valid

parseInet6Addressback to summary
public static Inet6Address parseInet6Address(String address, String hostName)

Parse an IPv6 address into an Inet6Address object.

Parameters
address:String

the address to parse (must not be null)

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:Inet6Address

the parsed address, or null if the address is not valid

parseInet6AddressOrFailback to summary
public static Inet6Address parseInet6AddressOrFail(String address)

Parse an IPv6 address into an Inet6Address object, throwing an exception on failure.

Parameters
address:String

the address to parse

Returns:Inet6Address

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInet6AddressOrFailback to summary
public static Inet6Address parseInet6AddressOrFail(String address, String hostName)

Parse an IPv6 address into an Inet6Address object.

Parameters
address:String

the address to parse (must not be null)

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:Inet6Address

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInet6AddressToBytesback to summary
public static byte[] parseInet6AddressToBytes(String address)

Converts IPv6 address from textual representation to bytes.

If given string doesn't represent valid IPv6 address, the method returns null.

Parameters
address:String

address textual representation

Returns:byte[]

byte array representing the address, or null if the address is not valid

parseInetAddressback to summary
public static InetAddress parseInetAddress(String address)

Parse an IP address into an InetAddress object.

Parameters
address:String

the address to parse

Returns:InetAddress

the parsed address, or null if the address is not valid

parseInetAddressback to summary
public static InetAddress parseInetAddress(String address, String hostName)

Parse an IP address into an InetAddress object.

Parameters
address:String

the address to parse

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:InetAddress

the parsed address, or null if the address is not valid

parseInetAddressOrFailback to summary
public static InetAddress parseInetAddressOrFail(String address)

Parse an IP address into an InetAddress object, throwing an exception on failure.

Parameters
address:String

the address to parse

Returns:InetAddress

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInetAddressOrFailback to summary
public static InetAddress parseInetAddressOrFail(String address, String hostName)

Parse an IP address into an InetAddress object.

Parameters
address:String

the address to parse (must not be null)

hostName:String

the host name to use in the resultant object, or null to use the string representation of the address

Returns:InetAddress

the parsed address (not null)

Exceptions
IllegalArgumentException:
if the address is not valid
parseInetAddressToBytesback to summary
public static byte[] parseInetAddressToBytes(String address)

Converts an IP address from textual representation to bytes.

If given string doesn't represent valid IP address, the method returns null.

Parameters
address:String

address textual representation

Returns:byte[]

byte array representing the address, or null if the address is not valid

toInet6Addressback to summary
public static Inet6Address toInet6Address(InetAddress inetAddress)

Get the IPv6 equivalent of the given address. If the address is IPv4 then it is returned as a compatibility address.

Parameters
inetAddress:InetAddress

the address to convert (must not be null)

Returns:Inet6Address

the converted address (not null)

toOptimalStringback to summary
public static String toOptimalString(InetAddress inetAddress)

Get the optimal string representation of an IP address. For IPv6 addresses, this representation will be more compact that the default.

Parameters
inetAddress:InetAddress

the address (must not be null)

Returns:String

the string representation (not null)

toOptimalStringback to summary
public static String toOptimalString(byte[] addressBytes)

Get the optimal string representation of the bytes of an IP address.

Parameters
addressBytes:byte[]

the address bytes (must not be null)

Returns:String

the string representation (not null)

toOptimalStringV6back to summary
private static String toOptimalStringV6(final byte[] bytes)
toURLStringback to summary
public static String toURLString(InetAddress inetAddress, boolean useHostNameIfPresent)

Get a string representation of the given address which is suitable for use as the host component of a URL.

Parameters
inetAddress:InetAddress

the address (must not be null)

useHostNameIfPresent:boolean

true to preserve the host name string in the address, false to always give an IP address string

Returns:String

the string representation (not null)

toURLStringback to summary
public static String toURLString(byte[] addressBytes)

Get a string representation of the given address bytes which is suitable for use as the host component of a URL.

Parameters
addressBytes:byte[]

the address bytes (must not be null)

Returns:String

the string representation (not null)