Home | History | Annotate | Download | only in net

Lines Matching defs:host

34  * An immutable representation of a host and port.
59 * host field (if desired) is the caller's responsibility.
72 private final String host;
77 /** True if the parsed host has colons, but no surrounding brackets. */
80 private HostAndPort(String host, int port, boolean hasBracketlessColons) {
81 this.host = host;
94 return host;
122 * Build a HostAndPort instance from separate host and port values.
127 * @param host the host string to parse. Must not contain a port number.
130 * @throws IllegalArgumentException if {@code host} contains a port number,
133 public static HostAndPort fromParts(String host, int port) {
135 HostAndPort parsedHost = fromString(host);
136 checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host);
137 return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons);
141 * Build a HostAndPort instance from a host only.
146 * @param host the host-only string to parse. Must not contain a port number.
148 * @throws IllegalArgumentException if {@code host} contains a port number.
151 public static HostAndPort fromHost(String host) {
152 HostAndPort parsedHost = fromString(host);
153 checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host);
158 * Split a freeform string into a host and port, without strict validation.
160 * Note that the host-only formats will leave the port field undefined. You
169 String host;
175 host = hostAndPort[0];
180 // Exactly 1 colon. Split into host:port.
181 host = hostPortString.substring(0, colonPos);
185 host = hostPortString;
203 return new HostAndPort(host, port, hasBracketlessColons);
207 * Parses a bracketed host-port string, throwing IllegalArgumentException if parsing fails.
209 * @param hostPortString the full bracketed host-port specification. Post might not be specified.
210 * @return an array with 2 strings: host and port, in that order.
211 * @throws IllegalArgumentException if parsing the bracketed host-port string fails.
217 "Bracketed host-port string must start with a bracket: %s", hostPortString);
221 "Invalid bracketed host/port: %s", hostPortString);
223 String host = hostPortString.substring(1, closeBracketIndex);
225 return new String[] { host, "" };
233 return new String[] { host, hostPortString.substring(closeBracketIndex + 2) };
238 * Provide a default port if the parsed string contained only a host.
252 return new HostAndPort(host, defaultPort, hasBracketlessColons);
256 * Generate an error if the host might be a non-bracketed IPv6 literal.
271 checkArgument(!hasBracketlessColons, "Possible bracketless IPv6 literal: %s", host);
282 return Objects.equal(this.host, that.host)
291 return Objects.hashCode(host, port, hasBracketlessColons);
294 /** Rebuild the host:port string, including brackets if necessary. */
298 StringBuilder builder = new StringBuilder(host.length() + 8);
299 if (host.indexOf(':') >= 0) {
300 builder.append('[').append(host).append(']');
302 builder.append(host);