public static void main(String args[]) throws ParseException { String hostNames[] = { "foo.bar.com:1234", "proxima.chaplin.bt.co.uk", "129.6.55.181:2345", ":1234", "foo.bar.com: 1234", "foo.bar.com : 1234 ", "MIK_S:1234" }; for (int i = 0; i < hostNames.length; i++) { try { HostNameParser hnp = new HostNameParser(hostNames[i]); HostPort hp = hnp.hostPort(true); System.out.println("["+hp.encode()+"]"); } catch (ParseException ex) { System.out.println("exception text = " + ex.getMessage()); } } } }
/** * Parse a host name and return a parsed structure. * * @param host * is a String containing the host name to be parsed * @return a parsed address structure. * @since v1.0 * @exception ParseException * a ParseException when the hostname is badly formatted. */ public Host parseHost(String host) throws ParseException { Lexer lexer = new Lexer("charLexer", host); return new HostNameParser(lexer).host(); }
public Host host() throws ParseException { if (debug) dbg_enter("host"); try { String hostname; hostname = ipv6Reference(); else if( isIPv6Address(lexer.getRest()) ) consumeDomainLabel(); hostname = lexer.getBuffer().substring(startPtr, lexer.getPtr()); } finally { if (debug) dbg_leave("host");
protected String uricString() throws ParseException { StringBuilder retval = new StringBuilder(); while (true) { String next = uric(); if (next == null) { char la = lexer.lookAhead(0); // JvB: allow IPv6 addresses in generic URI strings // e.g. http://[::1] if ( la == '[' ) { HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort( false ); retval.append(hp.toString()); continue; } break; } retval.append(next); } return retval.toString(); }
HostNameParser hostNameParser = new HostNameParser(host); Host h = hostNameParser.host(); originField.setAddress(h);
HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hostPort = hnp.hostPort( true ); v.setSentBy(hostPort);
HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort( false ); retval.setHostPort(hp);