411 this.protocol = protocol;
412 if (host != null) {
413
414 /**
415 * if host is a literal IPv6 address,
416 * we will make it conform to RFC 2732
417 */
418 if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
419 host = "["+host+"]";
420 }
421 this.host = host;
422
423 if (port < -1) {
424 throw new MalformedURLException("Invalid port number :" +
425 port);
426 }
427 this.port = port;
428 authority = (port == -1) ? host : host + ":" + port;
429 }
430
431 Parts parts = new Parts(file);
432 path = parts.getPath();
433 query = parts.getQuery();
434
435 if (query != null) {
436 this.file = path + "?" + query;
437 } else {
438 this.file = path;
439 }
440 ref = parts.getRef();
441
442 // Note: we don't do validation of the URL here. Too risky to change
443 // right now, but worth considering for future reference. -br
444 if (handler == null &&
445 (handler = getURLStreamHandler(protocol)) == null) {
446 throw new MalformedURLException("unknown protocol: " + protocol);
447 }
448 this.handler = handler;
449 }
450
451 /**
452 * Creates a {@code URL} object from the {@code String}
453 * representation.
454 * <p>
455 * This constructor is equivalent to a call to the two-argument
456 * constructor with a {@code null} first argument.
457 *
458 * @param spec the {@code String} to parse as a URL.
459 * @exception MalformedURLException if no protocol is specified, or an
460 * unknown protocol is found, or {@code spec} is {@code null},
1597 return (handlerClassName.startsWith(BUILTIN_HANDLERS_PREFIX));
1598 }
1599
1600 private void resetState() {
1601 this.protocol = null;
1602 this.host = null;
1603 this.port = -1;
1604 this.file = null;
1605 this.authority = null;
1606 this.ref = null;
1607 this.hashCode = -1;
1608 this.handler = null;
1609 this.query = null;
1610 this.path = null;
1611 this.userInfo = null;
1612 this.tempState = null;
1613 }
1614
1615 private void setSerializedHashCode(int hc) {
1616 this.hashCode = hc;
1617 }
1618 }
1619
1620 class Parts {
1621 String path, query, ref;
1622
1623 Parts(String file) {
1624 int ind = file.indexOf('#');
1625 ref = ind < 0 ? null: file.substring(ind + 1);
1626 file = ind < 0 ? file: file.substring(0, ind);
1627 int q = file.lastIndexOf('?');
1628 if (q != -1) {
1629 query = file.substring(q+1);
1630 path = file.substring(0, q);
1631 } else {
1632 path = file;
1633 }
1634 }
1635
1636 String getPath() {
1637 return path;
1638 }
1639
1640 String getQuery() {
1641 return query;
1642 }
1643
1644 String getRef() {
1645 return ref;
1646 }
1647 }
1648
1649 final class UrlDeserializedState {
1650 private final String protocol;
1651 private final String host;
1652 private final int port;
1653 private final String authority;
1654 private final String file;
1655 private final String ref;
1656 private final int hashCode;
1657
1658 public UrlDeserializedState(String protocol,
1659 String host, int port,
1660 String authority, String file,
1661 String ref, int hashCode) {
1662 this.protocol = protocol;
1663 this.host = host;
1664 this.port = port;
1665 this.authority = authority;
|
411 this.protocol = protocol;
412 if (host != null) {
413
414 /**
415 * if host is a literal IPv6 address,
416 * we will make it conform to RFC 2732
417 */
418 if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
419 host = "["+host+"]";
420 }
421 this.host = host;
422
423 if (port < -1) {
424 throw new MalformedURLException("Invalid port number :" +
425 port);
426 }
427 this.port = port;
428 authority = (port == -1) ? host : host + ":" + port;
429 }
430
431 int ind = file.indexOf('#');
432 this.ref = ind < 0 ? null : file.substring(ind + 1);
433 file = ind < 0 ? file : file.substring(0, ind);
434 int q = file.lastIndexOf('?');
435 if (q != -1) {
436 this.query = file.substring(q + 1);
437 this.path = file.substring(0, q);
438 this.file = path + "?" + query;
439 } else {
440 this.path = file;
441 this.file = path;
442 }
443
444 // Note: we don't do validation of the URL here. Too risky to change
445 // right now, but worth considering for future reference. -br
446 if (handler == null &&
447 (handler = getURLStreamHandler(protocol)) == null) {
448 throw new MalformedURLException("unknown protocol: " + protocol);
449 }
450 this.handler = handler;
451 }
452
453 /**
454 * Creates a {@code URL} object from the {@code String}
455 * representation.
456 * <p>
457 * This constructor is equivalent to a call to the two-argument
458 * constructor with a {@code null} first argument.
459 *
460 * @param spec the {@code String} to parse as a URL.
461 * @exception MalformedURLException if no protocol is specified, or an
462 * unknown protocol is found, or {@code spec} is {@code null},
1599 return (handlerClassName.startsWith(BUILTIN_HANDLERS_PREFIX));
1600 }
1601
1602 private void resetState() {
1603 this.protocol = null;
1604 this.host = null;
1605 this.port = -1;
1606 this.file = null;
1607 this.authority = null;
1608 this.ref = null;
1609 this.hashCode = -1;
1610 this.handler = null;
1611 this.query = null;
1612 this.path = null;
1613 this.userInfo = null;
1614 this.tempState = null;
1615 }
1616
1617 private void setSerializedHashCode(int hc) {
1618 this.hashCode = hc;
1619 }
1620 }
1621
1622 final class UrlDeserializedState {
1623 private final String protocol;
1624 private final String host;
1625 private final int port;
1626 private final String authority;
1627 private final String file;
1628 private final String ref;
1629 private final int hashCode;
1630
1631 public UrlDeserializedState(String protocol,
1632 String host, int port,
1633 String authority, String file,
1634 String ref, int hashCode) {
1635 this.protocol = protocol;
1636 this.host = host;
1637 this.port = port;
1638 this.authority = authority;
|