Top Description Fields Constructors Methods
org.eclipse.jetty.util

public Class HostPort

extends Object
Class Inheritance
Imports
java.net.InetAddress, org.eclipse.jetty.util.annotation.ManagedAttribute, org.slf4j.Logger, .LoggerFactory

Parse an authority string (in the form host:port) into host and port, handling IPv4 and IPv6 host formats as defined in RFC 2732

Field Summary

Modifier and TypeField and Description
private final String
private final int
private static final int
private static final Logger

Constructor Summary

AccessConstructor and Description
public
HostPort(String host, int port)

public
HostPort(String authority)

private
HostPort(String authority, boolean unsafe)

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the host
getHost
()

Get the host.

public int

Returns:

the port
getPort
()

Get the port.

public int

Returns:

the port
getPort
(int
the default port to return if a port is not specified
defaultPort
)

Get the port or the given default port.

public boolean
public boolean
protected boolean
protected boolean
public static String

Returns:

a host name or an IPv4 address or an IPv6 literal (not an IPv6 address)
normalizeHost
(String
a host name, IPv4 address, IPv6 address or IPv6 literal
host
)

Normalizes IPv6 address as per RFC 2732 and RFC 6874, surrounding with square brackets if they are absent.

public static int

Returns:

the integer value for the port.
parsePort
(String
the port string.
rawPort
)

Parse a string representing a port validating it is a valid port value.

private int

Returns:

the port
parsePort
(String
the raw port string to parse
rawPort
,
boolean
true to always return a port in the range 0 to 65535 (or -1 for undefined if rawPort is horribly bad), false to return the provided port (or IllegalArgumentException if it is horribly bad)
unsafe
)

Parse a potential port.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static HostPort

Returns:

the HostPort
unsafe
(String
raw authority
authority
)

Create a HostPort from an unsafe (and not validated) authority.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_hostback to summary
private final String _host
_portback to summary
private final int _port
BAD_PORTback to summary
private static final int BAD_PORT
LOGback to summary
private static final Logger LOG

Constructor Detail

HostPortback to summary
public HostPort(String host, int port)
HostPortback to summary
public HostPort(String authority) throws IllegalArgumentException
HostPortback to summary
private HostPort(String authority, boolean unsafe)
Annotations
@SuppressWarnings:ReassignedVariable, DataFlowIssue

Method Detail

getHostback to summary
public String getHost()

Get the host.

Returns:String

the host

Annotations
@ManagedAttribute:host
getPortback to summary
public int getPort()

Get the port.

Returns:int

the port

Annotations
@ManagedAttribute:port
getPortback to summary
public int getPort(int defaultPort)

Get the port or the given default port.

Parameters
defaultPort:int

the default port to return if a port is not specified

Returns:int

the port

hasHostback to summary
public boolean hasHost()
hasPortback to summary
public boolean hasPort()
isValidHostNameback to summary
protected boolean isValidHostName(String name)
isValidIpAddressback to summary
protected boolean isValidIpAddress(String ip)
normalizeHostback to summary
public static String normalizeHost(String host)

Normalizes IPv6 address as per RFC 2732 and RFC 6874, surrounding with square brackets if they are absent.

Parameters
host:String

a host name, IPv4 address, IPv6 address or IPv6 literal

Returns:String

a host name or an IPv4 address or an IPv6 literal (not an IPv6 address)

parsePortback to summary
public static int parsePort(String rawPort) throws IllegalArgumentException

Parse a string representing a port validating it is a valid port value.

Parameters
rawPort:String

the port string.

Returns:int

the integer value for the port.

Exceptions
IllegalArgumentException:
if the port is invalid
parsePortback to summary
private int parsePort(String rawPort, boolean unsafe)

Parse a potential port.

Parameters
rawPort:String

the raw port string to parse

unsafe:boolean

true to always return a port in the range 0 to 65535 (or -1 for undefined if rawPort is horribly bad), false to return the provided port (or IllegalArgumentException if it is horribly bad)

Returns:int

the port

Exceptions
IllegalArgumentException:
if unable to parse a valid port and unsafe is false
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unsafeback to summary
public static HostPort unsafe(String authority)

Create a HostPort from an unsafe (and not validated) authority.

There are no validations performed against the provided authority. It is quite possible to end up with HostPort that cannot be used to generate valid URL, URI, InetSocketAddress, Location header, etc.

Parameters
authority:String

raw authority

Returns:HostPort

the HostPort