public class HostPort
extends java.lang.Object
Parse an authority string (in the form host:port
) into
host
and port
, handling IPv4 and IPv6 host formats
as defined in https://www.ietf.org/rfc/rfc2732.txt
Constructor and Description |
---|
HostPort(java.lang.String authority) |
HostPort(java.lang.String host,
int port) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getHost()
Get the host.
|
int |
getPort()
Get the port.
|
int |
getPort(int defaultPort)
Get the port or the given default port.
|
static java.lang.String |
normalizeHost(java.lang.String host)
Normalizes IPv6 address as per https://tools.ietf.org/html/rfc2732
and https://tools.ietf.org/html/rfc6874,
surrounding with square brackets if they are absent.
|
static int |
parsePort(java.lang.String rawPort)
Parse a string representing a port validating it is a valid port value.
|
java.lang.String |
toString() |
public HostPort(java.lang.String host, int port)
public HostPort(java.lang.String authority) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public java.lang.String getHost()
public int getPort()
public int getPort(int defaultPort)
defaultPort,
- the default port to return if a port is not specifiedpublic java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String normalizeHost(java.lang.String host)
host
- a host name, IPv4 address, IPv6 address or IPv6 literalpublic static int parsePort(java.lang.String rawPort) throws java.lang.IllegalArgumentException
rawPort
- the port string.java.lang.IllegalArgumentException
- if the port is invalidCopyright © 1995–2021 Webtide. All rights reserved.