@Immutable
public final class Inet
extends Object
Provides some utility functions for Inet addresses.
Modifier and Type | Field and Description |
---|---|
static String |
LOCAL_HOST
Local host.
|
Modifier and Type | Method and Description |
---|---|
static int |
allocateTCPPort()
Allocates a TCP port.
|
static int |
allocateUDPPort()
Allocates an UDP port.
|
static Optional<byte[]> |
getHardwareAddress(Optional<String> name)
Gets the hardware address.
|
static InetAddress |
getLocalAddress(Optional<String> addressString)
Gets a local address.
|
static InetAddress |
getLocalHostAddress()
Gets the local host address.
|
static boolean |
isOnLocalHost(InetAddress address)
Asks if the supplied address is on an interface of the local host.
|
static boolean |
isOnLocalHost(URI uri)
Asks if the supplied URI points to an interface on the local host.
|
static Optional<InetSocketAddress> |
socketAddress(String addressString)
Returns a SocketAddress from an address string.
|
static InetAddress |
substituteAddress(InetAddress address)
Returns the loopback address if the host address is on localhost.
|
static Optional<URI> |
substituteURI(URI uri)
Returns a loopback URI if the host address is on localhost.
|
public static final String LOCAL_HOST
@CheckReturnValue public static int allocateTCPPort()
Used by some tests to get an unallocated port. Also used to create a 'stealth' service registry.
@CheckReturnValue public static int allocateUDPPort()
Used by some tests to get an unallocated port.
@Nonnull @CheckReturnValue public static Optional<byte[]> getHardwareAddress(@Nonnull Optional<String> name)
name
- An optional host name to select an interface.@Nullable @CheckReturnValue public static InetAddress getLocalAddress(@Nonnull Optional<String> addressString)
addressString
- An optional address string.@Nonnull @CheckReturnValue public static InetAddress getLocalHostAddress()
@CheckReturnValue public static boolean isOnLocalHost(@Nonnull InetAddress address)
address
- The address.@CheckReturnValue public static boolean isOnLocalHost(@Nonnull URI uri)
uri
- The URI.@Nonnull @CheckReturnValue public static Optional<InetSocketAddress> socketAddress(@Nonnull String addressString)
The format of the address string is "host:port". When present, a leading "//" or a trailing "/" are ignored to permit a more general, URL like, format.
addressString
- The address string.@Nonnull @CheckReturnValue public static InetAddress substituteAddress(@Nonnull InetAddress address)
address
- The original address.@Nonnull @CheckReturnValue public static Optional<URI> substituteURI(@Nonnull URI uri)
uri
- The original URI.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.