Package io.hekate.core.internal.util
Class AddressUtils
- java.lang.Object
-
- io.hekate.core.internal.util.AddressUtils
-
public final class AddressUtils extends Object
Network-related utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static String
FILE_PREFIX
Prefix for the file name oftoFileName(InetSocketAddress)
.static String
PORT_SEPARATOR
Separator of host and port components fortoFileName(InetSocketAddress)
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<NetworkInterface>
activeNetworks()
Returns an immutable list of allactive
network interfaces.static InetSocketAddress
fromFileName(String name, org.slf4j.Logger log)
Parses an address from the specified file name which was constructed viatoFileName(InetSocketAddress)
.static String
host(InetSocketAddress addr)
Returns thehost address
of asocket address
.static InetSocketAddress
parse(String address, ConfigCheck check)
Parses the specified string into anInetSocketAddress
.static InetSocketAddress
parseUnresolved(String address, ConfigCheck check)
Parses the specified string as anInetSocketAddress
with an unresolved host name.static String
toFileName(InetSocketAddress address)
Converts the specified address into a string that is suitable for naming files.
-
-
-
Field Detail
-
FILE_PREFIX
public static final String FILE_PREFIX
Prefix for the file name oftoFileName(InetSocketAddress)
.- See Also:
- Constant Field Values
-
PORT_SEPARATOR
public static final String PORT_SEPARATOR
Separator of host and port components fortoFileName(InetSocketAddress)
.- See Also:
- Constant Field Values
-
-
Method Detail
-
activeNetworks
public static List<NetworkInterface> activeNetworks() throws SocketException
Returns an immutable list of allactive
network interfaces.- Returns:
- List of all
active
network interfaces. - Throws:
SocketException
- If network interfaces couldn't be loaded.- See Also:
NetworkInterface.getNetworkInterfaces()
-
parse
public static InetSocketAddress parse(String address, ConfigCheck check) throws UnknownHostException
Parses the specified string into anInetSocketAddress
.String must be formatted as
<host>:<port>
(f.e.192.168.39.41:10012
). IPv6 addresses must wrap<host>
path with square brackets.- Parameters:
address
- Address string.check
- Checker that should be used to report the address parsing errors.- Returns:
- Address or
null
if the provided address string is empty or isnull
. - Throws:
UnknownHostException
- Signals that the host address couldn't be resolved (seeInetAddress.getByName(String)
).
-
parseUnresolved
public static InetSocketAddress parseUnresolved(String address, ConfigCheck check)
Parses the specified string as anInetSocketAddress
with an unresolved host name.String must be formatted as
<host>:<port>
(f.e.192.168.39.41:10012
). IPv6 addresses should wrap<host>
path with square brackets.- Parameters:
address
- Address string.check
- Checker that should be used to report parsing errors.- Returns:
- Address or
null
if the provided address string is empty ornull
.
-
toFileName
public static String toFileName(InetSocketAddress address)
Converts the specified address into a string that is suitable for naming files.- Parameters:
address
- Address.- Returns:
- File name.
- See Also:
fromFileName(String, Logger)
-
fromFileName
public static InetSocketAddress fromFileName(String name, org.slf4j.Logger log)
Parses an address from the specified file name which was constructed viatoFileName(InetSocketAddress)
. Returnsnull
if address could not be parsed due to invalid file format or if host address can't beresolved
.- Parameters:
name
- File name.log
- Optional logger for errors logging.- Returns:
- Address or
null
if parsing failed or parsed host isunknown
.
-
host
public static String host(InetSocketAddress addr)
Returns thehost address
of asocket address
.- Parameters:
addr
- Address.- Returns:
- Host address.
-
-