Tabnine Logo
UnknownHostException
Code IndexAdd Tabnine to your IDE (free)

How to use
UnknownHostException
in
java.net

Best Java code snippets using java.net.UnknownHostException (Showing top 20 results out of 8,199)

Refine searchRefine arrow

  • InetAddress
  • InetSocketAddress
  • NetworkInterface
  • Enumeration
  • Socket
origin: apache/ignite

/**
 * @throws IgniteSpiException If any error occurs.
 * @return {@code true} if IP finder contains local address.
 */
boolean ipFinderHasLocalAddress() throws IgniteSpiException {
  for (InetSocketAddress locAddr : locNodeAddrs) {
    for (InetSocketAddress addr : registeredAddresses())
      try {
        int port = addr.getPort();
        InetSocketAddress resolved = addr.isUnresolved() ?
          new InetSocketAddress(InetAddress.getByName(addr.getHostName()), port) :
          new InetSocketAddress(addr.getAddress(), port);
        if (resolved.equals(locAddr))
          return true;
      }
      catch (UnknownHostException e) {
        getExceptionRegistry().onException(e.getMessage(), e);
      }
  }
  return false;
}
origin: geoserver/geoserver

  InetAddress candidateAddress = null;
  for (Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
      interfaces.hasMoreElements(); ) {
    NetworkInterface ni = (NetworkInterface) interfaces.nextElement();
    for (Enumeration inetAddrs = ni.getInetAddresses(); inetAddrs.hasMoreElements(); ) {
      InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
      if (!inetAddr.isLoopbackAddress()) {
        if (inetAddr.isSiteLocalAddress()) {
          return inetAddr;
        } else if (candidateAddress == null) {
  InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
  if (jdkSuppliedAddress == null) {
    throw new UnknownHostException(
        "The JDK InetAddress.getLocalHost() method unexpectedly returned null.");
} catch (Exception e) {
  UnknownHostException unknownHostException =
      new UnknownHostException("Failed to determine LAN address");
  unknownHostException.initCause(e);
  throw unknownHostException;
origin: alibaba/TProfiler

/**
 * 建立远程连接并发送命令
 *
 * @param command
 * @param server
 * @param port
 */
private static void doSend(String command, String server, int port) {
  Socket socket = null;
  try {
    socket = new Socket(server, port);
    OutputStream os = socket.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(os);
    out.write(command.getBytes());
    out.write('\r');
    out.flush();
  } catch (UnknownHostException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (socket != null && !socket.isClosed()) {
      try {
        socket.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}
origin: robovm/robovm

public UnknownHostException rethrowAsUnknownHostException(String detailMessage) throws UnknownHostException {
  UnknownHostException newException = new UnknownHostException(detailMessage);
  newException.initCause(this);
  throw newException;
}
origin: seven332/EhViewer

 @Override
 public List<InetAddress> lookup(String hostname) throws UnknownHostException {
  if (hostname == null) throw new UnknownHostException("hostname == null");

  InetAddress inetAddress = hosts.get(hostname);
  if (inetAddress != null) {
   return Collections.singletonList(inetAddress);
  }

  if (Settings.getBuiltInHosts()) {
   inetAddress = builtInHosts.get(hostname);
   if (inetAddress != null) {
    return Collections.singletonList(inetAddress);
   }
  }

  try {
   return Arrays.asList(InetAddress.getAllByName(hostname));
  } catch (NullPointerException e) {
   UnknownHostException unknownHostException =
     new UnknownHostException("Broken system behaviour for dns lookup of " + hostname);
   unknownHostException.initCause(e);
   throw unknownHostException;
  }
 }
}
origin: camunda/camunda-bpm-platform

private static String getLocalAddressAsString() throws UnknownHostException,
    SocketException {
 Enumeration<NetworkInterface> interfaces =
     NetworkInterface.getNetworkInterfaces();
 while (interfaces != null && interfaces.hasMoreElements()) {
  Enumeration<InetAddress> addresses =
      interfaces.nextElement().getInetAddresses();
  while (addresses != null && addresses.hasMoreElements()) {
   InetAddress address = addresses.nextElement();
   if (acceptableAddress(address)) {
    return address.getHostAddress();
   }
  }
 }
 throw new UnknownHostException();
}
origin: wildfly/wildfly

NetworkInterface bind_intf=null;
if(bind_addr != null && bind_addr.isLoopbackAddress())
  return bind_addr;
  throw new UnknownHostException("network interface " + bind_interface_str + " not found");
  Enumeration addresses=bind_intf.getInetAddresses();
  while(addresses != null && addresses.hasMoreElements()) {
    InetAddress address=(InetAddress)addresses.nextElement();
    if(bind_addr.equals(address)) {
      hasAddress=true;
      break;
    String bind_addr_str=bind_addr.getHostAddress();
    throw new IllegalArgumentException("network interface " + bind_interface_str + " does not contain address " + bind_addr_str);
if(bind_addr != null && NetworkInterface.getByInetAddress(bind_addr) == null) {
  throw new UnknownHostException("Invalid bind address " + bind_addr);
origin: wildfly/wildfly

/**
 * A function to check if an interface supports an IP version (i.e has addresses
 * defined for that IP version).
 * @param intf
 * @return
 */
public static boolean interfaceHasIPAddresses(NetworkInterface intf,StackType ip_version) throws UnknownHostException {
  boolean supportsVersion=false;
  if(intf != null) {
    // get all the InetAddresses defined on the interface
    Enumeration addresses=intf.getInetAddresses();
    while(addresses != null && addresses.hasMoreElements()) {
      // get the next InetAddress for the current interface
      InetAddress address=(InetAddress)addresses.nextElement();
      // check if we find an address of correct version
      if((address instanceof Inet4Address && (ip_version == StackType.IPv4)) ||
       (address instanceof Inet6Address && (ip_version == StackType.IPv6))) {
        supportsVersion=true;
        break;
      }
    }
  }
  else {
    throw new UnknownHostException("network interface " + intf + " not found");
  }
  return supportsVersion;
}
origin: robovm/robovm

Enumeration<InetAddress> addressList = nif.getInetAddresses();
while (addressList.hasMoreElements()) {
  InetAddress ia = addressList.nextElement();
  if (ia.getAddress().length == 16) {
    Inet6Address v6ia = (Inet6Address) ia;
    boolean isSameType = v6ia.compareLocalType(address);
      address.scope_id = v6ia.scope_id;
      address.scope_ifname_set = true;
      address.ifname = nif.getName();
      break;
  throw new UnknownHostException("Scope id not found for address: " + Arrays.toString(addr));
origin: io.joynr.java/javaapi

public static void checkConnectivity(String host) throws IOException {
  InetAddress headUnitAddr = InetAddress.getByName(host);
  Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
  NetworkInterface iface;
  while (interfaces.hasMoreElements()) {
    iface = interfaces.nextElement();
    if (headUnitAddr.isReachable(iface, 0, 5000)) {
      return;
    }
  }
  throw new UnknownHostException("Connectivity check to the host \"" + host + "\" has failed");
}
origin: apache/incubator-dubbo

anyhost = true;
try {
  hostToBind = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
  logger.warn(e.getMessage(), e);
      try (Socket socket = new Socket()) {
        SocketAddress addr = new InetSocketAddress(registryURL.getHost(), registryURL.getPort());
        socket.connect(addr, 1000);
        hostToBind = socket.getLocalAddress().getHostAddress();
        break;
      } catch (Exception e) {
origin: i2p/i2p.i2p

if (_proxy != null) try { _proxy.close(); } catch (IOException ioe) {}
      String hostlc = host.toLowerCase(Locale.US);
      if (hostlc.endsWith(".i2p"))
        throw new UnknownHostException("I2P addresses must be proxied");
      if (hostlc.endsWith(".onion"))
        throw new UnknownHostException("Tor addresses must be proxied");
      int port = url.getPort();
      if (port == -1)
        port = 80;
      if (_fetchHeaderTimeout > 0) {
        _proxy = new Socket();
        _proxy.setSoTimeout(_fetchHeaderTimeout);
        _proxy.connect(new InetSocketAddress(host, port), _fetchHeaderTimeout);
      } else {
        _proxy = new Socket(host, port);
origin: dmart28/reveno

public void connect() throws IllegalStateException, IOException {
  if (isConnected()) {
    throw new IllegalStateException("Already connected");
  }
  InetSocketAddress address = this.address;
  if (address == null) {
    address = new InetSocketAddress(hostname, port);
  }
  if (address.getAddress() == null) {
    throw new UnknownHostException(address.getHostName());
  }
  this.socket = socketFactory.createSocket(address.getAddress(), address.getPort());
  this.writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), charset));
}

origin: gocd/gocd

public static String getLocalhostNameOrRandomNameIfNotFound() {
  if (hostName != null) {
    return hostName;
  }
  try {
    hostName = InetAddress.getLocalHost().getHostName();
  } catch (UnknownHostException e) {
    hostName = "unknown-host-" + Math.abs(new Random(System.currentTimeMillis()).nextInt()) % 1000;
    LOG.warn("Unable to resolve hostname: {}. Using: {}", e.getMessage(), hostName);
  }
  return hostName;
}
origin: guoguibing/librec

/**
 * Get IP of the System.
 *
 * @return IP of the System
 */
public static String getIP() {
  InetAddress ip = null;
  try {
    ip = InetAddress.getLocalHost();
  } catch (UnknownHostException e) {
    e.printStackTrace();
  }
  return ip.getHostName() + "@" + ip.getHostAddress();
}
origin: killbill/killbill

  public static String get() {
    try {
      final InetAddress addr = InetAddress.getLocalHost();
      return addr.getHostName();
    } catch (UnknownHostException e) {
      e.printStackTrace();
      return "hostname-unknown";
    }
  }
}
origin: org.caiguoqing/uyuni-rpc

private void init(){
  try {
    socket = new Socket(host, port);
    output = new ObjectOutputStream(socket.getOutputStream());
    input = new ObjectInputStream(socket.getInputStream());
    localAddress = socket.getLocalAddress().getHostAddress();
  } catch (UnknownHostException e) {
    exception = e;
    e.printStackTrace();
  } catch (IOException e) {
    exception = e;
    e.printStackTrace();
  }
}
 
origin: org.apache.hadoop/hadoop-common

/**
 * Construct the service key for a token
 * @param addr InetSocketAddress of remote connection with a token
 * @return "ip:port" or "host:port" depending on the value of
 *          hadoop.security.token.service.use_ip
 */
public static Text buildTokenService(InetSocketAddress addr) {
 String host = null;
 if (useIpForTokenService) {
  if (addr.isUnresolved()) { // host has no ip address
   throw new IllegalArgumentException(
     new UnknownHostException(addr.getHostName())
   );
  }
  host = addr.getAddress().getHostAddress();
 } else {
  host = StringUtils.toLowerCase(addr.getHostName());
 }
 return new Text(host + ":" + addr.getPort());
}
origin: yu199195/Raincat

  private String getHost() {
    try {
      return InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
      e.printStackTrace();
      return "127.0.0.1";
    }
  }
}
origin: square/okhttp

 socketPort = proxySocketAddress.getPort();
 inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort));
} else {
 eventListener.dnsStart(call, socketHost);
  throw new UnknownHostException(address.dns() + " returned no addresses for " + socketHost);
  inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
java.netUnknownHostException

Javadoc

Thrown when a hostname can not be resolved.

Most used methods

  • getMessage
  • <init>
    Constructs a new UnknownHostException instance with the given detail message. The detail message sho
  • printStackTrace
  • toString
  • initCause
  • getLocalizedMessage
  • getCause
  • getStackTrace

Popular in Java

  • Running tasks concurrently on multiple threads
  • notifyDataSetChanged (ArrayAdapter)
  • startActivity (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Kernel (java.awt.image)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now