@Test public void getAvailablePortWithMinPort() throws Exception { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); int portInUse = ss.getLocalPort(); int MIN_PORT = 20000; int port; for (int i = 0; i < 100; i++) { port = NetUtils.getAvailablePort(MIN_PORT); Assert.assertTrue(port != portInUse); } } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage(), e); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } }
public static int getAvailablePort() { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); return ss.getLocalPort(); } catch (IOException e) { return getRandomPort(); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } }
NetUtils { public static int getAvailablePort() { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); return ss.getLocalPort(); } catch (IOException e) { return getRandomPort(); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } } }
NetUtils { public static int getAvailablePort() { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); return ss.getLocalPort(); } catch (IOException e) { return getRandomPort(); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } }  }
NetUtils { public static int getAvailablePort() { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); return ss.getLocalPort(); } catch (IOException e) { return getRandomPort(); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } }  static int getRandomPort(); static int getAvailablePort(); static int getAvailablePort(int port); static boolean isValidAddress(String address); static boolean isLocalHost(String host); static boolean isAnyHost(String host); static boolean isInvalidLocalHost(String host); static boolean isValidLocalHost(String host); static InetSocketAddress getLocalSocketAddress(String host, int port); static String getLocalHost(); static String filterLocalHost(String host); static InetAddress getLocalAddress(); static String getLogHost(); static String getHostName(String address); static String getIpByHost(String hostName); static String toAddressString(InetSocketAddress address); static InetSocketAddress toAddress(String address); static String toURL(String protocol, String host, int port, String path); }
NetUtils { public static int getAvailablePort() { ServerSocket ss = null; try { ss = new ServerSocket(); ss.bind(null); return ss.getLocalPort(); } catch (IOException e) { return getRandomPort(); } finally { if (ss != null) { try { ss.close(); } catch (IOException e) { } } } }  static int getRandomPort(); static int getAvailablePort(); static int getAvailablePort(int port); static boolean isValidAddress(String address); static boolean isLocalHost(String host); static boolean isAnyHost(String host); static boolean isInvalidLocalHost(String host); static boolean isValidLocalHost(String host); static InetSocketAddress getLocalSocketAddress(String host, int port); static String getLocalHost(); static String filterLocalHost(String host); static InetAddress getLocalAddress(); static String getLogHost(); static String getHostName(String address); static String getIpByHost(String hostName); static String toAddressString(InetSocketAddress address); static InetSocketAddress toAddress(String address); static String toURL(String protocol, String host, int port, String path); static final String LOCALHOST; static final String ANYHOST; }