public final class NetUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canTcpListen(InetAddress address,
int port) |
static InetAddress |
ensureGetInterfaceAddress(String interfaceName) |
static String |
getHostAddress() |
static String |
getHostName() |
static InetAddress |
getInterfaceAddress(String interfaceName) |
static String |
getIpv6HostAddress() |
static String |
getRealListenAddress(String schema,
String address)
对于配置为0.0.0.0的地址,let it go
schema, e.g.
|
static String |
humanReadableBytes(long bytes) |
static IpPort |
parseIpPort(String address)
The format of address should be
IPv4:port or [IPv6]:port, or host:port,
or you will not get expected result. |
static IpPort |
parseIpPort(String scheme,
String authority) |
static IpPort |
parseIpPort(URI uri)
|
static IpPort |
parseIpPort(URI uri,
boolean ignorePortUndefined)
|
static IpPort |
parseIpPortFromURI(String uriAddress) |
public static IpPort parseIpPort(String address)
IPv4:port or [IPv6]:port, or host:port,
or you will not get expected result.
Note that the IPv6 address should be wrapped by square brackets.null if the param is null.public static IpPort parseIpPort(URI uri)
URI into an IpPort.
A uri without port is allowed, in which case the port will be inferred from the scheme. http is 80, and
https is 443.
The host of the uri should not be null, or it will be treated as an illegal param,
and an IllegalArgumentException will be thrown.
public static IpPort parseIpPort(URI uri, boolean ignorePortUndefined)
uri - a uri representing IpPortignorePortUndefined - whether the port should be inferred from scheme, when the port part of uri is -1.
If true the undefined port is ignored;
otherwise a port will be inferred from scheme: http is 80, and https is 443.public static IpPort parseIpPortFromURI(String uriAddress)
uriAddress - the address containing IP and port info.null if the param is null.public static String getRealListenAddress(String schema, String address)
public static String getHostName()
public static String getHostAddress()
public static String getIpv6HostAddress()
public static InetAddress getInterfaceAddress(String interfaceName)
public static InetAddress ensureGetInterfaceAddress(String interfaceName)
public static boolean canTcpListen(InetAddress address, int port)
public static String humanReadableBytes(long bytes)
Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.