@Test @DisplayName("Check well-known service names") void serviceName_1() { assumeTrue(System.getProperty("os.name").toLowerCase().contains("linux")); assertEquals("ssh", serviceName(22).get()); assertEquals("sandpolis", serviceName(8768).get()); }
public static Optional<String> serviceName(int port) { if (!ValidationUtil.port(port)) throw new IllegalArgumentException("Invalid port: " + port); if (!serviceResolutionEnabled) return Optional.empty(); if (port >= 49152) return Optional.empty(); if (serviceCache.containsKey(port)) return Optional.of(serviceCache.get(port)); try { var serviceName = serviceName0(port); if (serviceName != null) { serviceCache.put(port, serviceName); return Optional.of(serviceName); } else { return Optional.empty(); } } catch (Exception e) { serviceResolutionEnabled = false; return Optional.empty(); } }
NetUtil { public static Optional<String> serviceName(int port) { if (!ValidationUtil.port(port)) throw new IllegalArgumentException("Invalid port: " + port); if (!serviceResolutionEnabled) return Optional.empty(); if (port >= 49152) return Optional.empty(); if (serviceCache.containsKey(port)) return Optional.of(serviceCache.get(port)); try { var serviceName = serviceName0(port); if (serviceName != null) { serviceCache.put(port, serviceName); return Optional.of(serviceName); } else { return Optional.empty(); } } catch (Exception e) { serviceResolutionEnabled = false; return Optional.empty(); } } }
NetUtil { public static Optional<String> serviceName(int port) { if (!ValidationUtil.port(port)) throw new IllegalArgumentException("Invalid port: " + port); if (!serviceResolutionEnabled) return Optional.empty(); if (port >= 49152) return Optional.empty(); if (serviceCache.containsKey(port)) return Optional.of(serviceCache.get(port)); try { var serviceName = serviceName0(port); if (serviceName != null) { serviceCache.put(port, serviceName); return Optional.of(serviceName); } else { return Optional.empty(); } } catch (Exception e) { serviceResolutionEnabled = false; return Optional.empty(); } } private  NetUtil(); }
NetUtil { public static Optional<String> serviceName(int port) { if (!ValidationUtil.port(port)) throw new IllegalArgumentException("Invalid port: " + port); if (!serviceResolutionEnabled) return Optional.empty(); if (port >= 49152) return Optional.empty(); if (serviceCache.containsKey(port)) return Optional.of(serviceCache.get(port)); try { var serviceName = serviceName0(port); if (serviceName != null) { serviceCache.put(port, serviceName); return Optional.of(serviceName); } else { return Optional.empty(); } } catch (Exception e) { serviceResolutionEnabled = false; return Optional.empty(); } } private  NetUtil(); static boolean checkPort(String host, int port); static byte[] download(String url); static void download(String url, File file); static byte[] download(URL url); static void download(URL url, File file); static Optional<String> serviceName(int port); }
NetUtil { public static Optional<String> serviceName(int port) { if (!ValidationUtil.port(port)) throw new IllegalArgumentException("Invalid port: " + port); if (!serviceResolutionEnabled) return Optional.empty(); if (port >= 49152) return Optional.empty(); if (serviceCache.containsKey(port)) return Optional.of(serviceCache.get(port)); try { var serviceName = serviceName0(port); if (serviceName != null) { serviceCache.put(port, serviceName); return Optional.of(serviceName); } else { return Optional.empty(); } } catch (Exception e) { serviceResolutionEnabled = false; return Optional.empty(); } } private  NetUtil(); static boolean checkPort(String host, int port); static byte[] download(String url); static void download(String url, File file); static byte[] download(URL url); static void download(URL url, File file); static Optional<String> serviceName(int port);  }