< prev index next >

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

Print this page

1199             // delegate to different addresses when we are already replaced
1200             // but outside of synchronized block to avoid any chance of dead-locking
1201             return addresses.get();
1202         }
1203     }
1204 
1205     /**
1206      * The default InetAddressResolver implementation, which delegates to the underlying
1207      * OS network libraries to resolve host address mappings.
1208      *
1209      * @since 9
1210      */
1211     private static final class PlatformResolver implements InetAddressResolver {
1212 
1213         public Stream<InetAddress> lookupByName(String host, LookupPolicy policy)
1214                 throws UnknownHostException {
1215             Objects.requireNonNull(host);
1216             Objects.requireNonNull(policy);
1217             validate(host);
1218             InetAddress[] addrs;
1219             long comp = Blocker.begin();
1220             try {
1221                 addrs = impl.lookupAllHostAddr(host, policy);
1222             } finally {
1223                 Blocker.end(comp);
1224             }
1225             return Arrays.stream(addrs);
1226         }
1227 
1228         public String lookupByAddress(byte[] addr) throws UnknownHostException {
1229             Objects.requireNonNull(addr);
1230             if (addr.length != Inet4Address.INADDRSZ && addr.length != Inet6Address.INADDRSZ) {
1231                 throw new IllegalArgumentException("Invalid address length");
1232             }
1233             long comp = Blocker.begin();
1234             try {
1235                 return impl.getHostByAddr(addr);
1236             } finally {
1237                 Blocker.end(comp);
1238             }
1239         }
1240     }
1241 
1242     /**
1243      * The HostsFileResolver provides host address mapping
1244      * by reading the entries in a hosts file, which is specified by
1245      * {@code jdk.net.hosts.file} system property
1246      *
1247      * <p>The file format is that which corresponds with the /etc/hosts file
1248      * IP Address host alias list.
1249      *
1250      * <p>When the file lookup is enabled it replaces the default InetAddressResolver
1251      * implementation
1252      *
1253      * @since 9
1254      */
1255     private static final class HostsFileResolver implements InetAddressResolver {
1256 
1257         private final String hostsFile;

1199             // delegate to different addresses when we are already replaced
1200             // but outside of synchronized block to avoid any chance of dead-locking
1201             return addresses.get();
1202         }
1203     }
1204 
1205     /**
1206      * The default InetAddressResolver implementation, which delegates to the underlying
1207      * OS network libraries to resolve host address mappings.
1208      *
1209      * @since 9
1210      */
1211     private static final class PlatformResolver implements InetAddressResolver {
1212 
1213         public Stream<InetAddress> lookupByName(String host, LookupPolicy policy)
1214                 throws UnknownHostException {
1215             Objects.requireNonNull(host);
1216             Objects.requireNonNull(policy);
1217             validate(host);
1218             InetAddress[] addrs;
1219             boolean attempted = Blocker.beginCompenstate();
1220             try {
1221                 addrs = impl.lookupAllHostAddr(host, policy);
1222             } finally {
1223                 Blocker.endCompenstate(attempted);
1224             }
1225             return Arrays.stream(addrs);
1226         }
1227 
1228         public String lookupByAddress(byte[] addr) throws UnknownHostException {
1229             Objects.requireNonNull(addr);
1230             if (addr.length != Inet4Address.INADDRSZ && addr.length != Inet6Address.INADDRSZ) {
1231                 throw new IllegalArgumentException("Invalid address length");
1232             }
1233             boolean attempted = Blocker.beginCompenstate();
1234             try {
1235                 return impl.getHostByAddr(addr);
1236             } finally {
1237                 Blocker.endCompenstate(attempted);
1238             }
1239         }
1240     }
1241 
1242     /**
1243      * The HostsFileResolver provides host address mapping
1244      * by reading the entries in a hosts file, which is specified by
1245      * {@code jdk.net.hosts.file} system property
1246      *
1247      * <p>The file format is that which corresponds with the /etc/hosts file
1248      * IP Address host alias list.
1249      *
1250      * <p>When the file lookup is enabled it replaces the default InetAddressResolver
1251      * implementation
1252      *
1253      * @since 9
1254      */
1255     private static final class HostsFileResolver implements InetAddressResolver {
1256 
1257         private final String hostsFile;
< prev index next >