< prev index next >

src/java.base/share/classes/java/net/HostPortrange.java

Print this page




  43     boolean literal;
  44     boolean ipv6, ipv4;
  45     static final int PORT_MIN = 0;
  46     static final int PORT_MAX = (1 << 16) -1;
  47 
  48     boolean equals(HostPortrange that) {
  49         return this.hostname.equals(that.hostname)
  50             && this.portrange[0] == that.portrange[0]
  51             && this.portrange[1] == that.portrange[1]
  52             && this.wildcard == that.wildcard
  53             && this.literal == that.literal;
  54     }
  55 
  56     public int hashCode() {
  57         return hostname.hashCode() + portrange[0] + portrange[1];
  58     }
  59 
  60     HostPortrange(String scheme, String str) {
  61         // Parse the host name.  A name has up to three components, the
  62         // hostname, a port number, or two numbers representing a port
  63         // range.   "www.sun.com:8080-9090" is a valid host name.
  64 
  65         // With IPv6 an address can be 2010:836B:4179::836B:4179
  66         // An IPv6 address needs to be enclose in []
  67         // For ex: [2010:836B:4179::836B:4179]:8080-9090
  68         // Refer to RFC 2732 for more information.
  69 
  70         // first separate string into two fields: hoststr, portstr
  71         String hoststr, portstr = null;
  72         this.scheme = scheme;
  73 
  74         // check for IPv6 address
  75         if (str.charAt(0) == '[') {
  76             ipv6 = literal = true;
  77             int rb = str.indexOf(']');
  78             if (rb != -1) {
  79                 hoststr = str.substring(1, rb);
  80             } else {
  81                 throw new IllegalArgumentException("invalid IPv6 address: " + str);
  82             }
  83             int sep = str.indexOf(':', rb + 1);




  43     boolean literal;
  44     boolean ipv6, ipv4;
  45     static final int PORT_MIN = 0;
  46     static final int PORT_MAX = (1 << 16) -1;
  47 
  48     boolean equals(HostPortrange that) {
  49         return this.hostname.equals(that.hostname)
  50             && this.portrange[0] == that.portrange[0]
  51             && this.portrange[1] == that.portrange[1]
  52             && this.wildcard == that.wildcard
  53             && this.literal == that.literal;
  54     }
  55 
  56     public int hashCode() {
  57         return hostname.hashCode() + portrange[0] + portrange[1];
  58     }
  59 
  60     HostPortrange(String scheme, String str) {
  61         // Parse the host name.  A name has up to three components, the
  62         // hostname, a port number, or two numbers representing a port
  63         // range.   "www.example.com:8080-9090" is a valid host name.
  64 
  65         // With IPv6 an address can be 2010:836B:4179::836B:4179
  66         // An IPv6 address needs to be enclose in []
  67         // For ex: [2010:836B:4179::836B:4179]:8080-9090
  68         // Refer to RFC 2732 for more information.
  69 
  70         // first separate string into two fields: hoststr, portstr
  71         String hoststr, portstr = null;
  72         this.scheme = scheme;
  73 
  74         // check for IPv6 address
  75         if (str.charAt(0) == '[') {
  76             ipv6 = literal = true;
  77             int rb = str.indexOf(']');
  78             if (rb != -1) {
  79                 hoststr = str.substring(1, rb);
  80             } else {
  81                 throw new IllegalArgumentException("invalid IPv6 address: " + str);
  82             }
  83             int sep = str.indexOf(':', rb + 1);


< prev index next >