< prev index next >

src/java.base/share/classes/sun/security/x509/IPAddressName.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 108      * Create an IPAddressName from a String.
 109      * [IETF RFC1338 Supernetting {@literal &} IETF RFC1519 Classless Inter-Domain
 110      * Routing (CIDR)] For IPv4 addresses, the forms are
 111      * "b1.b2.b3.b4" or "b1.b2.b3.b4/m1.m2.m3.m4", where b1 - b4 are decimal
 112      * byte values 0-255 and m1 - m4 are decimal mask values
 113      * 0 - 255.
 114      * <p>
 115      * [IETF RFC2373 IP Version 6 Addressing Architecture]
 116      * For IPv6 addresses, the forms are "a1:a2:...:a8" or "a1:a2:...:a8/n",
 117      * where a1-a8 are hexadecimal values representing the eight 16-bit pieces
 118      * of the address. If /n is used, n is a decimal number indicating how many
 119      * of the leftmost contiguous bits of the address comprise the prefix for
 120      * this subnet. Internally, a mask value is created using the prefix length.
 121      *
 122      * @param name String form of IPAddressName
 123      * @throws IOException if name can not be converted to a valid IPv4 or IPv6
 124      *     address
 125      */
 126     public IPAddressName(String name) throws IOException {
 127 
 128         if (name == null || name.length() == 0) {
 129             throw new IOException("IPAddress cannot be null or empty");
 130         }
 131         if (name.charAt(name.length() - 1) == '/') {
 132             throw new IOException("Invalid IPAddress: " + name);
 133         }
 134 
 135         if (name.indexOf(':') >= 0) {
 136             // name is IPv6: uses colons as value separators
 137             // Parse name into byte-value address components and optional
 138             // prefix
 139             parseIPv6(name);
 140             isIPv4 = false;
 141         } else if (name.indexOf('.') >= 0) {
 142             //name is IPv4: uses dots as value separators
 143             parseIPv4(name);
 144             isIPv4 = true;
 145         } else {
 146             throw new IOException("Invalid IPAddress: " + name);
 147         }
 148     }




 108      * Create an IPAddressName from a String.
 109      * [IETF RFC1338 Supernetting {@literal &} IETF RFC1519 Classless Inter-Domain
 110      * Routing (CIDR)] For IPv4 addresses, the forms are
 111      * "b1.b2.b3.b4" or "b1.b2.b3.b4/m1.m2.m3.m4", where b1 - b4 are decimal
 112      * byte values 0-255 and m1 - m4 are decimal mask values
 113      * 0 - 255.
 114      * <p>
 115      * [IETF RFC2373 IP Version 6 Addressing Architecture]
 116      * For IPv6 addresses, the forms are "a1:a2:...:a8" or "a1:a2:...:a8/n",
 117      * where a1-a8 are hexadecimal values representing the eight 16-bit pieces
 118      * of the address. If /n is used, n is a decimal number indicating how many
 119      * of the leftmost contiguous bits of the address comprise the prefix for
 120      * this subnet. Internally, a mask value is created using the prefix length.
 121      *
 122      * @param name String form of IPAddressName
 123      * @throws IOException if name can not be converted to a valid IPv4 or IPv6
 124      *     address
 125      */
 126     public IPAddressName(String name) throws IOException {
 127 
 128         if (name == null || name.isEmpty()) {
 129             throw new IOException("IPAddress cannot be null or empty");
 130         }
 131         if (name.charAt(name.length() - 1) == '/') {
 132             throw new IOException("Invalid IPAddress: " + name);
 133         }
 134 
 135         if (name.indexOf(':') >= 0) {
 136             // name is IPv6: uses colons as value separators
 137             // Parse name into byte-value address components and optional
 138             // prefix
 139             parseIPv6(name);
 140             isIPv4 = false;
 141         } else if (name.indexOf('.') >= 0) {
 142             //name is IPv4: uses dots as value separators
 143             parseIPv4(name);
 144             isIPv4 = true;
 145         } else {
 146             throw new IOException("Invalid IPAddress: " + name);
 147         }
 148     }


< prev index next >